Hi Ian, one last question (I promise!): since fortran array indexing is non-standard, is there a way of specifying the index range (f_ptr(start:end) ) when calling c_to_f_pointer(c_ptr,f_ptr, []) ?
oops got it. What about integer(kind=4), real(kind=kind(0.d0))? These are the codes I am working with. If possible I probably don't want to modify the code significantly
Another option I am considering, is to do the regular allocation/initialization on MPI rank 0, and use the MPI_win_allocate_dynamic + MPI_win_attach + MPI_type_struct. However I am not knowledgeable enough if these three contain enough information for another process (e.g., MPI rank 1 on the same node) to easily read from attached data.
now I'd like to use MPI to share this particular data across all processes. If I understand correctly, MPI does not trivially recognize fortran derived data types, and to be able to share data between processes, I need some sort of way of "memory map" using pointers
Hi Ian, first of all, thanks for your answers! I've been stuck on the problem for past three days, and it would be nice to get some help. Please let me know if the question is clear enough.
@IanBush --- here's what I want to do: I need to use MPI to initiate multiple instances of fortran code to perform a numerical calculation. Different MPI processes run independently, except that they all share the same huge data structure. As a result, it makes sense to use MPI_allocate_shared to only create the data structure once, and have other MPI processes directly read from it. However, being a custom-defined type, it is not clear how to instruct other MPI processes to know the data structure. In C this can be achieved via pointer arithmetics. However in fortran it is not clear
@IanBush, Hi Ian thanks for the comment. It is not confusing actually, you described what just what I wanted, i.e., a(:) is a pointer to an array of integers. Now the reason I wanted pointers is because I want to store a fortran custom data type using MPI_shared, and access it between various processes. I only know how to do it using C pointers but my work requires that I use fortran.
you are right about the wrong code I have provide Ian. I have thus updated it, and hopefully it makes sense now. I hope my question still makes sense, i.e., since fortran does not support pointer arithmetic, how should I have the pointers data, data(i)%a and data(i)%b correctly point to a pre-allocated block of memory using MPI
btw the results for serial and parallel are out. The output data are consistent (physically, I am a physicist!). However the time cost for parallel code is 10min for 20iterations, while 6.39 for the serial code