c - Recursive mpi spawns (spawn from spawn) -


the problem quite simple: manager spawns x workers. each worker spawns 2 more workers if condition met. works fine long workers don't spawn anymore (so condition not met, or if first "original" worker spawns; hangs other workers).

manager code:

int main(int argc, char *argv[]) { int myrank, numworkers, tag = 3, sum = 0, k = 1; mpi_status status; mpi_comm workercomm;  numworkers = atoi(argv[1]);  mpi_init(&argc, &argv); mpi_comm_rank(mpi_comm_world, &myrank); mpi_comm_spawn("project_child",         mpi_argv_null, numworkers, mpi_info_null, 0, mpi_comm_self,         &workercomm, mpi_errcodes_ignore);  (int = 0; < numworkers; i++) { //sends 1,2,3... workers     k=i+1;     mpi_send(&k, 1, mpi_int, i, tag, workercomm); }  (int = 0; < numworkers; i++) { //receives int worker     mpi_recv(&k, 1, mpi_int, i, tag, workercomm, &status);     sum += k; } printf("%d \n", sum);  mpi_comm_free(&workercomm); mpi_finalize(); return 0; } 

worker code:

int main(int argc, char *argv[]) { int k, myrank, tag = 3; mpi_status status; mpi_comm parentcomm;  mpi_init(&argc, &argv); mpi_comm_rank(mpi_comm_world, &myrank); mpi_comm_get_parent(&parentcomm);  mpi_recv(&k, 1, mpi_int, 0, tag, parentcomm, &status); //recv k printf("child %d: k=%d\n", myrank, k); k++; if (k<5) { // && myrank==0) {     mpi_comm childparentcomm;     mpi_comm_spawn("project_child",             mpi_argv_null, 2, mpi_info_null, 0, mpi_comm_self,             &childparentcomm, mpi_errcodes_ignore);     //problem might here?^      //sends k first worker_child     mpi_send(&k, 1, mpi_int, 0, tag, childparentcomm);      //!!!!!!! hangs here if worker != 0      k++;     //sends k+1 second worker_child     mpi_send(&k, 1, mpi_int, 1, tag, childparentcomm);      int k1, k2;     mpi_recv(&k1, 1, mpi_int, 0, tag, childparentcomm, &status);     mpi_recv(&k2, 1, mpi_int, 1, tag, childparentcomm, &status);     k = k1 + k2;     mpi_comm_free(&childparentcomm); } mpi_send(&k, 1, mpi_int, 0, tag, parentcomm); mpi_comm_free(&parentcomm); mpi_finalize(); return 0; } 

ok, changed code simplify it.

tested code, problem same: worker0 spawns additional children (even child0 spawns additional children), others don't , hang @ second send. if condition (if (k<5) && myrank==0), work, that's not need.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -