Minimal Example (Blocking Reconfiguration)ΒΆ
The following C example demonstrates a blocking reconfiguration using the Dyn_PSets library. Copy and adapt for quick experimentation.
int main(){
MPI_Session session;
dyn_pset_state_t *dyn_pset_state;
int terminate, reconfigured = 0;
char msg[256];
/* Initialize a Session so we can create MPI_Info objects before dyn_pset_init */
MPI_Session_init(MPI_INFO_NULL, MPI_ERRORS_ARE_FATAL, &session);
/* Set DynPSet verbosity and stdout as outputstream
dyn_pset_set_output(NULL, 0); // Increase to print DynPset debug output */
/* Initialize the DynPSet state */
dyn_pset_state = dyn_pset_init("mpi://WORLD", NULL, MPI_INFO_NULL, NULL, NULL, NULL, NULL);
/* In the general case an expansion might be canceled, so we check for it here */
if (NULL == dyn_pset_state){
MPI_Session_finalize(&session);
return 0;
}
/* Code path for dynamically added processes */
if(dyn_pset_state->dynamic_process){
/* Receive and print message from existing processes before terminating*/
MPI_Bcast(msg, 256, MPI_CHAR, 0, dyn_pset_state->mpicomm);
printf("NEW PROCESS: rank %d/%d received message '%s' from original processes\n",
dyn_pset_state->mpirank, dyn_pset_state->mpisize, msg);
/* Code path for original processes */
}else{
printf("ORIGINAL PROCESS: == BEFORE reconfiguration: Rank %d/%d\n", dyn_pset_state->mpirank, dyn_pset_state->mpisize);
/* Set the optimization information for the DynPSet state */
MPI_Info_create(&info);
MPI_Info_set(info, "mpi_num_procs_add", "2");
dyn_pset_set_info(dyn_pset_state, info);
MPI_Info_free(&info);
/* Reconfigure the DyPSet state */
dyn_pset_adapt(dyn_pset_state, &terminate, &reconfigured);
printf("ORIGINAL PROCESS: == AFTER reconfiguration: Rank %d/%d\n", dyn_pset_state->mpirank, dyn_pset_state->mpisize);
strcpy(msg, "Hello, new processes!");
MPI_Bcast(msg, 256, MPI_CHAR, 0, dyn_pset_state->mpicomm);
}
/* Finalize the DynPSet state */
dyn_pset_finalize(&dyn_pset_state, NULL);
/* Finalize our MPI Session */
MPI_Session_finalize(&session);
return 0;
}