Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Allocating 2-D arrays in Fortran through MPI_Alloc_Mem

Status
Not open for further replies.

qwertyhpc

Technical User
Feb 14, 2013
1
US
Hello Folks,
I am very familiar with programming in C and MPI. However, I am fairly new to Fortran.
In a given fortran application, I am trying to replace the regular allocate() function with MPI_Alloc_mem. MPI_Alloc_mem will just return a pointer to a memory region that the MPI library allocates, as requested by the user. The following piece of code, with 1-D integer arrays seems to work fine.


type(c_ptr) :: baseptr
integer, pointer :: sbuf
alloc_size=length*itemsize*size

call MPI_alloc_mem (alloc_size, MPI_INFO_NULL, baseptr, ierr)
call c_f_pointer(baseptr, sbuf, alloc_size)
sbuf = 0
..
However, if an application deals with dynamic 2-D arrays, that are allocated as:
complex(mytype), save, allocatable :: buf1:),:)
allocate(buf1(nm,2),stat=err)

I am not too sure how to replace the allocate call with MPI_Alloc_mem(). I would greatly appreciate it if someone could help me out.

Thanks,
KK
 
Try equivalencing the 1D and 2D arrays. Then allocate as you would a 1D array and use it as a 2D array. The size will be the product of the two dimensions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top