From: Martin Quinson Date: Fri, 19 May 2017 09:11:14 +0000 (+0200) Subject: Merge pull request #167 from simgrid/smpi_execute_public X-Git-Tag: v3.16~281^2~10^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8f8bd4e0654bdeadb3653e14cd6f3ee8aa465443?hp=8c39f23c04ffdf69507a05539bb032a10571ec57 Merge pull request #167 from simgrid/smpi_execute_public Add smpi_execute_public --- diff --git a/examples/msg/app-chainsend/broadcaster.c b/examples/msg/app-chainsend/broadcaster.c index f14a1be7fc..f17ed64827 100644 --- a/examples/msg/app-chainsend/broadcaster.c +++ b/examples/msg/app-chainsend/broadcaster.c @@ -11,9 +11,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_broadcaster, "Messages specific for the broadca xbt_dynar_t build_hostlist_from_hostcount(int hostcount) { xbt_dynar_t host_list = xbt_dynar_new(sizeof(char*), xbt_free_ref); - int i; - - for (i = 1; i <= hostcount; i++) { + for (int i = 1; i <= hostcount; i++) { char *hostname = bprintf("host%d", i); XBT_DEBUG("%s", hostname); xbt_dynar_push(host_list, &hostname); @@ -24,12 +22,12 @@ xbt_dynar_t build_hostlist_from_hostcount(int hostcount) int broadcaster_build_chain(broadcaster_t bc) { msg_task_t task = NULL; - char **cur = (char**)xbt_dynar_iterator_next(bc->it); - const char *me = "host0"; /* FIXME: hardcoded*/ /*MSG_host_get_name(MSG_host_self());*/ - const char *current_host = NULL; - const char *prev = NULL; - const char *next = NULL; - const char *last = NULL; + char** cur = (char**)xbt_dynar_iterator_next(bc->it); + const char* me = MSG_host_get_name(MSG_host_self()); + const char* current_host = NULL; + const char* prev = NULL; + const char* next = NULL; + const char* last = NULL; /* Build the chain if there's at least one peer */ if (cur != NULL) { @@ -62,8 +60,7 @@ int broadcaster_build_chain(broadcaster_t bc) int broadcaster_send_file(broadcaster_t bc) { - const char *me = "host0"; /* FIXME: hardcoded*/ /*MSG_host_get_name(MSG_host_self());*/ - //msg_comm_t comm = NULL; + const char* me = MSG_host_get_name(MSG_host_self()); msg_task_t task = NULL; bc->current_piece = 0; @@ -101,7 +98,7 @@ static void broadcaster_destroy(broadcaster_t bc) /* Destroy iterator and hostlist */ xbt_dynar_iterator_delete(bc->it); xbt_dynar_free(&bc->pending_sends); - xbt_dynar_free(&bc->host_list); /* FIXME: host names are not free'd */ + xbt_dynar_free(&bc->host_list); xbt_free(bc); } diff --git a/examples/msg/app-chainsend/iterator.c b/examples/msg/app-chainsend/iterator.c index 2d0eccc271..e36ab5dab1 100644 --- a/examples/msg/app-chainsend/iterator.c +++ b/examples/msg/app-chainsend/iterator.c @@ -17,7 +17,7 @@ xbt_dynar_iterator_t xbt_dynar_iterator_new(xbt_dynar_t list, xbt_dynar_t (*crit it->list = list; it->length = xbt_dynar_length(list); - it->indices_list = criteria_fn(it->length); //xbt_dynar_new(sizeof(int), NULL); + it->indices_list = criteria_fn(it->length); // Creates and fills a dynar of int it->criteria_fn = criteria_fn; it->current = 0; @@ -46,8 +46,7 @@ void xbt_dynar_iterator_delete(xbt_dynar_iterator_t it) xbt_dynar_t forward_indices_list(int size) { xbt_dynar_t indices_list = xbt_dynar_new(sizeof(int), NULL); - int i; - for (i = 0; i < size; i++) + for (int i = 0; i < size; i++) xbt_dynar_push_as(indices_list, int, i); return indices_list; } diff --git a/include/xbt/functional.hpp b/include/xbt/functional.hpp index 7596ef6f1e..10c16bf98a 100644 --- a/include/xbt/functional.hpp +++ b/include/xbt/functional.hpp @@ -39,11 +39,12 @@ public: {} void operator()() const { + char noarg[] = {'\0'}; const int argc = args_->size(); std::vector args = *args_; std::unique_ptr argv(new char*[argc + 1]); for (int i = 0; i != argc; ++i) - argv[i] = args[i].empty() ? const_cast(""): &args[i].front(); + argv[i] = args[i].empty() ? noarg : &args[i].front(); argv[argc] = nullptr; code_(argc, argv.get()); } diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index 5a6483624c..4a2dd5479f 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -21,8 +21,8 @@ namespace routing { class BypassRoute { public: explicit BypassRoute(NetPoint* gwSrc, NetPoint* gwDst) : gw_src(gwSrc), gw_dst(gwDst) {} - const NetPoint* gw_src; - const NetPoint* gw_dst; + NetPoint* gw_src; + NetPoint* gw_dst; std::vector links; }; @@ -292,14 +292,14 @@ bool NetZoneImpl::getBypassRoute(routing::NetPoint* src, routing::NetPoint* dst, "calls to getRoute", src->cname(), dst->cname(), bypassedRoute->links.size()); if (src != key.first) - getGlobalRoute(src, const_cast(bypassedRoute->gw_src), links, latency); + getGlobalRoute(src, bypassedRoute->gw_src, links, latency); for (surf::LinkImpl* link : bypassedRoute->links) { links->push_back(link); if (latency) *latency += link->latency(); } if (dst != key.second) - getGlobalRoute(const_cast(bypassedRoute->gw_dst), dst, links, latency); + getGlobalRoute(bypassedRoute->gw_dst, dst, links, latency); return true; } XBT_DEBUG("No bypass route from '%s' to '%s'.", src->cname(), dst->cname()); diff --git a/src/msg/msg_global.cpp b/src/msg/msg_global.cpp index 0d94715ff6..a75e536279 100644 --- a/src/msg/msg_global.cpp +++ b/src/msg/msg_global.cpp @@ -38,7 +38,7 @@ void MSG_init_nocheck(int *argc, char **argv) { xbt_getpid = &MSG_process_self_PID; if (!msg_global) { - msg_global = xbt_new0(s_MSG_Global_t, 1); + msg_global = new s_MSG_Global_t(); xbt_cfg_register_boolean("msg/debug-multiple-use", "no", _sg_cfg_cb_msg_debug_multiple_use, "Print backtraces of both processes when there is a conflict of multiple use of a task"); @@ -121,7 +121,7 @@ static void MSG_exit() { TRACE_surf_resource_utilization_release(); TRACE_end(); - free(msg_global); + delete msg_global; msg_global = nullptr; } diff --git a/src/msg/msg_io.cpp b/src/msg/msg_io.cpp index 060e256413..702e0abc92 100644 --- a/src/msg/msg_io.cpp +++ b/src/msg/msg_io.cpp @@ -118,19 +118,15 @@ sg_size_t MSG_file_read(msg_file_t fd, sg_size_t size) if (strcmp(storage_priv_src->hostname, MSG_host_self()->cname())) { /* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */ XBT_DEBUG("File is on %s remote host, initiate data transfer of %llu bytes.", storage_priv_src->hostname, read_size); - msg_host_t *m_host_list = nullptr; - m_host_list = xbt_new0(msg_host_t, 2); - - m_host_list[0] = MSG_host_self(); - m_host_list[1] = attached_host; - double flops_amount[] = { 0, 0}; - double bytes_amount[] = { 0, 0, static_cast(read_size), 0 }; + msg_host_t m_host_list[] = {MSG_host_self(), attached_host}; + double flops_amount[] = {0, 0}; + double bytes_amount[] = {0, 0, static_cast(read_size), 0}; msg_task_t task = MSG_parallel_task_create("file transfer for read", 2, m_host_list, flops_amount, bytes_amount, nullptr); msg_error_t transfer = MSG_parallel_task_execute(task); MSG_task_destroy(task); - xbt_free(m_host_list); + if(transfer != MSG_OK){ if (transfer == MSG_HOST_FAILURE) XBT_WARN("Transfer error, %s remote host just turned off!", attached_host->cname()); @@ -163,19 +159,15 @@ sg_size_t MSG_file_write(msg_file_t fd, sg_size_t size) if (strcmp(storage_priv_src->hostname, MSG_host_self()->cname())) { /* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */ XBT_DEBUG("File is on %s remote host, initiate data transfer of %llu bytes.", storage_priv_src->hostname, size); - msg_host_t *m_host_list = nullptr; - m_host_list = xbt_new0(msg_host_t, 2); - - m_host_list[0] = MSG_host_self(); - m_host_list[1] = attached_host; - double flops_amount[] = { 0, 0 }; - double bytes_amount[] = { 0, static_cast(size), 0, 0 }; + msg_host_t m_host_list[] = {MSG_host_self(), attached_host}; + double flops_amount[] = {0, 0}; + double bytes_amount[] = {0, static_cast(size), 0, 0}; msg_task_t task = MSG_parallel_task_create("file transfer for write", 2, m_host_list, flops_amount, bytes_amount, nullptr); msg_error_t transfer = MSG_parallel_task_execute(task); MSG_task_destroy(task); - free(m_host_list); + if(transfer != MSG_OK){ if (transfer == MSG_HOST_FAILURE) XBT_WARN("Transfer error, %s remote host just turned off!", attached_host->cname()); @@ -332,14 +324,14 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa char *mount_name; char *storage_name; xbt_dict_foreach(storage_list,cursor,mount_name,storage_name){ - char* file_mount_name = static_cast(xbt_malloc ((strlen(mount_name)+1))); - strncpy(file_mount_name,fullpath,strlen(mount_name)+1); + char* file_mount_name = static_cast(xbt_malloc(strlen(mount_name) + 1)); + strncpy(file_mount_name, fullpath, strlen(mount_name) + 1); file_mount_name[strlen(mount_name)] = '\0'; - if(!strcmp(file_mount_name,mount_name) && strlen(mount_name)>longest_prefix_length){ + if (!strcmp(file_mount_name, mount_name) && strlen(mount_name) > longest_prefix_length) { /* The current mount name is found in the full path and is bigger than the previous*/ longest_prefix_length = strlen(mount_name); - storage_dest = (msg_storage_t) xbt_lib_get_elm_or_null(storage_lib, storage_name); + storage_dest = (msg_storage_t)xbt_lib_get_elm_or_null(storage_lib, storage_name); } xbt_free(file_mount_name); } @@ -358,19 +350,15 @@ msg_error_t MSG_file_rcopy (msg_file_t file, msg_host_t host, const char* fullpa XBT_DEBUG("Initiate data transfer of %llu bytes between %s and %s.", read_size, storage_priv_src->hostname, host_name_dest); - msg_host_t *m_host_list = nullptr; - m_host_list = xbt_new0(msg_host_t, 2); - - m_host_list[0] = attached_host; - m_host_list[1] = host_dest; - double flops_amount[] = { 0, 0 }; - double bytes_amount[] = { 0, static_cast(read_size), 0, 0 }; + msg_host_t m_host_list[] = {attached_host, host_dest}; + double flops_amount[] = {0, 0}; + double bytes_amount[] = {0, static_cast(read_size), 0, 0}; msg_task_t task = MSG_parallel_task_create("file transfer for write", 2, m_host_list, flops_amount, bytes_amount, nullptr); msg_error_t transfer = MSG_parallel_task_execute(task); MSG_task_destroy(task); - xbt_free(m_host_list); + if(transfer != MSG_OK){ if (transfer == MSG_HOST_FAILURE) XBT_WARN("Transfer error, %s remote host just turned off!", host_name_dest); diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index 161300d350..ff2da6f47d 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -489,10 +489,11 @@ typedef void (*smpi_fortran_entry_point_type)(); static int smpi_run_entry_point(smpi_entry_point_type entry_point, std::vector args) { + char noarg[] = {'\0'}; const int argc = args.size(); std::unique_ptr argv(new char*[argc + 1]); for (int i = 0; i != argc; ++i) - argv[i] = args[i].empty() ? const_cast(""): &args[i].front(); + argv[i] = args[i].empty() ? noarg : &args[i].front(); argv[argc] = nullptr; int res = entry_point(argc, argv.get()); diff --git a/src/surf/network_ib.hpp b/src/surf/network_ib.hpp index ac9b8a8da5..f132f83f84 100644 --- a/src/surf/network_ib.hpp +++ b/src/surf/network_ib.hpp @@ -24,7 +24,7 @@ namespace simgrid { NetworkAction *action; double init_rate; ActiveComm() : destination(nullptr),action(nullptr),init_rate(-1){}; - ~ActiveComm(){}; + virtual ~ActiveComm() = default; }; class IBNode{ @@ -37,7 +37,7 @@ namespace simgrid { //number of comms the node is receiving int nbActiveCommsDown; explicit IBNode(int id) : id(id),nbActiveCommsDown(0){}; - ~IBNode(){}; + virtual ~IBNode() = default; }; class XBT_PRIVATE NetworkIBModel : public NetworkSmpiModel { diff --git a/src/surf/storage_interface.cpp b/src/surf/storage_interface.cpp index 19b836182f..554c9a22ff 100644 --- a/src/surf/storage_interface.cpp +++ b/src/surf/storage_interface.cpp @@ -6,7 +6,6 @@ #include "storage_interface.hpp" #include "surf_private.h" -#include "xbt/file.h" /* xbt_getline */ #include #include #include diff --git a/src/xbt/dict_cursor.c b/src/xbt/dict_cursor.c index ab5872c158..d9f3b14664 100644 --- a/src/xbt/dict_cursor.c +++ b/src/xbt/dict_cursor.c @@ -108,7 +108,8 @@ inline void xbt_dict_cursor_step(xbt_dict_cursor_t cursor) XBT_CDEBUG(xbt_dict_cursor, "next element: %p", current); } - while (current == NULL && ++line <= cursor->dict->table_size) { + while (current == NULL && (line + 1) <= cursor->dict->table_size) { + line++; XBT_CDEBUG(xbt_dict_cursor, "current is NULL, take the next line"); current = cursor->dict->table[line]; XBT_CDEBUG(xbt_dict_cursor, "element in the next line: %p", current); diff --git a/src/xbt/xbt_os_file.c b/src/xbt/xbt_os_file.c index 46dd79a42e..789c14118e 100644 --- a/src/xbt/xbt_os_file.c +++ b/src/xbt/xbt_os_file.c @@ -36,10 +36,7 @@ */ ssize_t xbt_getline(char **buf, size_t *n, FILE *stream) { - ssize_t i; - int ch; - - ch = getc(stream); + int ch = getc(stream); if (ferror(stream) || feof(stream)) return -1; @@ -48,15 +45,20 @@ ssize_t xbt_getline(char **buf, size_t *n, FILE *stream) *buf = xbt_malloc(*n); } - i = 0; + ssize_t i = 0; do { - if (i == *n) - *buf = xbt_realloc(*buf, *n += 512); - (*buf)[i++] = ch; + if (i == *n) { + *n += 512; + *buf = xbt_realloc(*buf, *n); + } + (*buf)[i] = ch; + i++; } while (ch != '\n' && (ch = getc(stream)) != EOF); - if (i == *n) - *buf = xbt_realloc(*buf, *n += 1); + if (i == *n) { + *n += 1; + *buf = xbt_realloc(*buf, *n); + } (*buf)[i] = '\0'; return i; diff --git a/teshsuite/smpi/macro-sample/macro-sample.c b/teshsuite/smpi/macro-sample/macro-sample.c index 4ae5dbad95..e1a4bf7edd 100644 --- a/teshsuite/smpi/macro-sample/macro-sample.c +++ b/teshsuite/smpi/macro-sample/macro-sample.c @@ -48,7 +48,8 @@ int main(int argc, char *argv[]) /* I want the standard error to go below 0.1 second. * Two tests at least will be run (count is not > 0) */ SMPI_SAMPLE_LOCAL(0, 0.1) { - if (verbose || n++ < 2) { + if (verbose || n < 2) { + n++; if (verbose) fprintf(stderr, "(%12.6f)", MPI_Wtime()); else diff --git a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp index bc5bbe5f7d..7d4323c5cf 100644 --- a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp +++ b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp @@ -38,9 +38,9 @@ static unsigned int int_random(int max) static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limit, unsigned int pw_max_limit, float rate_no_limit, int max_share, int mode) { - lmm_constraint_t *cnst = xbt_new0(lmm_constraint_t, nb_cnst); - lmm_variable_t *var = xbt_new0(lmm_variable_t, nb_var); - int *used = xbt_new0(int, nb_cnst); + lmm_constraint_t cnst[nb_cnst]; + lmm_variable_t var[nb_var]; + int used[nb_cnst]; int concurrency_share; lmm_system_t Sys = lmm_system_new(1); @@ -106,9 +106,6 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi for (int i = 0; i < nb_var; i++) lmm_variable_free(Sys, var[i]); lmm_system_free(Sys); - free(cnst); - free(var); - free(used); } unsigned int TestClasses [][4]= diff --git a/tools/simgrid.supp b/tools/simgrid.supp index 82cd7a8293..e15cfce365 100644 --- a/tools/simgrid.supp +++ b/tools/simgrid.supp @@ -72,6 +72,29 @@ fun:smpi_simulated_main_ } +#SMPI leaks the dlopen handle used for loading the program +{ + dlopen handle leaks (1/2) + Memcheck:Leak + match-leak-kinds:reachable + fun:malloc + ... + fun:dlopen@@GLIBC_* + ... + fun:main +} + +{ + dlopen handle leaks (2/2) + Memcheck:Leak + match-leak-kinds:reachable + fun:calloc + ... + fun:dlopen@@GLIBC_* + ... + fun:main +} + # Memory leaks appearing to be in libcgraph. They can be seen with the # following simple program: # ,----