c - Why doesn't MPI_SEND work within my for loop? It works fine if explicitly stated -
i'm trying send number p-1 processes. process 0 sends value other processes. use mpi_send command this. when explicitly write out mpi_send commands 3 processes, works fine. when want put in loop, gives me output segmentation fault code. here code:
#include <stdlib.h> #include <mpi.h> #include "a1.h" //authors //lakshan sivananthan - 1150161 //razmig papissian - 1152517 int main(int argc, char** argv) { rgb *image; int width, height, max; int windowlength = atoi(argv[3]); int my_rank, p, local_height, source, i; int dest; mpi_status status; mpi_init(&argc, &argv); mpi_comm_size(mpi_comm_world, &p); mpi_comm_rank(mpi_comm_world, &my_rank); int *processorrows; processorrows = (int*)malloc(sizeof(int)*(p+1)); if (my_rank == 0) { printf("process %d reading...\n", my_rank); image = readppm(argv[1], &width, &height, &max); //calculate rows each process (i=0; i<p; i++) { processorrows[i] = height/p; } (i=0; i< height%p; i++){ processorrows[i]++; } (dest=1; dest<p; dest++) { mpi_send(processorrows + dest, 1, mpi_int, dest, 0, mpi_comm_world); //mpi_send(processorrows + 2, 1, mpi_int, 2, 0, mpi_comm_world); //mpi_send(processorrows + 3, 1, mpi_int, 3, 0, mpi_comm_world); } } else { mpi_recv(processorrows, 1, mpi_int, 0, 0, mpi_comm_world, &status); printf("i process %d , run %d rows...\n", my_rank, *processorrows); } //processimage(width, height, image, windowlength); //writeppm(argv[2], width, height, max, image); free(image); free(processorrows); mpi_finalize(); return(0); } if remove loop, replace "dest" 1, , uncomment other 2 mpi_send lines, works fine when running mpirun -np 4 ./program
not sure what's going on here...
i'm not sure trying accomplish. but, statement
process 0 sends value other processes.
and part of code, expect scatter process-0 other pes rather send-receive loop tricks.
remove send-receive pairs , remove loops, use single scatter operation. here link mpi_scatter operation https://www.open-mpi.org/doc/v1.8/man3/mpi_scatter.3.php. if unsure scatter operation, have @ neat explanation http://mpitutorial.com/tutorials/mpi-scatter-gather-and-allgather/
it looks like, size of processorrows array size of total number of process used. and, trying send each element of processorrows array other ranks. hence, code should 1 below:
int *processorrows; processorrows = (int*)malloc(sizeof(int)*(p+1)); if (my_rank == 0) { printf("process %d reading...\n", my_rank); image = readppm(argv[1], &width, &height, &max); (i=0; i<p; i++) { processorrows[i] = height/p; } (i=0; i< height%p; i++){ processorrows[i]++; } } mpi_scatter(processorrows, 1, mpi_int, processorrows, 1, mpi_int, 0, mpi_comm_world);
Comments
Post a Comment