Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove useless new/delete (please sonar).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 20 Nov 2020 23:19:38 +0000 (00:19 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 21 Nov 2020 17:15:05 +0000 (18:15 +0100)
18 files changed:
examples/s4u/app-chainsend/s4u-app-chainsend.cpp
examples/s4u/energy-link/s4u-energy-link.cpp
src/instr/instr_platform.cpp
src/kernel/routing/RoutedZone.cpp
src/kernel/routing/TorusZone.cpp
src/mc/sosp/Snapshot_test.cpp
src/plugins/file_system/s4u_FileSystem.cpp
src/simdag/sd_task.cpp
src/smpi/bindings/smpi_f77_coll.cpp
src/smpi/bindings/smpi_f77_type.cpp
src/smpi/bindings/smpi_pmpi_coll.cpp
src/smpi/include/smpi_file.hpp
src/smpi/internals/smpi_global.cpp
src/smpi/internals/smpi_replay.cpp
src/smpi/mpi/smpi_datatype_derived.cpp
src/smpi/mpi/smpi_group.cpp
src/smpi/mpi/smpi_topo.cpp
teshsuite/s4u/actor-suspend/actor-suspend.cpp

index ffce1cd..d04d43e 100644 (file)
@@ -139,30 +139,26 @@ static void peer()
 {
   XBT_DEBUG("peer");
 
-  auto* p = new Peer();
+  Peer p;
 
   double start_time = simgrid::s4u::Engine::get_clock();
-  p->joinChain();
-  p->forwardFile();
+  p.joinChain();
+  p.forwardFile();
 
-  simgrid::s4u::Comm::wait_all(&p->pending_sends);
+  simgrid::s4u::Comm::wait_all(&p.pending_sends);
   double end_time = simgrid::s4u::Engine::get_clock();
 
-  XBT_INFO("### %f %llu bytes (Avg %f MB/s); copy finished (simulated).", end_time - start_time, p->received_bytes,
-           p->received_bytes / 1024.0 / 1024.0 / (end_time - start_time));
-
-  delete p;
+  XBT_INFO("### %f %llu bytes (Avg %f MB/s); copy finished (simulated).", end_time - start_time, p.received_bytes,
+           p.received_bytes / 1024.0 / 1024.0 / (end_time - start_time));
 }
 
 static void broadcaster(int hostcount, unsigned int piece_count)
 {
   XBT_DEBUG("broadcaster");
 
-  auto* bc = new Broadcaster(hostcount, piece_count);
-  bc->buildChain();
-  bc->sendFile();
-
-  delete bc;
+  Broadcaster bc(hostcount, piece_count);
+  bc.buildChain();
+  bc.sendFile();
 }
 
 int main(int argc, char* argv[])
index 38cad52..a44422e 100644 (file)
@@ -52,7 +52,7 @@ static void receiver(std::vector<std::string> args)
     void* res = mailbox->get();
     xbt_free(res);
   } else {
-    auto* data = new void*[flow_amount];
+    std::vector<void*> data(flow_amount);
 
     // Start all comms in parallel, and wait for their completion in one shot
     std::vector<simgrid::s4u::CommPtr> comms;
@@ -62,7 +62,6 @@ static void receiver(std::vector<std::string> args)
     simgrid::s4u::Comm::wait_all(&comms);
     for (int i = 0; i < flow_amount; i++)
       xbt_free(data[i]);
-    delete[] data;
   }
   XBT_INFO("receiver done.");
 }
index 4f7288a..5b88ebd 100644 (file)
@@ -137,17 +137,15 @@ static void recursiveGraphExtraction(const simgrid::s4u::NetZone* netzone, simgr
   }
 
   auto* graph = xbt_graph_new_graph(0, nullptr);
-  auto* nodes = new std::map<std::string, xbt_node_t>();
-  auto* edges = new std::map<std::string, xbt_edge_t>();
+  std::map<std::string, xbt_node_t> nodes;
+  std::map<std::string, xbt_edge_t> edges;
 
-  netzone->get_impl()->get_graph(graph, nodes, edges);
-  for (auto elm : *edges) {
+  netzone->get_impl()->get_graph(graph, &nodes, &edges);
+  for (auto elm : edges) {
     const xbt_edge* edge = elm.second;
     linkContainers(simgrid::instr::Container::by_name(static_cast<const char*>(edge->src->data)),
                    simgrid::instr::Container::by_name(static_cast<const char*>(edge->dst->data)), filter);
   }
-  delete nodes;
-  delete edges;
   xbt_graph_free_graph(graph, xbt_free_f, xbt_free_f, nullptr);
 }
 
@@ -225,9 +223,9 @@ namespace instr {
 void platform_graph_export_graphviz(const std::string& output_filename)
 {
   auto* g     = xbt_graph_new_graph(0, nullptr);
-  auto* nodes = new std::map<std::string, xbt_node_t>();
-  auto* edges = new std::map<std::string, xbt_edge_t>();
-  s4u::Engine::get_instance()->get_netzone_root()->extract_xbt_graph(g, nodes, edges);
+  std::map<std::string, xbt_node_t> nodes;
+  std::map<std::string, xbt_edge_t> edges;
+  s4u::Engine::get_instance()->get_netzone_root()->extract_xbt_graph(g, &nodes, &edges);
 
   std::ofstream fs;
   fs.open(output_filename, std::ofstream::out);
@@ -243,10 +241,10 @@ void platform_graph_export_graphviz(const std::string& output_filename)
   fs << "  node [shape=box, style=filled]" << std::endl;
   fs << "  node [width=.3, height=.3, style=filled, color=skyblue]" << std::endl << std::endl;
 
-  for (auto const& elm : *nodes)
+  for (auto const& elm : nodes)
     fs << "  \"" << elm.first << "\";" << std::endl;
 
-  for (auto const& elm : *edges) {
+  for (auto const& elm : edges) {
     const char* src_s = static_cast<char*>(elm.second->src->data);
     const char* dst_s = static_cast<char*>(elm.second->dst->data);
     if (g->directed)
@@ -258,8 +256,6 @@ void platform_graph_export_graphviz(const std::string& output_filename)
   fs.close();
 
   xbt_graph_free_graph(g, xbt_free_f, xbt_free_f, nullptr);
-  delete nodes;
-  delete edges;
 }
 
 /* Callbacks */
@@ -368,11 +364,10 @@ static void on_action_state_change(kernel::resource::Action const& action,
 static void on_platform_created()
 {
   currentContainer.clear();
-  auto* filter = new std::set<std::string>();
+  std::set<std::string> filter;
   XBT_DEBUG("Starting graph extraction.");
-  recursiveGraphExtraction(s4u::Engine::get_instance()->get_netzone_root(), Container::get_root(), filter);
+  recursiveGraphExtraction(s4u::Engine::get_instance()->get_netzone_root(), Container::get_root(), &filter);
   XBT_DEBUG("Graph extraction finished.");
-  delete filter;
   dump_buffer(true);
 }
 
index 7619377..2823682 100644 (file)
@@ -68,9 +68,9 @@ void RoutedZone::get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt
       if (my_src == my_dst)
         continue;
 
-      auto* route = new RouteCreationArgs();
+      RouteCreationArgs route;
 
-      get_local_route(my_src, my_dst, route, nullptr);
+      get_local_route(my_src, my_dst, &route, nullptr);
 
       XBT_DEBUG("get_route_and_latency %s -> %s", my_src->get_cname(), my_dst->get_cname());
 
@@ -79,15 +79,15 @@ void RoutedZone::get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt
       const char *previous_name;
       const char *current_name;
 
-      if (route->gw_src) {
-        previous      = new_xbt_graph_node(graph, route->gw_src->get_cname(), nodes);
-        previous_name = route->gw_src->get_cname();
+      if (route.gw_src) {
+        previous      = new_xbt_graph_node(graph, route.gw_src->get_cname(), nodes);
+        previous_name = route.gw_src->get_cname();
       } else {
         previous      = new_xbt_graph_node(graph, my_src->get_cname(), nodes);
         previous_name = my_src->get_cname();
       }
 
-      for (auto const& link : route->link_list) {
+      for (auto const& link : route.link_list) {
         const char* link_name = link->get_cname();
         current               = new_xbt_graph_node(graph, link_name, nodes);
         current_name          = link_name;
@@ -97,17 +97,15 @@ void RoutedZone::get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt
         previous_name = current_name;
       }
 
-      if (route->gw_dst) {
-        current      = new_xbt_graph_node(graph, route->gw_dst->get_cname(), nodes);
-        current_name = route->gw_dst->get_cname();
+      if (route.gw_dst) {
+        current      = new_xbt_graph_node(graph, route.gw_dst->get_cname(), nodes);
+        current_name = route.gw_dst->get_cname();
       } else {
         current      = new_xbt_graph_node(graph, my_dst->get_cname(), nodes);
         current_name = my_dst->get_cname();
       }
       new_xbt_graph_edge(graph, previous, current, edges);
       XBT_DEBUG("  %s -> %s", previous_name, current_name);
-
-      delete route;
     }
   }
 }
index 6323da9..ac9177e 100644 (file)
@@ -107,8 +107,8 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
    * both arrays, we can easily assess whether we need to route into this dimension or not.
    */
   const unsigned int dsize = dimensions_.size();
-  auto* myCoords                = new unsigned int[dsize];
-  auto* targetCoords            = new unsigned int[dsize];
+  std::vector<unsigned int> myCoords(dsize);
+  std::vector<unsigned int> targetCoords(dsize);
   unsigned int dim_size_product = 1;
   for (unsigned i = 0; i < dsize; i++) {
     unsigned cur_dim_size = dimensions_[i];
@@ -185,8 +185,6 @@ void TorusZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
 
     current_node = next_node;
   }
-  delete[] myCoords;
-  delete[] targetCoords;
 }
 } // namespace routing
 } // namespace kernel
index f253bff..2921318 100644 (file)
@@ -158,15 +158,14 @@ void snap_test_helper::read_pointer()
 {
   prologue_return ret = prologue(1);
   memcpy(ret.src, &mc_model_checker, sizeof(void*));
-  const simgrid::mc::Region* region2 = new simgrid::mc::Region(simgrid::mc::RegionType::Data, ret.src, ret.size);
+  const simgrid::mc::Region region2(simgrid::mc::RegionType::Data, ret.src, ret.size);
   INFO("Mismtach in MC_region_read_pointer()");
-  REQUIRE(MC_region_read_pointer(region2, ret.src) == mc_model_checker);
+  REQUIRE(MC_region_read_pointer(&region2, ret.src) == mc_model_checker);
 
   munmap(ret.dstn, ret.size);
   munmap(ret.src, ret.size);
   delete ret.region0;
   delete ret.region;
-  delete region2;
 }
 
 /*************** End: class snap_test_helper *****************************/
index 32cf623..25c6caf 100644 (file)
@@ -463,15 +463,14 @@ int File::remote_copy(sg_host_t host, const std::string& fullpath)
   }
 
   /* Create file on remote host, write it and close it */
-  auto* fd = new File(fullpath, dst_host, nullptr);
+  File fd(fullpath, dst_host, nullptr);
   if (local_storage_) {
-    sg_size_t write_size = fd->local_storage_->write(read_size);
-    fd->local_storage_->extension<FileSystemStorageExt>()->incr_used_size(write_size);
-    (*(fd->local_storage_->extension<FileSystemStorageExt>()->get_content()))[path_] = size_;
+    sg_size_t write_size = fd.local_storage_->write(read_size);
+    fd.local_storage_->extension<FileSystemStorageExt>()->incr_used_size(write_size);
+    (*(fd.local_storage_->extension<FileSystemStorageExt>()->get_content()))[path_] = size_;
   }
   if (local_disk_)
-    fd->write(read_size);
-  delete fd;
+    fd.write(read_size);
   return 0;
 }
 
index 43b1489..e85a500 100644 (file)
@@ -962,12 +962,11 @@ void SD_task_schedulev(SD_task_t task, int count, const sg_host_t * list)
 void SD_task_schedulel(SD_task_t task, int count, ...)
 {
   va_list ap;
-  auto* list = new sg_host_t[count];
+  std::vector<sg_host_t> list(count);
   va_start(ap, count);
   for (int i=0; i<count; i++)
     list[i] = va_arg(ap, sg_host_t);
 
   va_end(ap);
-  SD_task_schedulev(task, count, list);
-  delete[] list;
+  SD_task_schedulev(task, count, list.data());
 }
index 0db71ca..2b4916a 100644 (file)
@@ -119,18 +119,16 @@ void mpi_reduce_scatter_block_ (void *sendbuf, void *recvbuf, int* recvcount, in
 void mpi_alltoallw_ ( void *sendbuf, int *sendcnts, int *sdispls, int* old_sendtypes, void *recvbuf, int *recvcnts,
                       int *rdispls, int* old_recvtypes, int* comm, int* ierr){
   int size = simgrid::smpi::Comm::f2c(*comm)->size();
-  auto* sendtypes = new MPI_Datatype[size];
-  auto* recvtypes = new MPI_Datatype[size];
+  std::vector<MPI_Datatype> sendtypes(size);
+  std::vector<MPI_Datatype> recvtypes(size);
   for(int i=0; i< size; i++){
     if(FORT_IN_PLACE(sendbuf)!=MPI_IN_PLACE)
       sendtypes[i] = simgrid::smpi::Datatype::f2c(old_sendtypes[i]);
     recvtypes[i] = simgrid::smpi::Datatype::f2c(old_recvtypes[i]);
   }
   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
- *ierr = MPI_Alltoallw( sendbuf, sendcnts, sdispls, sendtypes, recvbuf, recvcnts, rdispls,
-                        recvtypes, simgrid::smpi::Comm::f2c(*comm));
-  delete[] sendtypes;
-  delete[] recvtypes;
+  *ierr   = MPI_Alltoallw(sendbuf, sendcnts, sdispls, sendtypes.data(), recvbuf, recvcnts, rdispls, recvtypes.data(),
+                        simgrid::smpi::Comm::f2c(*comm));
 }
 
 void mpi_exscan_ (void *sendbuf, void *recvbuf, int* count, int* datatype, int* op, int* comm, int* ierr){
@@ -301,21 +299,19 @@ void mpi_ialltoallw_ ( void *sendbuf, int *sendcnts, int *sdispls, int* old_send
                       int *rdispls, int* old_recvtypes, int* comm, int* request, int* ierr){
   MPI_Request req;
   int size = simgrid::smpi::Comm::f2c(*comm)->size();
-  auto* sendtypes = new MPI_Datatype[size];
-  auto* recvtypes = new MPI_Datatype[size];
+  std::vector<MPI_Datatype> sendtypes(size);
+  std::vector<MPI_Datatype> recvtypes(size);
   for(int i=0; i< size; i++){
     if(FORT_IN_PLACE(sendbuf)!=MPI_IN_PLACE)
       sendtypes[i] = simgrid::smpi::Datatype::f2c(old_sendtypes[i]);
     recvtypes[i] = simgrid::smpi::Datatype::f2c(old_recvtypes[i]);
   }
   sendbuf = static_cast<char *>( FORT_IN_PLACE(sendbuf));
*ierr = MPI_Ialltoallw( sendbuf, sendcnts, sdispls, sendtypes, recvbuf, recvcnts, rdispls,
-                        recvtypes, simgrid::smpi::Comm::f2c(*comm), &req);
 *ierr   = MPI_Ialltoallw(sendbuf, sendcnts, sdispls, sendtypes.data(), recvbuf, recvcnts, rdispls, recvtypes.data(),
+                         simgrid::smpi::Comm::f2c(*comm), &req);
   if(*ierr == MPI_SUCCESS) {
     *request = req->add_f();
   }
-  delete[] sendtypes;
-  delete[] recvtypes;
 }
 
 void mpi_iexscan_ (void *sendbuf, void *recvbuf, int* count, int* datatype, int* op, int* comm, int* request, int* ierr){
index 648c7d5..c36085f 100644 (file)
@@ -132,14 +132,13 @@ void mpi_type_create_hvector_(int* count, int* blocklen, MPI_Aint* stride, int*
 
 void mpi_type_hindexed_ (int* count, int* blocklens, int* indices, int* old_type, int*  newtype, int* ierr) {
   MPI_Datatype tmp;
-  auto* indices_aint = new MPI_Aint[*count];
+  std::vector<MPI_Aint> indices_aint(*count);
   for(int i=0; i<*count; i++)
     indices_aint[i]=indices[i];
-  *ierr = MPI_Type_hindexed(*count, blocklens, indices_aint, simgrid::smpi::Datatype::f2c(*old_type), &tmp);
+  *ierr = MPI_Type_hindexed(*count, blocklens, indices_aint.data(), simgrid::smpi::Datatype::f2c(*old_type), &tmp);
   if(*ierr == MPI_SUCCESS) {
     *newtype = tmp->add_f();
   }
-  delete[] indices_aint;
 }
 
 void mpi_type_create_hindexed_(int* count, int* blocklens, MPI_Aint* indices, int* old_type, int*  newtype, int* ierr){
index fa76b74..95976f5 100644 (file)
@@ -637,14 +637,13 @@ int PMPI_Ireduce_scatter_block(const void* sendbuf, void* recvbuf, int recvcount
       new simgrid::instr::VarCollTIData(request == MPI_REQUEST_IGNORED ? "reducescatter" : "ireducescatter", -1, 0,
                                         nullptr, -1, trace_recvcounts, simgrid::smpi::Datatype::encode(datatype), ""));
 
-  auto* recvcounts = new int[count];
+  std::vector<int> recvcounts(count);
   for (int i      = 0; i < count; i++)
     recvcounts[i] = recvcount;
   if (request == MPI_REQUEST_IGNORED)
-    simgrid::smpi::colls::reduce_scatter(real_sendbuf, recvbuf, recvcounts, datatype, op, comm);
+    simgrid::smpi::colls::reduce_scatter(real_sendbuf, recvbuf, recvcounts.data(), datatype, op, comm);
   else
-    simgrid::smpi::colls::ireduce_scatter(real_sendbuf, recvbuf, recvcounts, datatype, op, comm, request);
-  delete[] recvcounts;
+    simgrid::smpi::colls::ireduce_scatter(real_sendbuf, recvbuf, recvcounts.data(), datatype, op, comm, request);
 
   TRACE_smpi_comm_out(rank);
   smpi_bench_begin();
index ad5e008..17969e5 100644 (file)
@@ -82,10 +82,10 @@ int File::op_all(void* buf, int count, const Datatype* datatype, MPI_Status* sta
   MPI_Offset max_offset =
       min_offset +
       count * datatype->get_extent(); // cheating, as we don't care about exact data location, we can skip extent
-  auto* min_offsets = new MPI_Offset[size];
-  auto* max_offsets = new MPI_Offset[size];
-  simgrid::smpi::colls::allgather(&min_offset, 1, MPI_OFFSET, min_offsets, 1, MPI_OFFSET, comm_);
-  simgrid::smpi::colls::allgather(&max_offset, 1, MPI_OFFSET, max_offsets, 1, MPI_OFFSET, comm_);
+  std::vector<MPI_Offset> min_offsets(size);
+  std::vector<MPI_Offset> max_offsets(size);
+  simgrid::smpi::colls::allgather(&min_offset, 1, MPI_OFFSET, min_offsets.data(), 1, MPI_OFFSET, comm_);
+  simgrid::smpi::colls::allgather(&max_offset, 1, MPI_OFFSET, max_offsets.data(), 1, MPI_OFFSET, comm_);
   MPI_Offset min = min_offset;
   MPI_Offset max = max_offset;
   MPI_Offset tot = 0;
@@ -103,15 +103,11 @@ int File::op_all(void* buf, int count, const Datatype* datatype, MPI_Status* sta
   XBT_CDEBUG(smpi_pmpi, "my offsets to read : %lld:%lld, global min and max %lld:%lld", min_offset, max_offset, min,
              max);
   if (empty == 1) {
-    delete[] min_offsets;
-    delete[] max_offsets;
     status->count = 0;
     return MPI_SUCCESS;
   }
   MPI_Offset total = max - min;
   if (total == tot && (datatype->flags() & DT_FLAG_CONTIGUOUS)) {
-    delete[] min_offsets;
-    delete[] max_offsets;
     // contiguous. Just have each proc perform its read
     if (status != MPI_STATUS_IGNORE)
       status->count = count * datatype->size();
@@ -122,10 +118,10 @@ int File::op_all(void* buf, int count, const Datatype* datatype, MPI_Status* sta
   MPI_Offset my_chunk_start = (max - min + 1) / size * rank;
   MPI_Offset my_chunk_end   = ((max - min + 1) / size * (rank + 1));
   XBT_CDEBUG(smpi_pmpi, "my chunks to read : %lld:%lld", my_chunk_start, my_chunk_end);
-  auto* send_sizes = new int[size];
-  auto* recv_sizes = new int[size];
-  auto* send_disps = new int[size];
-  auto* recv_disps = new int[size];
+  std::vector<int> send_sizes(size);
+  std::vector<int> recv_sizes(size);
+  std::vector<int> send_disps(size);
+  std::vector<int> recv_disps(size);
   int total_sent  = 0;
   for (int i = 0; i < size; i++) {
     send_sizes[i] = 0;
@@ -183,24 +179,18 @@ int File::op_all(void* buf, int count, const Datatype* datatype, MPI_Status* sta
     seek(min_offset, MPI_SEEK_SET);
     T(this, sendbuf, totreads / datatype->size(), datatype, status);
   }
-  simgrid::smpi::colls::alltoall(send_sizes, 1, MPI_INT, recv_sizes, 1, MPI_INT, comm_);
+  simgrid::smpi::colls::alltoall(send_sizes.data(), 1, MPI_INT, recv_sizes.data(), 1, MPI_INT, comm_);
   int total_recv = 0;
   for (int i = 0; i < size; i++) {
     recv_disps[i] = total_recv;
     total_recv += recv_sizes[i];
   }
   // Set buf value to avoid copying dumb data
-  simgrid::smpi::colls::alltoallv(sendbuf, send_sizes, send_disps, MPI_BYTE, buf, recv_sizes, recv_disps, MPI_BYTE,
-                                  comm_);
+  simgrid::smpi::colls::alltoallv(sendbuf, send_sizes.data(), send_disps.data(), MPI_BYTE, buf, recv_sizes.data(),
+                                  recv_disps.data(), MPI_BYTE, comm_);
   if (status != MPI_STATUS_IGNORE)
     status->count = count * datatype->size();
   smpi_free_tmp_buffer(sendbuf);
-  delete[] send_sizes;
-  delete[] recv_sizes;
-  delete[] send_disps;
-  delete[] recv_disps;
-  delete[] min_offsets;
-  delete[] max_offsets;
   return MPI_SUCCESS;
 }
 }
index 26d4cec..a80f69d 100644 (file)
@@ -17,6 +17,7 @@
 #include "xbt/file.hpp"
 
 #include <algorithm>
+#include <array>
 #include <boost/algorithm/string.hpp> /* split */
 #include <boost/tokenizer.hpp>
 #include <cinttypes>
@@ -377,13 +378,13 @@ static void smpi_copy_file(const std::string& src, const std::string& target, of
   }
 #endif
   // If this point is reached, sendfile() actually is not available.  Copy file by hand.
-  const int bufsize = 1024 * 1024 * 4;
-  auto* buf         = new char[bufsize];
-  while (int got = read(fdin, buf, bufsize)) {
+  constexpr int BUFSIZE = 1024 * 1024 * 4;
+  std::array<char, BUFSIZE> buf;
+  while (int got = read(fdin, buf.data(), BUFSIZE)) {
     if (got == -1) {
       xbt_assert(errno == EINTR, "Cannot read from %s", src.c_str());
     } else {
-      const char* p = buf;
+      const char* p = buf.data();
       int todo = got;
       while (int done = write(fdout, p, todo)) {
         if (done == -1) {
@@ -395,7 +396,6 @@ static void smpi_copy_file(const std::string& src, const std::string& target, of
       }
     }
   }
-  delete[] buf;
   close(fdin);
   close(fdout);
 }
index 749fed9..6ab3911 100644 (file)
@@ -821,15 +821,14 @@ void smpi_replay_main(int rank, const char* trace_filename)
   unsigned int count_requests = storage[simgrid::s4u::this_actor::get_pid()].size();
   XBT_DEBUG("There are %ud elements in reqq[*]", count_requests);
   if (count_requests > 0) {
-    auto* requests = new MPI_Request[count_requests];
+    std::vector<MPI_Request> requests(count_requests);
     unsigned int i=0;
 
     for (auto const& pair : storage[simgrid::s4u::this_actor::get_pid()].get_store()) {
       requests[i] = pair.second;
       i++;
     }
-    simgrid::smpi::Request::waitall(count_requests, requests, MPI_STATUSES_IGNORE);
-    delete[] requests;
+    simgrid::smpi::Request::waitall(count_requests, requests.data(), MPI_STATUSES_IGNORE);
   }
   active_processes--;
 
index 924c02d..0b4a906 100644 (file)
@@ -136,12 +136,11 @@ Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int
     , block_indices_(new MPI_Aint[count])
     , old_type_(old_type)
 {
-  auto* ints = new int[count + 1];
+  std::vector<int> ints(count + 1);
   ints[0]=count;
   for(int i=1;i<=count;i++)
     ints[i]=block_lengths[i-1];
-  contents_ = new Datatype_contents(MPI_COMBINER_HINDEXED, count+1, ints, count, block_indices, 1, &old_type);
-  delete[] ints;
+  contents_ = new Datatype_contents(MPI_COMBINER_HINDEXED, count + 1, ints.data(), count, block_indices, 1, &old_type);
   old_type_->ref();
   for (int i = 0; i < count; i++) {
     block_lengths_[i] = block_lengths[i];
@@ -230,14 +229,13 @@ Type_Indexed::Type_Indexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int co
     : Type_Hindexed(size, lb, ub, flags, count, block_lengths, block_indices, old_type, old_type->get_extent())
 {
   delete contents_;
-  auto* ints = new int[2 * count + 1];
+  std::vector<int> ints(2 * count + 1);
   ints[0]=count;
   for(int i=1;i<=count;i++)
     ints[i]=block_lengths[i-1];
   for(int i=count+1;i<=2*count;i++)
     ints[i]=block_indices[i-count-1];
-  contents_ = new Datatype_contents(MPI_COMBINER_INDEXED, 2*count+1, ints, 0, nullptr, 1, &old_type);
-  delete[] ints;
+  contents_ = new Datatype_contents(MPI_COMBINER_INDEXED, 2 * count + 1, ints.data(), 0, nullptr, 1, &old_type);
 }
 
 int Type_Indexed::clone(MPI_Datatype* type)
@@ -255,12 +253,12 @@ Type_Struct::Type_Struct(int size, MPI_Aint lb, MPI_Aint ub, int flags, int coun
     , block_indices_(new MPI_Aint[count])
     , old_types_(new MPI_Datatype[count])
 {
-  auto* ints = new int[count + 1];
+  std::vector<int> ints(count + 1);
   ints[0]=count;
   for(int i=1;i<=count;i++)
     ints[i]=block_lengths[i-1];
-  contents_ = new Datatype_contents(MPI_COMBINER_INDEXED, count+1, ints, count, block_indices, count, old_types);
-  delete[] ints;
+  contents_ =
+      new Datatype_contents(MPI_COMBINER_INDEXED, count + 1, ints.data(), count, block_indices, count, old_types);
   for (int i = 0; i < count; i++) {
     block_lengths_[i]=block_lengths[i];
     block_indices_[i]=block_indices[i];
index 8d2d653..75a499a 100644 (file)
@@ -207,20 +207,17 @@ int Group::excl(int n, const int *ranks, MPI_Group * newgroup){
   int oldsize = size_;
   int newsize = oldsize - n;
   *newgroup = new  Group(newsize);
-  auto* to_exclude = new int[size_];
-  for (int i     = 0; i < oldsize; i++)
-    to_exclude[i]=0;
-  for (int i            = 0; i < n; i++)
-    to_exclude[ranks[i]]=1;
+  std::vector<bool> to_exclude(size_, false);
+  for (int i = 0; i < n; i++)
+    to_exclude[ranks[i]] = true;
   int j = 0;
   for (int i = 0; i < oldsize; i++) {
-    if(to_exclude[i]==0){
+    if (not to_exclude[i]) {
       s4u::Actor* actor = this->actor(i);
       (*newgroup)->set_mapping(actor, j);
       j++;
     }
   }
-  delete[] to_exclude;
   return MPI_SUCCESS;
 }
 
index 5cbfa67..a512932 100644 (file)
@@ -92,8 +92,8 @@ Topo_Cart::Topo_Cart(MPI_Comm comm_old, int ndims, const int dims[], const int p
 
 Topo_Cart* Topo_Cart::sub(const int remain_dims[], MPI_Comm *newcomm) {
   int oldNDims = ndims_;
-  int *newDims = nullptr;
-  int *newPeriodic = nullptr;
+  std::vector<int> newDims;
+  std::vector<int> newPeriodic;
 
   if (remain_dims == nullptr && oldNDims != 0) {
     return nullptr;
@@ -105,8 +105,8 @@ Topo_Cart* Topo_Cart::sub(const int remain_dims[], MPI_Comm *newcomm) {
   }
 
   if (newNDims > 0) {
-    newDims     = new int[newNDims];
-    newPeriodic = new int[newNDims];
+    newDims.resize(newNDims);
+    newPeriodic.resize(newNDims);
 
     // that should not segfault
     int j = 0;
@@ -128,16 +128,14 @@ Topo_Cart* Topo_Cart::sub(const int remain_dims[], MPI_Comm *newcomm) {
   }
   Topo_Cart* res;
   if (newNDims == 0){
-    res = new Topo_Cart(getComm(), newNDims, newDims, newPeriodic, 0, newcomm);
+    res = new Topo_Cart(getComm(), newNDims, newDims.data(), newPeriodic.data(), 0, newcomm);
   } else {
     *newcomm = getComm()->split(color, getComm()->rank());
-    auto topo = std::make_shared<Topo_Cart>(getComm(), newNDims, newDims, newPeriodic, 0, nullptr);
+    auto topo = std::make_shared<Topo_Cart>(getComm(), newNDims, newDims.data(), newPeriodic.data(), 0, nullptr);
     res       = topo.get();
     res->setComm(*newcomm);
     (*newcomm)->set_topo(topo);
   }
-  delete[] newDims;
-  delete[] newPeriodic;
   return res;
 }
 
@@ -207,34 +205,33 @@ int Topo_Cart::shift(int direction, int disp, int* rank_source, int* rank_dest)
     return MPI_ERR_DIMS;
   }
 
-  auto* position = new int[ndims_];
-  this->coords(getComm()->rank(), ndims_, position);
+  std::vector<int> position(ndims_);
+  this->coords(getComm()->rank(), ndims_, position.data());
   position[direction] += disp;
 
   if(position[direction] < 0 ||
       position[direction] >=dims_[direction]) {
     if(periodic_[direction]) {
       position[direction] %=dims_[direction];
-      this->rank(position, rank_dest);
+      this->rank(position.data(), rank_dest);
     } else {
       *rank_dest = MPI_PROC_NULL;
     }
   } else {
-    this->rank(position, rank_dest);
+    this->rank(position.data(), rank_dest);
   }
 
   position[direction] = position_[direction] - disp;
   if(position[direction] < 0 || position[direction] >=dims_[direction]) {
     if(periodic_[direction]) {
       position[direction] %=dims_[direction];
-      this->rank(position, rank_source);
+      this->rank(position.data(), rank_source);
     } else {
       *rank_source = MPI_PROC_NULL;
     }
   } else {
-    this->rank(position, rank_source);
+    this->rank(position.data(), rank_source);
   }
-  delete[] position;
   return MPI_SUCCESS;
 }
 
index e157191..585f564 100644 (file)
@@ -50,15 +50,15 @@ public:
 
 int main(int argc, char** argv)
 {
-  const simgrid::s4u::Engine* engine = new simgrid::s4u::Engine(&argc, argv);
+  simgrid::s4u::Engine engine(&argc, argv);
 
-  engine->load_platform(argv[1]);
+  engine.load_platform(argv[1]);
   simgrid::s4u::Host* host = simgrid::s4u::Host::by_name("Tremblay");
 
   simgrid::s4u::Actor::create("Suspender", host, Suspender());
   receiver = simgrid::s4u::Actor::create("Receiver", host, Receiver());
 
-  engine->run();
+  engine.run();
 
   return 0;
 }