[MPICH] How to create a Window for 2D array
Rajeev Thakur
thakur at mcs.anl.gov
Tue Jan 10 17:33:22 CST 2006
To create a window for a dynamically allocated 2D array, you need to
allocate a single contiguous chunk of memory and then set up the pointers so
that it can be addressed as a 2D array. For example:
double *temp;
error = MPI_Alloc_mem(n1D * sizeof(double*), MPI_INFO_NULL, &pp);
error = MPI_Alloc_mem(n1D * n2D * sizeof(double), MPI_INFO_NULL, &temp);
pp[0] = temp;
for(i=1; i<n1D; i++)
pp[i] = pp[i-1] + n2D;
error = MPI_Win_create(pp, n1D*n2D, sizeof(double), MPI_INFO_NULL,
MPI_COMM_WORLD, &win);
Rajeev
> -----Original Message-----
> From: owner-mpich-discuss at mcs.anl.gov
> [mailto:owner-mpich-discuss at mcs.anl.gov] On Behalf Of Tao He
> Sent: Thursday, January 05, 2006 5:00 PM
> To: mpich-discuss at mcs.anl.gov
> Subject: [MPICH] How to create a Window for 2D array
>
> Dear All,
>
> I am a newer for One Sided-Communcation. I have a question
> how to create a window for 2D array. For example, I create a
> 2D double array by this function:
>
> double** NewMPI2_2DPointer(int n1D, int n2D)
> { double **pp;
> int error;
> error = MPI_Alloc_mem(n1D * sizeof(double*), MPI_INFO_NULL, &pp);
> if (error != MPI_SUCCESS)
> {
> printf("Memory allocation failed for PP 1D array, aborting.\n");
> MPI_Abort(MPI_COMM_WORLD, -1);
> exit(-1);
> }
>
> for(i=0; i<n1D; i++)
> {
> error = MPI_Alloc_mem(n2D * sizeof(double),
> MPI_INFO_NULL, &pp[i]);
> if (error != MPI_SUCCESS)
> {
> printf("Memory allocation failed for PP 1D array,
> aborting.\n");
> MPI_Abort(MPI_COMM_WORLD, -1);
> exit(-1);
> }
> }
>
> }
>
> I want to create a window for this memory:
> Like:
> error = MPI_Win_create(pp, n1D, sizeof(double*),
> MPI_INFO_NULL, MPI_COMM_WORLD, &win);
>
> or should be
> error = MPI_Win_create(pp, n1D*n2D, sizeof(double),
> MPI_INFO_NULL, MPI_COMM_WORLD, &win);
>
> Which is the right? Please tell me! THanks very much!
>
> Tao
>
More information about the mpich-discuss
mailing list