X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e9decd04ae6f5fb586c56fd5473f8b9b321143d2..54a0d3535520d228f830d6d0397fa2b0b26293de:/src/smpi/smpi_global.cpp diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index f6094d53e3..6dffca85ab 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -83,6 +83,8 @@ MPI_Errhandler *MPI_ERRORS_RETURN = nullptr; MPI_Errhandler *MPI_ERRORS_ARE_FATAL = nullptr; MPI_Errhandler *MPI_ERRHANDLER_NULL = nullptr; +void (*smpi_comm_copy_data_callback) (smx_activity_t, void*, size_t) = &smpi_comm_copy_buffer_callback; + #define MAILBOX_NAME_MAXLEN (5 + sizeof(int) * 2 + 1) static char *get_mailbox_name(char *str, int index) @@ -133,7 +135,7 @@ void smpi_process_init(int *argc, char ***argv) data->instance_id = instance_id; data->replaying = false; - static_cast(proc->data)->data = data; + static_cast(proc->data)->data = data; if (*argc > 3) { memmove(&(*argv)[0], &(*argv)[2], sizeof(char *) * (*argc - 2)); @@ -226,7 +228,7 @@ int smpi_global_size() smpi_process_data_t smpi_process_data() { - MsgActorExt* msgExt = static_cast(SIMIX_process_self()->data); + simgrid::MsgActorExt* msgExt = static_cast(SIMIX_process_self()->data); return static_cast(msgExt->data); } @@ -350,9 +352,9 @@ MPI_Comm smpi_process_comm_self() { smpi_process_data_t data = smpi_process_data(); if(data->comm_self==MPI_COMM_NULL){ - MPI_Group group = smpi_group_new(1); - data->comm_self = smpi_comm_new(group, nullptr); - smpi_group_set_mapping(group, smpi_process_index(), 0); + MPI_Group group = new simgrid::SMPI::Group(1); + data->comm_self = new simgrid::SMPI::Comm(group, nullptr); + group->set_mapping(smpi_process_index(), 0); } return data->comm_self; @@ -388,6 +390,11 @@ void print_request(const char *message, MPI_Request request) message, request, request->buf, request->size, request->src, request->dst, request->tag, request->flags); } +void smpi_comm_set_copy_data_callback(void (*callback) (smx_activity_t, void*, size_t)) +{ + smpi_comm_copy_data_callback = callback; +} + void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t buff_size) { XBT_DEBUG("Copy the data over"); @@ -400,7 +407,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b XBT_DEBUG("Privatization : We are copying from a zone inside global memory... Saving data to temp buffer !"); smpi_switch_data_segment( - (static_cast((static_cast(comm->src_proc->data)->data))->index)); + (static_cast((static_cast(comm->src_proc->data)->data))->index)); tmpbuff = static_cast(xbt_malloc(buff_size)); memcpy(tmpbuff, buff, buff_size); } @@ -409,7 +416,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b && ((char*)comm->dst_buff < smpi_start_data_exe + smpi_size_data_exe )){ XBT_DEBUG("Privatization : We are copying to a zone inside global memory - Switch data segment"); smpi_switch_data_segment( - (static_cast((static_cast(comm->dst_proc->data)->data))->index)); + (static_cast((static_cast(comm->dst_proc->data)->data))->index)); } memcpy(comm->dst_buff, tmpbuff, buff_size); @@ -597,13 +604,13 @@ void smpi_global_init() //if the process was launched through smpirun script we generate a global mpi_comm_world //if not, we let MPI_COMM_NULL, and the comm world will be private to each mpi instance if(smpirun){ - group = smpi_group_new(process_count); - MPI_COMM_WORLD = smpi_comm_new(group, nullptr); + group = new simgrid::SMPI::Group(process_count); + MPI_COMM_WORLD = new simgrid::SMPI::Comm(group, nullptr); MPI_Attr_put(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, reinterpret_cast(process_count)); msg_bar_t bar = MSG_barrier_init(process_count); for (i = 0; i < process_count; i++) { - smpi_group_set_mapping(group, i, i); + group->set_mapping(i, i); process_data[i]->finalization_barrier = bar; } } @@ -615,17 +622,17 @@ void smpi_global_destroy() smpi_bench_destroy(); if (MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED){ - while (smpi_group_unuse(smpi_comm_group(MPI_COMM_WORLD)) > 0); + while (MPI_COMM_WORLD->group()->unuse() > 0); MSG_barrier_destroy(process_data[0]->finalization_barrier); }else{ smpi_deployment_cleanup_instances(); } for (int i = 0; i < count; i++) { if(process_data[i]->comm_self!=MPI_COMM_NULL){ - smpi_comm_destroy(process_data[i]->comm_self); + process_data[i]->comm_self->destroy(); } if(process_data[i]->comm_intra!=MPI_COMM_NULL){ - smpi_comm_destroy(process_data[i]->comm_intra); + process_data[i]->comm_intra->destroy(); } xbt_os_timer_free(process_data[i]->timer); xbt_mutex_destroy(process_data[i]->mailboxes_mutex); @@ -635,11 +642,11 @@ void smpi_global_destroy() process_data = nullptr; if (MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED){ - smpi_comm_cleanup_smp(MPI_COMM_WORLD); - smpi_comm_cleanup_attributes(MPI_COMM_WORLD); + MPI_COMM_WORLD->cleanup_smp(); + MPI_COMM_WORLD->cleanup_attributes(); if(smpi_coll_cleanup_callback!=nullptr) smpi_coll_cleanup_callback(); - xbt_free(MPI_COMM_WORLD); + delete MPI_COMM_WORLD; } MPI_COMM_WORLD = MPI_COMM_NULL; @@ -770,6 +777,18 @@ static void smpi_init_options(){ smpi_privatize_global_variables = xbt_cfg_get_boolean("smpi/privatize-global-variables"); if (smpi_cpu_threshold < 0) smpi_cpu_threshold = DBL_MAX; + + char* val = xbt_cfg_get_string("smpi/shared-malloc"); + if (!strcasecmp(val, "yes") || !strcmp(val, "1") || !strcasecmp(val, "on") || !strcasecmp(val, "global")) { + smpi_cfg_shared_malloc = shmalloc_global; + } else if (!strcasecmp(val, "local")) { + smpi_cfg_shared_malloc = shmalloc_local; + } else if (!strcasecmp(val, "no") || !strcmp(val, "0") || !strcasecmp(val, "off")) { + smpi_cfg_shared_malloc = shmalloc_none; + } else { + xbt_die("Invalid value '%s' for option smpi/shared-malloc. Possible values: 'on' or 'global', 'local', 'off'", + val); + } } int smpi_main(int (*realmain) (int argc, char *argv[]), int argc, char *argv[]) @@ -796,7 +815,7 @@ int smpi_main(int (*realmain) (int argc, char *argv[]), int argc, char *argv[]) // parse the platform file: get the host list SIMIX_create_environment(argv[1]); - SIMIX_comm_set_copy_data_callback(&smpi_comm_copy_buffer_callback); + SIMIX_comm_set_copy_data_callback(smpi_comm_copy_data_callback); SIMIX_function_register_default(realmain); SIMIX_launch_application(argv[2]);