#include "mpi.h" #include #include #include #include int main( int argc, char *argv[] ) { MPI_Comm parentcomm, intercomm; printf("Starting ...\n"); MPI_Init( &argc, &argv ); MPI_Comm_get_parent( &parentcomm ); if (parentcomm == MPI_COMM_NULL) { char *newHost; newHost = (char *)malloc(sizeof(char) * 255); //Open de file //Read process from source file //For this tests: //////////////////// CHANGE THIS LINE memcpy(newHost, "compute-0-0"); /////////////////// //Host for new process MPI_Info info; MPI_Info_create(&info); MPI_Info_set(info, "host", newHost); // Create 1 more process int errcodes[1]; MPI_Comm_spawn( "~/testSpawn/spawn_example", MPI_ARGV_NULL, 1, info, 0, MPI_COMM_WORLD, &intercomm, errcodes ); char hostname[256]; gethostname(hostname,255); printf(" I'm the parent %s.\n", hostname); //Merge between the intercomm and the intracomm MPI_Comm comm_new_and_old; MPI_Intercomm_merge(intercomm, 0, &comm_new_and_old); int npesNEW = -1; int myidNEW = -1; MPI_Comm_size(comm_new_and_old, &npesNEW); MPI_Comm_rank(comm_new_and_old, &myidNEW); printf(" Im %d of %d.\n", myidNEW, npesNEW); //PROBLEMATIC BARRIER. MPI_Barrier(comm_new_and_old); printf(" After barrier %d\n", myidNEW); MPI_Comm_free(&comm_new_and_old); } else { char hostname2[256]; gethostname(hostname2,255); printf(" I'm the spawned %s.\n", hostname2); //PROBLEMATIC BARRIER. MPI_Comm comm_new_and_old; MPI_Intercomm_merge(parentcomm, 1, &comm_new_and_old); int npesNEW = -1; int myidNEW = -1; MPI_Comm_size(comm_new_and_old, &npesNEW); MPI_Comm_rank(comm_new_and_old, &myidNEW); printf(" Im %d of %d (New).\n", myidNEW, npesNEW); //PROBLEMATIC BARRIER. MPI_Barrier(comm_new_and_old); printf(" After barrier (New proc.)\n"); MPI_Comm_free(&comm_new_and_old); } MPI_Finalize(); return 0; }