[mpich-discuss] Help : Sending a pointer type data to other nodes
Steven Liu
steven.dpliu at gmail.com
Tue Mar 24 09:24:42 CDT 2009
Hi,
I want to send a data as pointer type in C to the other nodes.
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.
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20090324/f6c79ce1/attachment.htm>
More information about the mpich-discuss
mailing list