Jul 16, 2021 02:05
Thanks a million for your expertise and help!
Jul 16, 2021 02:04
I figured it out, i.e., to do an additional fortran mapping: e.g., f_ptr(-2:2) => f_ptr(1:5)
Jul 15, 2021 22:31
@IanBush
Jul 15, 2021 22:31
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, []) ?
Jul 15, 2021 19:52
got it, thanks!
Jul 15, 2021 19:47
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
Jul 15, 2021 19:40
is it necessary to use c_int, c_double, instead of the usual fortran integer*4, complex*16 etc? are there differences in how numbers are allocated?
Jul 15, 2021 19:37
many thanks! I am studying your answer now, but looks like using c_loc will make it work.
Jul 15, 2021 19:09
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.
Jul 15, 2021 19:05
In your view, could you think of a simpler solution?
Jul 15, 2021 19:05
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
Jul 15, 2021 19:03
now this piece of data will be fixed after calling the initialize_data_entries subroutine, and only read-from in later calculations.
Jul 15, 2021 19:02
type mytype
complex, allocatable: data1(:,:)
real, allocatable :: data2(:)
....
end mytype

type (mytype) , allocatable :: data(:,:)
allocate(data(m,n))
call initialize data_entries(data)
Jul 15, 2021 19:00
the structure I am working with --- without invoking MPI --- has something like the follows :
Jul 15, 2021 18:59
I could not find material on the internet that covers it
Jul 15, 2021 18:58
It is not entirely clear to me how to combine them, although I know both exists
Jul 15, 2021 18:58
On the issue of sharing , are you recommending that I combine mpi_dataypes and mpi_shared?
Jul 15, 2021 18:57
thx for the response ! I will look into c_loc
Jul 15, 2021 18:57
Thanks foe
Jul 15, 2021 18:12
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.
Jul 15, 2021 18:11
@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
Jul 15, 2021 18:11
@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.
Jul 15, 2021 18:11
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
 

Python

Room rules: sopython.com/chatroom Code formatting guide: tinyu...
Feb 12, 2015 23:44
Hi guys, I have a brief question about python, is it appropriate to ask here?
 
Aug 29, 2014 20:00
Goodnight ;)
Aug 29, 2014 19:59
sure I'll edit it ;)
Aug 29, 2014 19:58
Thans guys!
Aug 29, 2014 19:58
Aha
Aug 29, 2014 19:57
I used call cpu_time(clock_start); call cpu_time(clock_finish), time=clock_finish-clock_start
Aug 29, 2014 19:54
let me check
Aug 29, 2014 19:54
that's my point...
Aug 29, 2014 19:54
sorry
Aug 29, 2014 19:54
wait a sec...
Aug 29, 2014 19:53
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
Aug 29, 2014 19:51
sorry for the confusion
Aug 29, 2014 19:51
yes
Aug 29, 2014 19:50
yes
Aug 29, 2014 19:50
yes
Aug 29, 2014 19:49
each thread calls the function matmul to compute a matrix product
Aug 29, 2014 19:49
the 4 threads deals with C(1) C(2) C(3) C(4) respectively
Aug 29, 2014 19:48
it is within one thread only
Aug 29, 2014 19:48
oh it is not distributed
Aug 29, 2014 19:48
I'm confused how computing C(i) in random sequence could result in difference as compared to computing C(1) C(2) C(3)...
Aug 29, 2014 19:47
so C(1)(i,j) is a scalar
Aug 29, 2014 19:47
no, C(1) is a 2x2 matrix
Aug 29, 2014 19:46
I understand openmp as putting this operation into one thread,
Aug 29, 2014 19:46
let's say real A(1)={1,2;3,4}, B(1)={3,2;4,1}. then C(1)=A(1)*B(1)
Aug 29, 2014 19:42
Ah, you misunderstood my point. when I say do i=1,N C(i)=matmul(A(i),B(i)), I am not adding up ,say, C(i)+C(j)
Aug 29, 2014 19:38
I'm still confused. why would the "randomness" affect the numerical accuracy?
Aug 29, 2014 19:36
feel free to do whatever for the moment, I'll post the results in 2min