[mpich-discuss] derived data type

Lion Lion shajarian_e at yahoo.com
Sat Mar 17 02:53:05 CDT 2012


Hi all
I have a problem with mpi_type_vector, I want to divide a cubic matrix between for example two processes for solving my problem I have to send boundary plane's information from one process to other I did it before by point_point_communication but I know it's not good because of my huge matrix so I want to use derived data type.
I want to create a vector I know that in c++ matrix is row major but I have problem with  mpi_type_vector().I write arguments with respect to tutorial http://www.mcs.anl.gov/research/projects/mpi/www/www3/MPI_Type_vector.html
but I get segmentation fault error .my code is :
#include <mpi.h>
#include <iostream>
using namespace std;

int main(int argc,char ** argv)
{
int const IE=100,JE=25,KE=100;
int size,rank;
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&size);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Datatype sub;
MPI_Type_vector(KE,IE,IE+(JE-1)*IE,MPI_DOUBLE,&sub);
MPI_Type_commit(&sub);
if (rank==0){
double*** a=new double**[IE];
for(int i=0;i<IE;i++){
a[i]=new double *[JE];
for(int j=0;j<JE;j++){
a[i][j]=new double [KE];
}
}
for(int i=0;i<IE;i++){
for(int j=0;j<JE;j++){
for(int k=0;k<KE;k++){
a[i][j][k]=2;
}}}
for(int i=0;i<IE;i++){
for(int j=0;j<JE;j++){
a[i][j][0]=2;
}}
MPI_Send(&a[0][0][0],1,sub,1,52,MPI_COMM_WORLD);
}
if (rank==1){
double*** b=new double**[IE];
for(int i=0;i<IE;i++){
b[i]=new double *[JE];
for(int j=0;j<JE;j++){
b[i][j]=new double [KE];
}
}
for(int i=0;i<IE;i++){
for(int j=0;j<JE;j++){
for(int k=0;k<KE;k++){
b[i][j][k]=0;
}}}
MPI_Recv(&b[0][0][0][0],1,sub,0,52,MPI_COMM_WORLD,&status);
for(int i=0;i<IE;i++){
for(int j=0;j<JE;j++){
for(int k=0;k<KE;k++){
if(b[i][j][k]>0){
cout<<"b["<<i<<"]["<<j<<"]["<<k<<"]="<<b[i][j][k]<<endl;
}}}}
}
MPI_Finalize();
}
I just want to send plane y=0 from process 0 to process 1.can everybody help me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20120317/11b6d2f0/attachment-0001.htm>


More information about the mpich-discuss mailing list