[Mpi-forum] C-MPI DYNAMIC ALLOCATION / DERIVED DATATYPES
Simone Pellegrini
spellegrini at dps.uibk.ac.at
Thu Feb 11 06:57:44 CST 2010
On 02/11/2010 01:42 PM, kostas pinokio wrote:
> HALLO,
>
> I would like to send a whole column of a dynamicly allocated array (in
> C language).
> When i use derived datatypes(for example MPI_Type_vector) i can send a
> column ONLY if i have static array but when i use dynamic allocation i
> have problem!
> Please tell me one way to send a column of a dynamc allocated array.
>
> For example :
> MPI_Datatype columntype;
> MPI_Type_vector(10, 1, 10, MPI_INT, &columntype);
> MPI_Type_commit(&columntype);
> if(rank==0){
> dyn_array=(int **) calloc(10,sizeof(int *));
> for(i = 0; i < 10; i++){
> dyn_array[i] =(int *) calloc(10,sizeof(int));
> }
> for(i=0;i<10;i++){ for(j=0;j<10;j++)
> dyn_array[i][j]=9;}
> MPI_Send(&dyn_array[0][0], 1, columntype, dest,
> tag,MPI_COMM_WORLD);
> }
> if(rank==1){
> MPI_Recv(&other_dyn_array[0][0], 1, columntype, 0, tag,
> MPI_COMM_WORLD, &Stat);
> }
>
> the values of the receive are not correct!!
>
The MPI_Type_vector assumes your data is contiguous in memory and this
is not the case in your code.
As each raw is allocated using a different calloc. You need to arrange
the 2D array in memory in a more clever way:
if(rank==0){
dyn_array=(int **) calloc(10,sizeof(int *));
dyn_array[0] = (int*) calloc(10*10, sizeof(int));
for(i = 1; i < 10; i++)
dyn_array[i] = dyn_array[0] + i*10;
/*same code*/
}
this should work!
cheers, Simone
>
> Thank You!
>
>
> __________________________________________________
> Χρησιμοποιείτε Yahoo!;
> Βαρεθήκατε τα ενοχλητικά μηνύματα (spam); Το Yahoo! Mail διαθέτει την
> καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων
> http://mail.yahoo.gr
>
>
> _______________________________________________
> mpi-forum mailing list
> mpi-forum at lists.mpi-forum.org
> http://lists.mpi-forum.org/mailman/listinfo.cgi/mpi-forum
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mpi-forum.org/pipermail/mpi-forum/attachments/20100211/15313485/attachment-0001.html>
More information about the mpi-forum
mailing list