[mpich-discuss] derived data type

William Gropp wgropp at illinois.edu
Sun Mar 18 09:41:45 CDT 2012


The MPI vector type requires that the memory be a single contiguous section - your code, while using a natural C++ style, allocates IE*JE separate arrays of size KE doubles, which may not be placed in successive locations.  To use the MPI_Type_vector, you need to allocate the entire memory as a single IE*JE*KE*sizeof(double) memory block; you can then create and set the various a[] and a{][] fields to point into this.

Bill

On Mar 17, 2012, at 2:53 AM, Lion Lion wrote:

> 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?
> _______________________________________________
> mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> To manage subscription options or unsubscribe:
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss

William Gropp
Director, Parallel Computing Institute
Deputy Director for Research
Institute for Advanced Computing Applications and Technologies
Paul and Cynthia Saylor Professor of Computer Science
University of Illinois Urbana-Champaign



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20120318/bdce10a9/attachment.htm>


More information about the mpich-discuss mailing list