c - MPI segmentation fault with MPI_Bcast communication -


i have mpi program works fine if use 1 node, , if have multiple nodes communications off runs fine (albeit wrong numerical result since calculation needs communication). address not mapped segmentation fault when run communications.

i have cut down program basic outline below. have struct defined outside main program. have array of these structs, array of structs divided amongst mpi nodes, example may have 500 particles , 5 nodes first node operates on 0-99 , on. after each operation nodes need synchronise data, try achieve mpi_bcast.

is there problem using global struct in communication between mpi nodes? or why else might communication structure give segmentation fault.

#define buffer 2  typedef struct {     double x[buffer]; } particle;  particle *body;  void communication(int i_buf, int size){    // there n particles have been operated on various mpi nodes   // seek synchronize data between nodes   #pragma omp parallel   for(int nbody = 0; nbody < n; nbody++)   {     // below returns node number operated on particle       int node = isnode(nbody, size);      mpi_bcast(&(body[nbody].x[i_buf]), 1, mpi_double, node, mpi_comm_world);   }  }  void main() {  mpi_init(&argc, &argv);  int rank, size; mpi_comm_rank(mpi_comm_world, &rank); mpi_comm_size(mpi_comm_world, &size);  body = (particle*) calloc((size_t)n, sizeof(particle));    int adjust_a, adjust_b, a, b;   adjust_a = min(rank, n % size);   adjust_b = min(rank + 1, n % size);   = n / size * rank + adjust_a;   b = n / size * (rank + 1) + adjust_b;     int i_buf, i_buf_old;    for(int i_time = 0; i_time <= time_steps; i_time++)   {      i_buf = mod(i_time, buffer);     i_buf_old = mod(i_time - 1, buffer);      #pragma omp sections     {       #pragma omp section       {         compute(i_buf, i_buf_old, a, b); // calc         communication(i_buf, size);       }       #pragma omp section       {       if((i_time != 0) && (rank == 0))         logthread(i_buf_old); // writes file       }     }    } 

my full struct is:

typedef struct {     double mass;     double x[buffer];     double y[buffer];     double z[buffer];     double vx[buffer];     double vy[buffer];     double vz[buffer];     double fx[buffer];     double fy[buffer];     double fz[buffer]; } particle; 

it sounds might using wrong tool job. if you're trying aggregate array of data of processes , make sure processes have result of aggregation, should using mpi_allgather.

this function pretty want. if you're in situation each processes has data (an integer instance) this:

0)    0 1)    1 2)    2 3)    3 

when allgather, result this:

0) 0 1 2 3 1) 0 1 2 3 2) 0 1 2 3 3) 0 1 2 3 

if, instance, needed data aggregated in 1 place (such rank 0), use mpi_gather, this:

0) 0 1 2 3 1)    1 2)    2 3)    3 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -