Note that there are some explanatory texts on larger screens.

plurals
  1. POMPI_Type_create_subarray and MPI_Gather
    primarykey
    data
    text
    <p>I have to solve a little mpi problem. I have 4 slaves processes and each of these wants to send a 2d subarray (CHUNK_ROWS X CHUNK_COLUMNS) to master 0. Master 0 collects all chunks in ddd[ROWS][COLUMNS] and print it. I want to use MPI_Gather()</p> <pre><code>#include &lt;mpi.h&gt; #include &lt;iostream&gt; using namespace std; #define ROWS 10 #define COLUMNS 10 #define CHUNK_ROWS 5 #define CHUNK_COLUMNS 5 #define TAG 0 int** alloca_matrice(int righe, int colonne) { int** matrice=NULL; int i; matrice = (int **)malloc(righe * sizeof(int*)); if(matrice != NULL){ matrice[0] = (int *)malloc(righe*colonne*sizeof(int)); if(matrice[0]!=NULL) for(i=1; i&lt;righe; i++) matrice[i] = matrice[0]+i*colonne; else{ free(matrice); matrice = NULL; } } else{ matrice = NULL; } return matrice; } int main(int argc, char* argv[]) { int my_id, numprocs,length,i,j; int ndims, sizes[2],subsizes[2],starts[2]; int** DEBUG_CH=NULL; int** ddd=NULL; char name[BUFSIZ]; MPI_Datatype subarray=NULL; //MPI_Status status; MPI_Init(&amp;argc, &amp;argv) ; MPI_Comm_rank(MPI_COMM_WORLD, &amp;my_id) ; MPI_Comm_size(MPI_COMM_WORLD, &amp;numprocs) ; // Ottiene quanti processi sono attivi MPI_Get_processor_name(name, &amp;length); if(my_id!=0){ //creo una sottomatrice ripulita dalle ghost cells ndims=2; sizes[0] = CHUNK_ROWS+2; sizes[1] = CHUNK_COLUMNS+2; subsizes[0] = CHUNK_ROWS; subsizes[1] = CHUNK_COLUMNS; starts[0] = 1; starts[1] = 1; MPI_Type_create_subarray(ndims,sizes,subsizes,starts,MPI_ORDER_C,MPI_INT,&amp;subarray); MPI_Type_commit(&amp;subarray); DEBUG_CH = alloca_matrice(CHUNK_ROWS+2,CHUNK_COLUMNS+2); for(i=0; i&lt;CHUNK_ROWS+2; i++){ for(j=0; j&lt;CHUNK_COLUMNS+2; j++){ if(i==0 || i==CHUNK_ROWS+1 || j==0 || j==CHUNK_COLUMNS+1) DEBUG_CH[i][j] = 5; else DEBUG_CH[i][j] = 1; } } //MPI_Send(DEBUG_CH[0],1,subarray,0,TAG,MPI_COMM_WORLD); } if(my_id==0){ ddd = alloca_matrice(ROWS,COLUMNS); } MPI_Gather(DEBUG_CH[0],1,subarray,ddd[0],CHUNK_ROWS*CHUNK_COLUMNS,MPI_INT,0,MPI_COMM_WORLD); if(!my_id){ for(i=0; i&lt;ROWS; i++){ for(j=0; j&lt;COLUMNS; j++){ printf("%d ",ddd[i][j]); } printf("\n"); } } if(my_id) MPI_Type_free(&amp;subarray); MPI_Finalize(); // Chiusura di MPI. return 0; } </code></pre> <p>Thanks all.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload