PTL logo

From: sedegheh ghaffari (cs_986_at_[hidden])
Date: 2011-07-18 04:09:50


Hi This is transposing matrix program that  I wrote using mpi. #include<stdio.h> #include<iostream> #include<mpi.h> #include<iomanip> usingnamespace std; intmain(int argc,char*argv[]) {       int myrank, nproc;       int   nlocal=3;       int i;       int c[3][3];       int n=3;       cout<<"Input matrix is:\n";       for(i=0; i<n; i++)       {             for(int j=0; j<n; j++)             {                   c[i][j]=rand()/1000;                   cout<< setw(8) << c[i][j];             }             cout<<"\n";       }                   MPI_Init(&argc,&argv);       int a[3];       int b[3];       int d[3];       MPI_Comm_size(MPI_COMM_WORLD,&nproc);       MPI_Comm_rank(MPI_COMM_WORLD, &myrank);       for(int i=0; i<nlocal; i++)             a[i]=c[myrank][i];                   MPI_Alltoall(&a,1,MPI_INT,&b,1,MPI_INT,MPI_COMM_WORLD);         MPI_Gather(&b,nlocal,MPI_INT,&d,nlocal,MPI_INT,0,MPI_COMM_WORLD);           cout<<"\n Transpose of matrix C is:";       for (int i=0; i<3; i++)                cout<< setw(8) << d[i];             MPI_Finalize();      getchar(); } ****************************** Can anyone help me? What is wrong about this? Its run in single machine. Is process with rank 1 and 2 execute and if yes why array d does not print out for them? When I put if (myrank ==2)print something, nothing happened. Where is the problem? 1.from code 2.from machine 3.from visual studio 2008 Thanks very much for  your any help. I attach error message and output window files. Best Regards.