I am trying to read an image (.ras) and sending a part of the image to each process. But every time I get
Primary job terminated normally, but 1 process returned a non-zero exit code. Per user-direction, the job has been aborted. mpirun noticed that process rank 0 with PID 0 on node eskandarany exited on signal 6 (Aborted).
Here is my code :
typedef struct {
struct rasterfile file; ///< Entête image Sun Raster
unsigned char rouge[256],vert[256],bleu[256]; ///< Palette de couleur
unsigned char *data; ///< Pointeur vers l'image
} Raster;
int main(int argc, char *argv[]) {
Raster r;
int w, h, lh; /* nombre de lignes et de colonnes de l'image */
/* Variables liees au traitement de l'image */
int filtre; /* numero du filtre */
int nbiter; /* nombre d'iterations */
/* Variables liees au chronometrage */
double debut, fin;
/* Variables de boucle */
int i,j;
/* Nombres de processus */
int p, my_rank, tag = 0, root = 0;
MPI_Status status;
if (argc != 4) {
fprintf( stderr, usage, argv[0]);
return 1;
}
/* Saisie des paramètres */
filtre = atoi(argv[2]);
nbiter = atoi(argv[3]);
/* Initialisation */
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &p);
/* Lecture du fichier Raster */
if (my_rank == root) {
lire_rasterfile( argv[1], &r);
h = r.file.ras_height;
w = r.file.ras_width;
lh = (h/p) + 2;
}
MPI_Bcast(&w, 1, MPI_INT, root, MPI_COMM_WORLD);
MPI_Bcast(&lh, 1, MPI_INT, root, MPI_COMM_WORLD);
int shift = 0;
if (my_rank == 0 || my_rank == p-1) {
lh--;
shift = w;
}
unsigned char *bandlette = (unsigned char *) malloc(w * lh * sizeof(unsigned char));
MPI_Scatter(r.data, w*h, MPI_UNSIGNED_CHAR, bandlette + shift, w*lh, MPI_UNSIGNED_CHAR, root, MPI_COMM_WORLD);
printf("my rank is %i\n", my_rank);
free(bandlette);
free(r.data);
MPI_Finalize();
return 0;
} ```
The problem is that the second argument of MPI_Scatter is the size of data you want to send to each process, not the total size of the send_buffer. So in this case it's gonna be w*h/p.