parallel processing - MPI Address not mapped in C -


i have trouble mpi_recv when using malloc? there suggestion receive 2 dimensional array created malloc?

thanks.

#include <stdio.h> #include <stdlib.h> #include <time.h> #include <mpi.h>  #define size 2000 /* tags defines message from_to */ #define to_slave_tag 1 #define to_master_tag 5  void creatematrices(); /* matrices */ int** first; /* mpi_world rank , size */ int rank, size;  mpi_status status; /*  * matrixsize: current matrix size  * lower_bound: lower bound of number of rows of [first matrix] allocated slave  * upper_bound: upper bound of number of rows of [first matrix] allocated slave  * portion: number of rows of [first matrix] allocated slave according number of processors  * count: number of data pass mpi functions  */ int matrixsize, lower_bound, upper_bound, portion, count; int sum = 0; clock_t t, start_time, end_time;  int main( int argc, char **argv ) {    /* initialize mpi execution environment */   mpi_init( &argc, &argv );   /* determines size of group */   mpi_comm_size( mpi_comm_world, &size );   /* determines rank of calling process */   mpi_comm_rank( mpi_comm_world, &rank );    if (rank == 0)     {       (matrixsize = 500; matrixsize <= size; matrixsize += 500) {     creatematrices(matrixsize);     /*       * master processor divides [first matrix] elements      * , send them proper slave processors.      * can start time @ point.      */     start_time = clock();      /* define bounds each processor except master */     (int = 1; < size; ++i)       {         /* calculate portion each slave */         portion = (matrixsize / (size - 1));         lower_bound = (i-1) * portion;         if (((i+1)==size) && (matrixsize % (size-1) != 0)) {           upper_bound = matrixsize;         } else {           upper_bound = lower_bound + portion;         }         /* send matrix size ith slave */         mpi_send(&matrixsize, 1, mpi_int, i, to_slave_tag, mpi_comm_world);         /* send lower bount ith slave */         mpi_send(&lower_bound, 1, mpi_int, i, to_slave_tag + 1, mpi_comm_world);         /* send upper bount ith slave */         mpi_send(&upper_bound, 1, mpi_int, i, to_slave_tag + 2, mpi_comm_world);         /* send allocated row of [first matrix] ith slave */         count = (upper_bound - lower_bound) * matrixsize;         printf("count: %d\n", count);         mpi_send(&(first[lower_bound][0]), count, mpi_double, i, to_slave_tag + 3, mpi_comm_world);       }       }     }   if (rank > 0)     {       //receive low bound master       mpi_recv(&matrixsize, 1, mpi_int, 0, to_slave_tag, mpi_comm_world, &status);       printf("matrix size: %d\n", matrixsize);       //receive low bound master       mpi_recv(&lower_bound, 1, mpi_int, 0, to_slave_tag + 1, mpi_comm_world, &status);       printf("lower bound: %d\n", lower_bound);       //next receive upper bound master       mpi_recv(&upper_bound, 1, mpi_int, 0, to_slave_tag + 2, mpi_comm_world, &status);       printf("upper bound: %d\n", upper_bound);       //finally receive row portion of [a] processed master       count = (upper_bound - lower_bound) * matrixsize;       printf("count: %d\n", count);        mpi_recv(&first[lower_bound][0], count, mpi_int, 0, to_slave_tag + 3, mpi_comm_world, &status);       printf("first[0][0]: %d\n", first[0][0]);     }   mpi_finalize();   return 0; }  void creatematrices(int msize) {   /* matrix cols */   first = malloc(msize * sizeof(int*));   /* matrix rows */   (int = 0; < msize; ++i)     first[i] = malloc(msize * sizeof(int));    srand(time(null));   (int = 0; < msize; ++i)     (int j = 0; j < msize; ++j)       first[i][j] = rand()%2; } 

and problem is:

*** process received signal *** signal: segmentation fault: 11 (11) signal code: address not mapped (1) failing @ address: 0x0 [ 0] 0   libsystem_platform.dylib            0x00007fff89cc8f1a _sigtramp + 26 [ 1] 0   libsystem_c.dylib                   0x00007fff73857070 __stack_chk_guard + 0 [ 2] 0   libdyld.dylib                       0x00007fff90f535c9 start + 1 [ 3] 0   ???                                 0x0000000000000001 0x0 + 1 *** end of error message *** 

to avoid (possibly high) latency costs of sending each row individual need create matrix in linear memory. done allocating enough memory entire matrix , setting pointers each row. here function modified so.

void creatematrices(int msize) {   /* initialize enough linear memory store whole matrix */   raw_data=malloc(msize*msize*sizeof(int*));    /* matrix row pointers i.e. point each consecutive row */   first = malloc(msize * sizeof(int*));    /* set pointers appropriate address */   (int = 0; < msize; ++i)     first[i] = raw_data + msize*i;    /* initialize random values */   srand(time(null));   (int = 0; < msize; ++i)     (int j = 0; j < msize; ++j)       first[i][j] = rand()%2; } 

the other major problem facing proper memory handling. should free matrices before allocating new ones on root rank.

you need allocate memory matrix on slave ranks before trying copy on data. needs in linear memory done in above function.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -