[mpich-discuss] Help : Sending a pointer type data to other nodes

Dorian Krause ddkrause at uni-bonn.de
Tue Mar 24 10:59:30 CDT 2009


Hi,

please correct me if I misunderstood your question ...


Steven Liu wrote:
> Hi,
>
>     I want to send a data as pointer type in C to the other nodes. 
>   

Local pointers (i.e. memory adresses) are meaningless on other nodes since
the adress space is not shared among them.

> Is there any method to do so? I tried several times. But failed. 
> Thanks a lot. 
>
> PS: Purpose -- make a variable which can be read and written by the other nodes.
>   

shared variables on distributed memory machines are a complex topic 
(look for PGAS, partitioned global adress space, languages)


Onesided communication is a method to manipulate remote memory directly 
via put (store), get (retrieve) and accumulate (e.g., sum up)
operations. I can come up with a simple example if you are interested ...

Regards,
Dorian

> My code is attached below:
>
> #include <stdlib.h>
> #include <string.h>
> #include "mpi.h"
>
> int main(int argc,char *argv[])
> {
>  int myid, numprocs;
>  
>  double *ptr;
>  double Q[1];
>  Q[0]=1.3;
>  Q[1]=7.3;
>  
>  MPI_Init(&argc,&argv);
>     MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
>     MPI_Comm_rank(MPI_COMM_WORLD,&myid);
>  
>  if (myid == 0) {
>  
>   ptr = &Q;
>   MPI_Bcast((void*)&ptr, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
>   printf("\n");
>   printf("sizeof pointer %d\n", sizeof(ptr));
>   printf("ptr has the value %p and is stored at %p\n", ptr, (void*)&ptr);
>   printf("The value of the integer pointed to by ptr is %f\n", *ptr);
>   printf("Second address of ptr has the value %p and is valued at %f\n", ptr+1, *(ptr+1));
>   
>  }
>  else{
>  
>   MPI_Bcast(ptr, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
>   printf("\n");
>   printf("ptr has the value %p and is stored at %p\n", ptr, (void*)&ptr);
>   printf("The value of the integer pointed to by ptr is %f\n", *ptr);
>   printf("Second address of ptr has the value %p and is valued at %f\n", ptr+1, *(ptr+1));
>  }
>
>  MPI_Finalize();
>     return 0;
> }
>
> With all my best wishes.
>
>
> Yours, Dongping Liu
>
> Group M02
> State Key Laboratory of Magnetism
> Institute of Physics
> Chinese Academy of Sciences
> P.O.Box 603, Beijing 100190, P. R. China



More information about the mpich-discuss mailing list