Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenMPI doesn't send data from an array
    primarykey
    data
    text
    <p>I am trying to parallelize a grayscale filter for BMP image, my function get stuck when trying to send data from a pixel array.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;time.h&gt; #include "mpi.h" #define MASTER_TO_SLAVE_TAG 1 //tag for messages sent from master to slaves #define SLAVE_TO_MASTER_TAG 10 //tag for messages sent from slaves to master #pragma pack(1) struct image { struct fileHeader fh; struct imageHeader ih; pixel *array; }; struct fileHeader { //blablabla... }; struct imageHeader { //blablabla... }; typedef struct { unsigned char R; unsigned char G; unsigned char B; }pixel; void grayScale_Parallel(struct image *im, int size, int rank) { int i,j,lum,aux,r; pixel tmp; int total_pixels = (*im).ih.width * (*im).ih.height; int qty = total_pixels/(size-1); int rest = total_pixels % (size-1); MPI_Status status; //printf("\n%d\n", rank); if(rank == 0) { for(i=1; i&lt;size; i++){ j = i*qty - qty; aux = j; if(rest != 0 &amp;&amp; i==size-1) {qty=qty+rest;} //para distrubuir toda la carga printf("\nj: %d qty: %d rest: %d\n", j, qty, rest); //it gets stuck here,it doesn't send the data MPI_Send(&amp;(*im).array[j], qty*3, MPI_BYTE, i, MASTER_TO_SLAVE_TAG, MPI_COMM_WORLD); MPI_Send(&amp;aux, 1, MPI_INT, i, MASTER_TO_SLAVE_TAG+1, MPI_COMM_WORLD); MPI_Send(&amp;qty, 1, MPI_INT, i, MASTER_TO_SLAVE_TAG+2, MPI_COMM_WORLD); printf("\nSending to node=%d, sender node=%d\n", i, rank); } } else { MPI_Recv(&amp;aux, 1, MPI_INT, MPI_ANY_SOURCE, MASTER_TO_SLAVE_TAG+1, MPI_COMM_WORLD,&amp;status); MPI_Recv(&amp;qty, 1, MPI_INT, MPI_ANY_SOURCE, MASTER_TO_SLAVE_TAG+2, MPI_COMM_WORLD,&amp;status); pixel *arreglo = (pixel *)calloc(qty, sizeof(pixel)); MPI_Recv(&amp;arreglo[0], qty*3, MPI_BYTE, MPI_ANY_SOURCE, MASTER_TO_SLAVE_TAG, MPI_COMM_WORLD,&amp;status); //PROCESS RECEIVED PIXELS... //SEND to ROOT PROCESS } if (rank==0){ //RECEIVE DATA FROM ALL PROCESS } } int main(int argc, char *argv[]) { int rank, size; MPI_Init(&amp;argc, &amp;argv); MPI_Comm_size(MPI_COMM_WORLD, &amp;size); MPI_Comm_rank(MPI_COMM_WORLD, &amp;rank); MPI_Status status; int op=1; char filename_toload[50]; int bright_number=0; struct image image2; if (rank==0) { printf("File to load: \n"); scanf("%s", filename_toload); loadImage(&amp;image2, filename_toload); } while(op != 0) { if (rank==0) { printf("Welcome to example program!\n\n"); printf("\t1.- GrayScale Parallel Function\n"); printf("\t2.- Call another Function\n"); printf("\t0.- Exit\n\t"); printf("\n\n\tEnter option:"); scanf("%d", &amp;op); } //Broadcast the user's choice to all other ranks MPI_Bcast(&amp;op, 1, MPI_INT, 0, MPI_COMM_WORLD); switch(op) { case 1: grayScale_Parallel(&amp;image2, size, rank); MPI_Barrier(MPI_COMM_WORLD); printf("GrayScale applied successfully!\n\n"); break; case 2: function_blabla(); printf("Function called successfully\n\n"); break; } } MPI_Finalize(); return 0; } </code></pre> <p>I think the MPI_Send function can't read the array of pixels, but is strange because i can print the pixels.</p> <p>Any idea?</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.
    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