X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/156df478fec05131317179a0147670b04f1e6493..ad0a588bd29ee5715a65929a6ac2ebb8ff05cd54:/src/smpi/smpi_global.c diff --git a/src/smpi/smpi_global.c b/src/smpi/smpi_global.c index d17f4bd9f6..12da83c2b2 100644 --- a/src/smpi/smpi_global.c +++ b/src/smpi/smpi_global.c @@ -34,6 +34,7 @@ typedef struct s_smpi_process_data { char state; int sampling; /* inside an SMPI_SAMPLE_ block? */ char* instance_id; + xbt_bar_t finalization_barrier; } s_smpi_process_data_t; static smpi_process_data_t *process_data = NULL; @@ -78,17 +79,18 @@ void smpi_process_init(int *argc, char ***argv) int rank = atoi((*argv)[2]); index = SIMIX_process_get_PID(proc) -1; -#ifdef SMPI_F2C - smpi_current_rank = index; -#endif if(!index_to_process_data){ index_to_process_data=(int*)xbt_malloc(SIMIX_process_count()*sizeof(int)); } - MPI_Comm* temp_comm_world = smpi_deployment_register_process(instance_id, rank, index); + MPI_Comm* temp_comm_world; + xbt_bar_t temp_bar; + smpi_deployment_register_process(instance_id, rank, index, &temp_comm_world ,&temp_bar); data = smpi_process_remote_data(index); data->comm_world = temp_comm_world; + if(temp_bar != NULL) data->finalization_barrier = temp_bar; data->index = index; data->instance_id = instance_id; + xbt_free(simcall_process_get_data(proc)); simcall_process_set_data(proc, data); if (*argc > 3) { free((*argv)[1]); @@ -128,44 +130,10 @@ void smpi_process_destroy(void) */ void smpi_process_finalize(void) { -#if 0 - // wait for all pending asynchronous comms to finish - while (SIMIX_process_has_pending_comms(SIMIX_process_self())) { - simcall_process_sleep(0.01); - } -#else - int i; - int size = smpi_comm_size(MPI_COMM_WORLD); - int rank = smpi_comm_rank(MPI_COMM_WORLD); - /* All non-root send & receive zero-length message. */ - if (rank > 0) { - smpi_mpi_ssend (NULL, 0, MPI_BYTE, 0, - COLL_TAG_BARRIER, - MPI_COMM_WORLD); - smpi_mpi_recv (NULL, 0, MPI_BYTE, 0, - COLL_TAG_BARRIER, - MPI_COMM_WORLD, MPI_STATUS_IGNORE); - } - /* The root collects and broadcasts the messages. */ - else { - MPI_Request* requests; - requests = (MPI_Request*)malloc( size * sizeof(MPI_Request) ); - for (i = 1; i < size; ++i) { - requests[i] = smpi_mpi_irecv(NULL, 0, MPI_BYTE, MPI_ANY_SOURCE, - COLL_TAG_BARRIER, MPI_COMM_WORLD - ); - } - smpi_mpi_waitall( size-1, requests+1, MPI_STATUSES_IGNORE ); - for (i = 1; i < size; ++i) { - requests[i] = smpi_mpi_issend(NULL, 0, MPI_BYTE, i, - COLL_TAG_BARRIER, - MPI_COMM_WORLD - ); - } - smpi_mpi_waitall( size-1, requests+1, MPI_STATUSES_IGNORE ); - free( requests ); - } -#endif + int index = smpi_process_index(); + // wait for all pending asynchronous comms to finish + xbt_barrier_wait(process_data[index_to_process_data[index]]->finalization_barrier); + } /** @@ -201,33 +169,6 @@ void smpi_process_mark_as_initialized(void) } -#ifdef SMPI_F2C -int smpi_process_argc(void) -{ - smpi_process_data_t data = smpi_process_data(); - return data->argc ? *(data->argc) - 1 : 0; -} - -int smpi_process_getarg(integer * index, char *dst, ftnlen len) -{ - smpi_process_data_t data = smpi_process_data(); - char *arg; - ftnlen i; - - if (!data->argc || !data->argv || *index < 1 || *index >= *(data->argc)) { - return -1; - } - arg = (*data->argv)[*index]; - for (i = 0; i < len && arg[i] != '\0'; i++) { - dst[i] = arg[i]; - } - for (; i < len; i++) { - dst[i] = ' '; - } - return 0; -} -#endif - int smpi_global_size(void) { char *value = getenv("SMPI_GLOBAL_SIZE"); @@ -413,6 +354,10 @@ static void smpi_check_options(){ } } +int smpi_enabled(void) { + return process_data != NULL; +} + void smpi_global_init(void) { int i; @@ -441,6 +386,7 @@ void smpi_global_init(void) process_data[i]->comm_world = NULL; process_data[i]->state = SMPI_UNINITIALIZED; process_data[i]->sampling = 0; + process_data[i]->finalization_barrier = NULL; } //if the process was launched through smpirun script //we generate a global mpi_comm_world @@ -449,9 +395,12 @@ void smpi_global_init(void) if(smpirun){ group = smpi_group_new(process_count); MPI_COMM_WORLD = smpi_comm_new(group, NULL); + xbt_bar_t bar=xbt_barrier_init(process_count); + MPI_UNIVERSE_SIZE = smpi_comm_size(MPI_COMM_WORLD); for (i = 0; i < process_count; i++) { smpi_group_set_mapping(group, i, i); + process_data[i]->finalization_barrier = bar; } } } @@ -465,6 +414,9 @@ void smpi_global_destroy(void) if (MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED){ while (smpi_group_unuse(smpi_comm_group(MPI_COMM_WORLD)) > 0); xbt_free(MPI_COMM_WORLD); + xbt_barrier_destroy(process_data[0]->finalization_barrier); + }else{ + smpi_deployment_cleanup_instances(); } MPI_COMM_WORLD = MPI_COMM_NULL; for (i = 0; i < count; i++) { @@ -486,12 +438,6 @@ void smpi_global_destroy(void) smpi_free_static(); } -/* Fortran specific stuff */ -/* With smpicc, the following weak symbols are used */ -/* With smpiff, the following weak symbols are replaced by those in libf2c */ -int __attribute__ ((weak)) xargc; -char ** __attribute__ ((weak)) xargv; - #ifndef WIN32 void __attribute__ ((weak)) user_main_() { @@ -511,10 +457,6 @@ int __attribute__ ((weak)) main(int argc, char **argv) return smpi_main(smpi_simulated_main_, argc, argv); } -int __attribute__ ((weak)) MAIN__() -{ - return smpi_main(smpi_simulated_main_, xargc, xargv); -}; #endif static void smpi_init_logs(){ @@ -539,6 +481,7 @@ static void smpi_init_logs(){ XBT_LOG_CONNECT(smpi_mpi_dt); XBT_LOG_CONNECT(smpi_pmpi); XBT_LOG_CONNECT(smpi_replay); + XBT_LOG_CONNECT(smpi_rma); }