Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace fixed-size C-style arrays with std::array.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 20 Nov 2020 20:52:39 +0000 (21:52 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 21 Nov 2020 17:00:48 +0000 (18:00 +0100)
src/mc/inspect/DwarfExpression.hpp
src/mc/sosp/PageStore_test.cpp
src/smpi/internals/smpi_shared.cpp
src/smpi/mpi/smpi_comm.cpp
src/smpi/mpi/smpi_datatype.cpp
src/smpi/mpi/smpi_datatype_derived.cpp
src/smpi/mpi/smpi_request.cpp

index 3a94b47..ab229de 100644 (file)
@@ -9,6 +9,7 @@
 #include <cstdint>
 #include <cstdlib>
 
+#include <array>
 #include <stdexcept> // runtime_error
 #include <utility>
 #include <vector>
@@ -62,12 +63,12 @@ public:
  */
 class ExpressionStack {
 public:
-  using value_type                  = std::uintptr_t;
-  static const std::size_t max_size = 64;
+  using value_type                      = std::uintptr_t;
+  static constexpr std::size_t MAX_SIZE = 64;
 
 private:
   // Values of the stack (the top is stack_[size_ - 1]):
-  uintptr_t stack_[max_size]{0};
+  std::array<uintptr_t, MAX_SIZE> stack_{{0}};
   size_t size_ = 0;
 
 public:
@@ -97,7 +98,7 @@ public:
   /** Push a value on the top of the stack */
   void push(value_type value)
   {
-    if (size_ == max_size)
+    if (size_ == stack_.size())
       throw evaluation_error("DWARF stack overflow");
     stack_[size_++] = value;
   }
index 99ff03a..526bfc7 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "src/include/catch.hpp"
 
+#include <array>
 #include <cstdint>
 #include <cstring>
 #include <iostream>
@@ -25,7 +26,7 @@ public:
   static std::size_t pagesize;
   static std::unique_ptr<PageStore> store;
   static void* data;
-  static size_t pageno[4];
+  static std::array<size_t, 4> pageno;
   static int value;
 
   // member functions used by the test suite(s)
@@ -43,7 +44,7 @@ public:
 std::size_t helper_tests::pagesize             = 0;
 std::unique_ptr<PageStore> helper_tests::store = nullptr;
 void* helper_tests::data                       = nullptr;
-size_t helper_tests::pageno[4]                 = {0, 0, 0, 0};
+std::array<size_t, 4> helper_tests::pageno     = {{0, 0, 0, 0}};
 int helper_tests::value                        = 0;
 
 void helper_tests::Init()
index 50be4ae..87838e7 100644 (file)
@@ -33,8 +33,9 @@
  *                                                                    \ |  |
  *                                                                      ----
  */
-#include <map>
+#include <array>
 #include <cstring>
+#include <map>
 
 #include "private.hpp"
 #include "xbt/config.hpp"
@@ -326,8 +327,8 @@ void* smpi_shared_malloc(size_t size, const char* file, int line)
     return smpi_shared_malloc_local(size, file, line);
   } else if (smpi_cfg_shared_malloc() == SharedMallocType::GLOBAL) {
     int nb_shared_blocks = 1;
-    size_t shared_block_offsets[2] = {0, size};
-    return smpi_shared_malloc_partial(size, shared_block_offsets, nb_shared_blocks);
+    const std::array<size_t, 2> shared_block_offsets = {{0, size}};
+    return smpi_shared_malloc_partial(size, shared_block_offsets.data(), nb_shared_blocks);
   }
   XBT_DEBUG("Classic allocation of %zu bytes", size);
   return ::operator new(size);
index 73d4f84..307fcdd 100644 (file)
@@ -241,16 +241,13 @@ MPI_Comm Comm::split(int color, int key)
   int myrank           = this->rank();
   int size             = this->size();
   /* Gather all colors and keys on rank 0 */
-  int* sendbuf = xbt_new(int, 2);
-  sendbuf[0] = color;
-  sendbuf[1] = key;
+  const std::array<int, 2> sendbuf = {{color, key}};
   if (myrank == 0) {
     recvbuf = xbt_new(int, 2 * size);
   } else {
     recvbuf = nullptr;
   }
-  gather__default(sendbuf, 2, MPI_INT, recvbuf, 2, MPI_INT, 0, this);
-  xbt_free(sendbuf);
+  gather__default(sendbuf.data(), 2, MPI_INT, recvbuf, 2, MPI_INT, 0, this);
   /* Do the actual job */
   if (myrank == 0) {
     MPI_Group* group_snd = xbt_new(MPI_Group, size);
index a7ea791..3f770e9 100644 (file)
@@ -12,6 +12,7 @@
 #include "src/smpi/include/smpi_actor.hpp"
 
 #include <algorithm>
+#include <array>
 #include <functional>
 #include <string>
 
@@ -423,8 +424,8 @@ int Datatype::create_vector(int count, int block_length, int stride, MPI_Datatyp
     /* in this situation the data are contiguous thus it's not required to serialize and unserialize it*/
     *new_type = new Datatype(count * block_length * old_type->size(), 0, ((count -1) * stride + block_length)*
                          old_type->size(), DT_FLAG_CONTIGUOUS);
-    int ints[3] = {count, block_length, stride};
-    (*new_type)->contents_ = new Datatype_contents(MPI_COMBINER_VECTOR, 3, ints, 0, nullptr, 1, &old_type);
+    const std::array<int, 3> ints = {{count, block_length, stride}};
+    (*new_type)->contents_ = new Datatype_contents(MPI_COMBINER_VECTOR, 3, ints.data(), 0, nullptr, 1, &old_type);
     retval=MPI_SUCCESS;
   }
   return retval;
@@ -449,8 +450,8 @@ int Datatype::create_hvector(int count, int block_length, MPI_Aint stride, MPI_D
   }else{
     /* in this situation the data are contiguous thus it's not required to serialize and unserialize it*/
     *new_type = new Datatype(count * block_length * old_type->size(), 0, count * block_length * old_type->size(), DT_FLAG_CONTIGUOUS);
-    int ints[2] = {count, block_length};
-    (*new_type)->contents_ = new Datatype_contents(MPI_COMBINER_HVECTOR, 2, ints, 1, &stride, 1, &old_type);
+    const std::array<int, 2> ints = {{count, block_length}};
+    (*new_type)->contents_ = new Datatype_contents(MPI_COMBINER_HVECTOR, 2, ints.data(), 1, &stride, 1, &old_type);
     retval=MPI_SUCCESS;
   }
   return retval;
@@ -618,10 +619,10 @@ int Datatype::create_subarray(int ndims, const int* array_of_sizes,
       tmp = *newtype;
   }
 
-  MPI_Aint lbs[1] = {lb * extent};
-  int sizes [1]={1};
+  const MPI_Aint lbs = lb * extent;
+  const int sizes    = 1;
   //handle LB and UB with a resized call
-  create_hindexed( 1, sizes, lbs, tmp, newtype);
+  create_hindexed(1, &sizes, &lbs, tmp, newtype);
   unref(tmp);
 
   tmp = *newtype;
@@ -632,11 +633,12 @@ int Datatype::create_subarray(int ndims, const int* array_of_sizes,
 }
 
 int Datatype::create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype){
-  int blocks[3]         = {1, 1, 1};
-  MPI_Aint disps[3]     = {lb, 0, lb + extent};
-  MPI_Datatype types[3] = {MPI_LB, oldtype, MPI_UB};
+  const std::array<int, 3> blocks         = {{1, 1, 1}};
+  const std::array<MPI_Aint, 3> disps     = {{lb, 0, lb + extent}};
+  const std::array<MPI_Datatype, 3> types = {{MPI_LB, oldtype, MPI_UB}};
 
-  *newtype = new simgrid::smpi::Type_Struct(oldtype->size(), lb, lb + extent, DT_FLAG_DERIVED, 3, blocks, disps, types);
+  *newtype = new simgrid::smpi::Type_Struct(oldtype->size(), lb, lb + extent, DT_FLAG_DERIVED, 3, blocks.data(),
+                                            disps.data(), types.data());
 
   (*newtype)->addflag(~DT_FLAG_COMMITED);
   return MPI_SUCCESS;
index 75abfb4..924c02d 100644 (file)
@@ -8,6 +8,7 @@
 #include "smpi_op.hpp"
 #include <xbt/log.h>
 
+#include <array>
 #include <cstring>
 
 namespace simgrid{
@@ -58,8 +59,8 @@ void Type_Contiguous::unserialize(const void* contiguous_buf, void* noncontiguou
 }
 
 Type_Hvector::Type_Hvector(int size,MPI_Aint lb, MPI_Aint ub, int flags, int count, int block_length, MPI_Aint stride, MPI_Datatype old_type): Datatype(size, lb, ub, flags), block_count_(count), block_length_(block_length), block_stride_(stride), old_type_(old_type){
-  int ints[2] = {count, block_length};
-  contents_ = new Datatype_contents(MPI_COMBINER_HVECTOR, 2, ints, 1, &stride, 1, &old_type);
+  const std::array<int, 2> ints = {{count, block_length}};
+  contents_                     = new Datatype_contents(MPI_COMBINER_HVECTOR, 2, ints.data(), 1, &stride, 1, &old_type);
   old_type->ref();
 }
 Type_Hvector::~Type_Hvector(){
@@ -116,8 +117,8 @@ Type_Vector::Type_Vector(int size, MPI_Aint lb, MPI_Aint ub, int flags, int coun
     : Type_Hvector(size, lb, ub, flags, count, block_length, stride * old_type->get_extent(), old_type)
 {
   delete contents_;
-  int ints[3] = {count, block_length, stride};
-  contents_ = new Datatype_contents(MPI_COMBINER_VECTOR, 3, ints, 0, nullptr, 1, &old_type);
+  const std::array<int, 3> ints = {{count, block_length, stride}};
+  contents_                     = new Datatype_contents(MPI_COMBINER_VECTOR, 3, ints.data(), 0, nullptr, 1, &old_type);
 }
 
 int Type_Vector::clone(MPI_Datatype* type)
index 5dd26dc..e0c6ec5 100644 (file)
@@ -18,6 +18,7 @@
 #include "src/smpi/include/smpi_actor.hpp"
 
 #include <algorithm>
+#include <array>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_request, smpi, "Logging specific to SMPI (request)");
 
@@ -337,8 +338,8 @@ void Request::sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype
                        void *recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag,
                        MPI_Comm comm, MPI_Status * status)
 {
-  MPI_Request requests[2];
-  MPI_Status stats[2];
+  std::array<MPI_Request, 2> requests;
+  std::array<MPI_Status, 2> stats;
   int myid = simgrid::s4u::this_actor::get_pid();
   if ((comm->group()->actor(dst)->get_pid() == myid) && (comm->group()->actor(src)->get_pid() == myid)) {
     Datatype::copy(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype);
@@ -352,8 +353,8 @@ void Request::sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype
   }
   requests[0] = isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm);
   requests[1] = irecv_init(recvbuf, recvcount, recvtype, src, recvtag, comm);
-  startall(2, requests);
-  waitall(2, requests, stats);
+  startall(2, requests.data());
+  waitall(2, requests.data(), stats.data());
   unref(&requests[0]);
   unref(&requests[1]);
   if(status != MPI_STATUS_IGNORE) {