0

How to gather blocks of matrix in root process. I tried using gather with the data type blocktype declared below but it didn't work.

    int sqr=sqrt(p);
    modval = n % sqr;
    divval = n/sqr;
    //partition into rows and columns
    MyNoofRows = (me/sqr< modval ? divval + 1 : divval);
    MyNoofcols = (me%sqr < modval ? divval + 1 : divval);
    // surrounding rows with additional values required for computation  
    int rows_with_halo=MyNoofRows+(2*d);
    int cols_with_halo=MyNoofcols+(2*d);
    int istart= (cols_with_halo*d)+d;
    MPI_Type_vector(rows_with_halo,d,cols_with_halo,MPI_DOUBLE,&columntype);
    MPI_Type_commit(&columntype);
    MPI_Type_vector(MyNoofRows,MyNoofcols,cols_with_halo,MPI_DOUBLE,&blocktype);
    MPI_Type_commit(&blocktype);
    MPI_Type_vector(MyNoofRows,MyNoofcols,n,MPI_DOUBLE,&blocktype_recv);
    MPI_Type_commit(&blocktype_recv);
    double *chunk_array=(double *)calloc((rows_with_halo*cols_with_halo),sizeof(double));
    double *result_array=(double *)calloc((n*n),sizeof(double));
    // now after computation I want matrix in each process must be collected in root              process 
Biparite
  • 203
  • 1
  • 2
  • 13
  • How didn't it work? How did you try to use the types you've just defined? Simple self-contained example code is the best way to describe your problem. At any rate, if you want to gather blocks of a matrix, [this answer](http://stackoverflow.com/a/9271753/463827) is a good starting point, as are other similar answers on this site. – Jonathan Dursi Apr 30 '14 at 20:48
  • `MPI_Gather(&chunk_array[istart],1,blocktype,result_array,1,blocktype_recv,0,MPI_COMM_WORLD);` @JonathanDursi I used this but only process 0 gets collected in proper order, others are scattered randomly. – Biparite May 01 '14 at 02:49
  • all the examples I read are based on double** pointers, However my code uses double* for 2D array. – Biparite May 01 '14 at 17:35

0 Answers0