Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #167 from simgrid/smpi_execute_public
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 19 May 2017 09:11:14 +0000 (11:11 +0200)
committerGitHub <noreply@github.com>
Fri, 19 May 2017 09:11:14 +0000 (11:11 +0200)
Add smpi_execute_public

14 files changed:
examples/msg/app-chainsend/broadcaster.c
examples/msg/app-chainsend/iterator.c
include/xbt/functional.hpp
src/kernel/routing/NetZoneImpl.cpp
src/msg/msg_global.cpp
src/msg/msg_io.cpp
src/smpi/smpi_global.cpp
src/surf/network_ib.hpp
src/surf/storage_interface.cpp
src/xbt/dict_cursor.c
src/xbt/xbt_os_file.c
teshsuite/smpi/macro-sample/macro-sample.c
teshsuite/surf/maxmin_bench/maxmin_bench.cpp
tools/simgrid.supp

index f14a1be..f17ed64 100644 (file)
@@ -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 charcurrent_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);
 }
 
index 2d0eccc..e36ab5d 100644 (file)
@@ -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;
 }
index 7596ef6..10c16bf 100644 (file)
@@ -39,11 +39,12 @@ public:
   {}
   void operator()() const
   {
+    char noarg[] = {'\0'};
     const int argc = args_->size();
     std::vector<std::string> args = *args_;
     std::unique_ptr<char*[]> argv(new char*[argc + 1]);
     for (int i = 0; i != argc; ++i)
-      argv[i] = args[i].empty() ? const_cast<char*>(""): &args[i].front();
+      argv[i] = args[i].empty() ? noarg : &args[i].front();
     argv[argc] = nullptr;
     code_(argc, argv.get());
   }
index 5a64836..4a2dd54 100644 (file)
@@ -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<surf::LinkImpl*> 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<NetPoint*>(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<NetPoint*>(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());
index 0d94715..a75e536 100644 (file)
@@ -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;
 }
 
index 060e256..702e0ab 100644 (file)
@@ -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<double>(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<double>(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<double>(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<double>(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<char *>(xbt_malloc ((strlen(mount_name)+1)));
-    strncpy(file_mount_name,fullpath,strlen(mount_name)+1);
+    char* file_mount_name = static_cast<char*>(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<double>(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<double>(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);
index 161300d..ff2da6f 100644 (file)
@@ -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<std::string> args)
 {
+  char noarg[]   = {'\0'};
   const int argc = args.size();
   std::unique_ptr<char*[]> argv(new char*[argc + 1]);
   for (int i = 0; i != argc; ++i)
-    argv[i] = args[i].empty() ? const_cast<char*>(""): &args[i].front();
+    argv[i] = args[i].empty() ? noarg : &args[i].front();
   argv[argc] = nullptr;
 
   int res = entry_point(argc, argv.get());
index ac9b8a8..f132f83 100644 (file)
@@ -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 {
index 19b8361..554c9a2 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "storage_interface.hpp"
 #include "surf_private.h"
-#include "xbt/file.h" /* xbt_getline */
 #include <boost/algorithm/string.hpp>
 #include <boost/algorithm/string/join.hpp>
 #include <boost/algorithm/string/split.hpp>
index ab5872c..d9f3b14 100644 (file)
@@ -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);
index 46dd79a..789c141 100644 (file)
  */
 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;
index 4ae5dba..e1a4bf7 100644 (file)
@@ -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
index bc5bbe5..7d4323c 100644 (file)
@@ -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]=
index 82cd7a8..e15cfce 100644 (file)
    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:
 # ,----