Author Topic: Handle array slicing out of bounds  (Read 5354 times)

JStorm

  • Sr. Member
  • ****
  • Posts: 250
Handle array slicing out of bounds
« on: November 08, 2017, 01:29:31 AM »
I have observed a behaviour, which I can not explain:

I have declared temporary arrays (TEMP*) and some own arrays with palloc. Than I read and write data using the slice-feature:
Code: [Select]
mr(pos1:pos1+length-1) = mr(pos2:pos2+length-1), where pos1 and pos2 are declared in accordance to np and determined from np(*). The memory is allocated in the necessary length.

This is working fine on Linux, but on Windows I get crashes from segmentation violations. To replace the slice-notation by a loop over the components, solve that issue. Do someone know the reason for that? Is it due to the slicing out of array bounds of hr and mr? What is the recommended way in FEAP?

FEAP_Admin

  • Administrator
  • FEAP Guru
  • *****
  • Posts: 993
Re: Handle array slicing out of bounds
« Reply #1 on: November 08, 2017, 07:56:09 AM »
How are you declaring pos1 and pos2?

If you are getting these from statements like pos1 = np(xxx), then you need to make sure that pos1 matches the declaration type for np(xxx).
In particular, integer (kind=8) if you are on a machine with 64bit pointers.

Prof. R.L. Taylor

  • Administrator
  • FEAP Guru
  • *****
  • Posts: 2649
Re: Handle array slicing out of bounds
« Reply #2 on: November 08, 2017, 09:37:34 AM »
When we have this sort of action we use an include 'p_int.h' (which is not a common but just declares an array fp(10) of the precision loaded).  this avoids errors on different machines better.

JStorm

  • Sr. Member
  • ****
  • Posts: 250
Re: Handle array slicing out of bounds
« Reply #3 on: November 13, 2017, 12:16:16 AM »
To avoid data type conflicts, the type of np is directly uses:
Code: [Select]
integer, parameter :: ip = kind(np)
integer(kind=ip) pos1,pos2, length

But I am using statements like
Code: [Select]
pos1   = np(111) + tpo
where tpo is defined as ordinary integer.  So far I know, this should be casted to into the np-type.

Futhermore, everything also is working fine on windows, if I replace the slice-form by loops. in that case the same pointers (pos1, etc.) are used.

I still do not understand this issue.

FEAP_Admin

  • Administrator
  • FEAP Guru
  • *****
  • Posts: 993
Re: Handle array slicing out of bounds
« Reply #4 on: November 13, 2017, 07:09:29 AM »
Your code looks fine and there should not be a problem with tpo being integer.  It should automatically cast to interger::(kind=ip).

This may just be some sort of 'compiler feature'.

You could spend some more time on it, or just stick with the loops.

JStorm

  • Sr. Member
  • ****
  • Posts: 250
Re: Handle array slicing out of bounds
« Reply #5 on: November 14, 2017, 01:18:12 AM »
Thank you. I will use the loops instead of slicing. Is there a helper subroutine of FEAP which copies a subset of an array into a subset of a second one?
Code: [Select]
copyarray(arr1, start1, end1, arr2, start2, end2)I prefer to keep the code short. If there is no such subroutine, I will create my own.

Prof. R.L. Taylor

  • Administrator
  • FEAP Guru
  • *****
  • Posts: 2649
Re: Handle array slicing out of bounds
« Reply #6 on: November 14, 2017, 09:13:21 AM »
the only routine is 'pmove.f' in the ./program directory.  This moves one array into another.  It only considers stride one (1) moves.

JStorm

  • Sr. Member
  • ****
  • Posts: 250
Re: Handle array slicing out of bounds
« Reply #7 on: November 15, 2017, 01:08:54 AM »
Thank you Prof. Taylor, the routines  pmove, pmovei and pmovec will do the job.