Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace #define with constexpr declarations.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 26 Feb 2019 16:23:29 +0000 (17:23 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 27 Feb 2019 14:26:19 +0000 (15:26 +0100)
27 files changed:
examples/s4u/app-bittorrent/s4u-bittorrent.hpp
examples/s4u/app-bittorrent/s4u-peer.cpp
examples/s4u/app-chainsend/s4u-app-chainsend.cpp
examples/s4u/dht-chord/s4u-dht-chord.hpp
examples/s4u/dht-kademlia/node.cpp
examples/s4u/dht-kademlia/routing_table.cpp
examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp
examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp
examples/s4u/synchro-mutex/s4u-synchro-mutex.cpp
src/bindings/lua/lua_host.cpp
src/bindings/lua/lua_platf.cpp
src/include/xbt/mmalloc.h
src/instr/instr_config.cpp
src/kernel/activity/MailboxImpl.hpp
src/mc/mc_exit.hpp
src/smpi/include/private.hpp
src/smpi/include/smpi_datatype.hpp
src/smpi/internals/smpi_global.cpp
src/smpi/internals/smpi_shared.cpp
src/surf/cpu_ti.cpp
src/xbt/dict.cpp
src/xbt/dict_private.h
src/xbt/dynar_test.cpp
teshsuite/msg/cloud-capping/cloud-capping.c
teshsuite/surf/maxmin_bench/maxmin_bench.cpp
teshsuite/xbt/mmalloc/mmalloc_test.cpp
teshsuite/xbt/parmap_bench/parmap_bench.cpp

index d61f301..4b1728b 100644 (file)
 #include <simgrid/s4u.hpp>
 #include <xbt/RngStream.h>
 
-#define TRACKER_MAILBOX "tracker_mailbox"
+constexpr char TRACKER_MAILBOX[] = "tracker_mailbox";
 /** Max number of peers sent by the tracker to clients */
-#define MAXIMUM_PEERS 50
+constexpr int MAXIMUM_PEERS = 50;
 /** Interval of time where the peer should send a request to the tracker */
-#define TRACKER_QUERY_INTERVAL 1000
+constexpr int TRACKER_QUERY_INTERVAL = 1000;
 /** Communication size for a task to the tracker */
-#define TRACKER_COMM_SIZE 1
-#define GET_PEERS_TIMEOUT 10000
+constexpr unsigned TRACKER_COMM_SIZE = 1;
+constexpr double GET_PEERS_TIMEOUT   = 10000.0;
 /** Number of peers that can be unchocked at a given time */
-#define MAX_UNCHOKED_PEERS 4
+constexpr int MAX_UNCHOKED_PEERS = 4;
 /** Interval between each update of the choked peers */
-#define UPDATE_CHOKED_INTERVAL 30
+constexpr int UPDATE_CHOKED_INTERVAL = 30;
 
 /** Message sizes
  * Sizes based on report by A. Legout et al, Understanding BitTorrent: An Experimental Perspective
  * http://hal.inria.fr/inria-00000156/en
  */
-#define MESSAGE_HANDSHAKE_SIZE 68
-#define MESSAGE_CHOKE_SIZE 5
-#define MESSAGE_UNCHOKE_SIZE 5
-#define MESSAGE_INTERESTED_SIZE 5
-#define MESSAGE_NOTINTERESTED_SIZE 5
-#define MESSAGE_HAVE_SIZE 9
-#define MESSAGE_BITFIELD_SIZE 5
-#define MESSAGE_REQUEST_SIZE 17
-#define MESSAGE_PIECE_SIZE 13
-#define MESSAGE_CANCEL_SIZE 17
+constexpr unsigned MESSAGE_HANDSHAKE_SIZE     = 68;
+constexpr unsigned MESSAGE_CHOKE_SIZE         = 5;
+constexpr unsigned MESSAGE_UNCHOKE_SIZE       = 5;
+constexpr unsigned MESSAGE_INTERESTED_SIZE    = 5;
+constexpr unsigned MESSAGE_NOTINTERESTED_SIZE = 5;
+constexpr unsigned MESSAGE_HAVE_SIZE          = 9;
+constexpr unsigned MESSAGE_BITFIELD_SIZE      = 5;
+constexpr unsigned MESSAGE_REQUEST_SIZE       = 17;
+constexpr unsigned MESSAGE_PIECE_SIZE         = 13;
+constexpr unsigned MESSAGE_CANCEL_SIZE        = 17;
 
 /** Types of messages exchanged between two peers. */
 enum e_message_type {
index 5541383..d36aae4 100644 (file)
@@ -15,15 +15,15 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_bt_peer, "Messages specific for the peers");
  * User parameters for transferred file data. For the test, the default values are :
  * File size: 10 pieces * 5 blocks/piece * 16384 bytes/block = 819200 bytes
  */
-#define FILE_PIECES 10UL
-#define PIECES_BLOCKS 5UL
-#define BLOCK_SIZE 16384
+constexpr unsigned long FILE_PIECES   = 10UL;
+constexpr unsigned long PIECES_BLOCKS = 5UL;
+constexpr int BLOCK_SIZE              = 16384;
 
 /** Number of blocks asked by each request */
-#define BLOCKS_REQUESTED 2UL
+constexpr unsigned long BLOCKS_REQUESTED = 2UL;
 
-#define ENABLE_END_GAME_MODE 1
-#define SLEEP_DURATION 1
+constexpr bool ENABLE_END_GAME_MODE = true;
+constexpr double SLEEP_DURATION     = 1.0;
 #define BITS_TO_BYTES(x) (((x) / 8 + (x) % 8) ? 1 : 0)
 
 Peer::Peer(std::vector<std::string> args)
@@ -453,9 +453,8 @@ int Peer::selectPieceToDownload(Connection* remote_peer)
 
   // end game mode
   if (countPieces(current_pieces) >= (FILE_PIECES - countPieces(bitfield_)) && isInterestedBy(remote_peer)) {
-#if ENABLE_END_GAME_MODE == 0
-    return -1;
-#endif
+    if (not ENABLE_END_GAME_MODE)
+      return -1;
     int nb_interesting_pieces = 0;
     // compute the number of interesting pieces
     for (unsigned int i = 0; i < FILE_PIECES; i++)
index 28022f4..39ee01d 100644 (file)
@@ -6,9 +6,9 @@
 #include "simgrid/s4u.hpp"
 #include <vector>
 
-#define PIECE_SIZE 65536
-#define MESSAGE_BUILD_CHAIN_SIZE 40
-#define MESSAGE_SEND_DATA_HEADER_SIZE 1
+constexpr unsigned PIECE_SIZE                    = 65536;
+constexpr unsigned MESSAGE_BUILD_CHAIN_SIZE      = 40;
+constexpr unsigned MESSAGE_SEND_DATA_HEADER_SIZE = 1;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_chainsend, "Messages specific for chainsend");
 
index 1bedad7..0ca638a 100644 (file)
 #include <xbt/RngStream.h>
 #include <xbt/str.h>
 
-#define MAX_SIMULATION_TIME 1000
-#define PERIODIC_STABILIZE_DELAY 20
-#define PERIODIC_FIX_FINGERS_DELAY 120
-#define PERIODIC_CHECK_PREDECESSOR_DELAY 120
-#define PERIODIC_LOOKUP_DELAY 10
-#define SLEEP_DELAY 4.9999
+constexpr double MAX_SIMULATION_TIME              = 1000;
+constexpr double PERIODIC_STABILIZE_DELAY         = 20;
+constexpr double PERIODIC_FIX_FINGERS_DELAY       = 120;
+constexpr double PERIODIC_CHECK_PREDECESSOR_DELAY = 120;
+constexpr double PERIODIC_LOOKUP_DELAY            = 10;
+constexpr double SLEEP_DELAY                      = 4.9999;
 
 extern int nb_bits;
 extern int nb_keys;
index a760100..ead02fe 100644 (file)
@@ -58,13 +58,13 @@ bool Node::join(unsigned int known_id)
 
   /* Second step: Send a FIND_NODE to a a random node in buckets */
   unsigned int bucket_id = table->findBucket(known_id)->getId();
-  xbt_assert(bucket_id <= identifier_size);
-  for (i = 0; ((bucket_id > i) || (bucket_id + i) <= identifier_size) && i < JOIN_BUCKETS_QUERIES; i++) {
+  xbt_assert(bucket_id <= IDENTIFIER_SIZE);
+  for (i = 0; ((bucket_id > i) || (bucket_id + i) <= IDENTIFIER_SIZE) && i < JOIN_BUCKETS_QUERIES; i++) {
     if (bucket_id > i) {
       unsigned int id_in_bucket = get_id_in_prefix(id_, bucket_id - i);
       findNode(id_in_bucket, false);
     }
-    if (bucket_id + i <= identifier_size) {
+    if (bucket_id + i <= IDENTIFIER_SIZE) {
       unsigned int id_in_bucket = get_id_in_prefix(id_, bucket_id + i);
       findNode(id_in_bucket, false);
     }
@@ -90,7 +90,7 @@ void Node::sendFindNode(unsigned int id, unsigned int destination)
 }
 
 /**
-  * Sends to the best "kademlia_alpha" nodes in the "node_list" array a "FIND_NODE" request, to ask them for their best
+  * Sends to the best "KADEMLIA_ALPHA" nodes in the "node_list" array a "FIND_NODE" request, to ask them for their best
   * nodes
   */
 unsigned int Node::sendFindNodeToBest(Answer* node_list)
@@ -99,14 +99,14 @@ unsigned int Node::sendFindNodeToBest(Answer* node_list)
   unsigned int j           = 0;
   unsigned int destination = node_list->getDestinationId();
   for (auto node_to_query : node_list->nodes) {
-    /* We need to have at most "kademlia_alpha" requests each time, according to the protocol */
+    /* We need to have at most "KADEMLIA_ALPHA" requests each time, according to the protocol */
     /* Gets the node we want to send the query to */
     if (node_to_query.first != id_) { /* No need to query ourselves */
       sendFindNode(node_to_query.first, destination);
       j++;
     }
     i++;
-    if (j == kademlia_alpha)
+    if (j == KADEMLIA_ALPHA)
       break;
   }
   return i;
@@ -148,26 +148,26 @@ Answer* Node::findClosest(unsigned int destination_id)
   /* We find the corresponding bucket for the id */
   Bucket* bucket = table->findBucket(destination_id);
   int bucket_id  = bucket->getId();
-  xbt_assert((bucket_id <= identifier_size), "Bucket found has a wrong identifier");
+  xbt_assert((bucket_id <= IDENTIFIER_SIZE), "Bucket found has a wrong identifier");
   /* So, we copy the contents of the bucket unsigned into our answer */
   answer->addBucket(bucket);
 
-  /* However, if we don't have enough elements in our bucket, we NEED to include at least "bucket_size" elements
-   * (if, of course, we know at least "bucket_size" elements. So we're going to look unsigned into the other buckets.
+  /* However, if we don't have enough elements in our bucket, we NEED to include at least "BUCKET_SIZE" elements
+   * (if, of course, we know at least "BUCKET_SIZE" elements. So we're going to look unsigned into the other buckets.
    */
-  for (int i = 1; answer->getSize() < BUCKET_SIZE && ((bucket_id - i > 0) || (bucket_id + i < identifier_size)); i++) {
+  for (int i = 1; answer->getSize() < BUCKET_SIZE && ((bucket_id - i > 0) || (bucket_id + i < IDENTIFIER_SIZE)); i++) {
     /* We check the previous buckets */
     if (bucket_id - i >= 0) {
       Bucket* bucket_p = table->buckets[bucket_id - i];
       answer->addBucket(bucket_p);
     }
     /* We check the next buckets */
-    if (bucket_id + i <= identifier_size) {
+    if (bucket_id + i <= IDENTIFIER_SIZE) {
       Bucket* bucket_n = table->buckets[bucket_id + i];
       answer->addBucket(bucket_n);
     }
   }
-  /* We trim the array to have only bucket_size or less elements */
+  /* We trim the array to have only BUCKET_SIZE or less elements */
   std::sort(answer->nodes.begin(), answer->nodes.end(), sortbydistance);
   answer->trim();
 
@@ -183,7 +183,7 @@ bool Node::findNode(unsigned int id_to_find, bool count_in_stats)
   unsigned int answers;
   bool destination_found   = false;
   unsigned int nodes_added = 0;
-  double global_timeout    = simgrid::s4u::Engine::get_clock() + find_node_global_timeout;
+  double global_timeout    = simgrid::s4u::Engine::get_clock() + FIND_NODE_GLOBAL_TIMEOUT;
   unsigned int steps       = 0;
 
   /* First we build a list of who we already know */
@@ -196,7 +196,7 @@ bool Node::findNode(unsigned int id_to_find, bool count_in_stats)
     answers        = 0;
     queries        = sendFindNodeToBest(node_list);
     nodes_added    = 0;
-    double timeout = simgrid::s4u::Engine::get_clock() + find_node_timeout;
+    double timeout = simgrid::s4u::Engine::get_clock() + FIND_NODE_TIMEOUT;
     steps++;
     double time_beginreceive = simgrid::s4u::Engine::get_clock();
 
index a6c9a63..341153b 100644 (file)
@@ -14,15 +14,15 @@ namespace kademlia {
 /** @brief Initialization of a node routing table.  */
 RoutingTable::RoutingTable(unsigned int node_id) : id_(node_id)
 {
-  buckets = new Bucket*[identifier_size + 1];
-  for (unsigned int i = 0; i < identifier_size + 1; i++)
+  buckets = new Bucket*[IDENTIFIER_SIZE + 1];
+  for (unsigned int i = 0; i < IDENTIFIER_SIZE + 1; i++)
     buckets[i]        = new Bucket(i);
 }
 
 RoutingTable::~RoutingTable()
 {
   // Free the buckets.
-  for (unsigned int i = 0; i <= identifier_size; i++) {
+  for (unsigned int i = 0; i <= IDENTIFIER_SIZE; i++) {
     delete buckets[i];
   }
   delete[] buckets;
@@ -32,7 +32,7 @@ void RoutingTable::print()
 {
   XBT_INFO("Routing table of %08x:", id_);
 
-  for (unsigned int i = 0; i <= identifier_size; i++) {
+  for (unsigned int i = 0; i <= IDENTIFIER_SIZE; i++) {
     if (not buckets[i]->nodes.empty()) {
       XBT_INFO("Bucket number %u: ", i);
       int j = 0;
@@ -51,8 +51,8 @@ void RoutingTable::print()
 Bucket* RoutingTable::findBucket(unsigned int id)
 {
   unsigned int xor_number = id_ ^ id;
-  unsigned int prefix     = get_node_prefix(xor_number, identifier_size);
-  xbt_assert(prefix <= identifier_size, "Tried to return a  bucket that doesn't exist.");
+  unsigned int prefix     = get_node_prefix(xor_number, IDENTIFIER_SIZE);
+  xbt_assert(prefix <= IDENTIFIER_SIZE, "Tried to return a  bucket that doesn't exist.");
   return buckets[prefix];
 }
 
index cd70443..29d8d2b 100644 (file)
@@ -40,7 +40,7 @@ static int node(int argc, char* argv[])
   if (join_success) {
     XBT_VERB("Ok, I'm joining the network with id %u", node->getId());
     // We start the main loop
-    double next_lookup_time = simgrid::s4u::Engine::get_clock() + random_lookup_interval;
+    double next_lookup_time = simgrid::s4u::Engine::get_clock() + RANDOM_LOOKUP_INTERVAL;
 
     XBT_VERB("Main loop start");
 
@@ -64,7 +64,7 @@ static int node(int argc, char* argv[])
         /* We search for a pseudo random node */
         if (simgrid::s4u::Engine::get_clock() >= next_lookup_time) {
           node->randomLookup();
-          next_lookup_time += random_lookup_interval;
+          next_lookup_time += RANDOM_LOOKUP_INTERVAL;
         } else {
           // Didn't get a message: sleep for a while...
           simgrid::s4u::this_actor::sleep_for(1);
index a66c4a9..05a5078 100644 (file)
@@ -14,20 +14,20 @@ class Answer;
 class Message;
 }
 
-#define find_node_timeout 10
-#define find_node_global_timeout 50
+constexpr double FIND_NODE_TIMEOUT        = 10.0;
+constexpr double FIND_NODE_GLOBAL_TIMEOUT = 50.0;
 
-#define kademlia_alpha 3
-#define BUCKET_SIZE 20
+constexpr unsigned KADEMLIA_ALPHA = 3;
+constexpr unsigned BUCKET_SIZE    = 20;
 
-#define identifier_size 32
+constexpr int IDENTIFIER_SIZE = 32;
 
-#define random_lookup_interval 100
+constexpr double RANDOM_LOOKUP_INTERVAL = 100.0;
 
-#define MAX_STEPS 10
+constexpr unsigned MAX_STEPS = 10;
 
-#define JOIN_BUCKETS_QUERIES 5
+constexpr unsigned JOIN_BUCKETS_QUERIES = 5;
 
-#define RANDOM_LOOKUP_NODE 0
+constexpr unsigned RANDOM_LOOKUP_NODE = 0;
 
 #endif
index 4f8b519..e7819f7 100644 (file)
@@ -6,7 +6,7 @@
 #include <mutex> /* std::mutex and std::lock_guard */
 #include "simgrid/s4u.hpp" /* All of S4U */
 
-#define NB_ACTOR 6
+constexpr int NB_ACTOR = 6;
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category");
 
index f2188fd..175be6e 100644 (file)
@@ -11,8 +11,9 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(lua_host, "Lua Host module");
 
-#define HOST_MODULE_NAME "simgrid.host"
-#define HOST_FIELDNAME   "__simgrid_host"
+constexpr char HOST_MODULE_NAME[] = "simgrid.host";
+constexpr char HOST_FIELDNAME[]   = "__simgrid_host";
+
 /* ********************************************************************************* */
 /*                                simgrid.host API                                   */
 /* ********************************************************************************* */
index ca19e54..905776d 100644 (file)
@@ -24,8 +24,8 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(lua_platf, "Lua bindings (platform module)");
 
-#define PLATF_MODULE_NAME "simgrid.engine"
-#define AS_FIELDNAME   "__simgrid_as"
+constexpr char PLATF_MODULE_NAME[] = "simgrid.engine";
+constexpr char AS_FIELDNAME[]      = "__simgrid_as";
 
 /* ********************************************************************************* */
 /*                               simgrid.platf API                                   */
index 60e57c4..792e9e9 100644 (file)
@@ -7,7 +7,7 @@
    This file was then part of the GNU C Library. */
 
 #ifndef SIMGRID_MMALLOC_H
-#define SIMGRID_MMALLOC_H 1
+#define SIMGRID_MMALLOC_H
 
 #include "src/internal_config.h"
 
index d90153a..c6cdff7 100644 (file)
@@ -18,13 +18,12 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY (instr_config, instr, "Configuration");
 
 std::ofstream tracing_file;
 
-#define OPT_TRACING_BASIC                "tracing/basic"
-#define OPT_TRACING_COMMENT_FILE         "tracing/comment-file"
-#define OPT_TRACING_DISABLE_DESTROY      "tracing/disable-destroy"
-#define OPT_TRACING_FORMAT_TI_ONEFILE    "tracing/smpi/format/ti-one-file"
-#define OPT_TRACING_SMPI_INTERNALS       "tracing/smpi/internals"
-#define OPT_TRACING_SMPI                 "tracing/smpi"
-#define OPT_TRACING_TOPOLOGY             "tracing/platform/topology"
+constexpr char OPT_TRACING_BASIC[]             = "tracing/basic";
+constexpr char OPT_TRACING_COMMENT_FILE[]      = "tracing/comment-file";
+constexpr char OPT_TRACING_DISABLE_DESTROY[]   = "tracing/disable-destroy";
+constexpr char OPT_TRACING_FORMAT_TI_ONEFILE[] = "tracing/smpi/format/ti-one-file";
+constexpr char OPT_TRACING_SMPI[]              = "tracing/smpi";
+constexpr char OPT_TRACING_TOPOLOGY[]          = "tracing/platform/topology";
 
 static simgrid::config::Flag<bool> trace_enabled{
     "tracing", "Enable the tracing system. You have to enable this option to use other tracing options.", false};
index b88d28d..2620d7e 100644 (file)
@@ -13,7 +13,6 @@
 #include "src/kernel/activity/CommImpl.hpp"
 #include "src/simix/ActorImpl.hpp"
 
-#define MAX_MAILBOX_SIZE 10000000
 namespace simgrid {
 namespace kernel {
 namespace activity {
@@ -21,6 +20,8 @@ namespace activity {
 /** @brief Implementation of the simgrid::s4u::Mailbox */
 
 class MailboxImpl {
+  static constexpr size_t MAX_MAILBOX_SIZE = 10000000;
+
   friend s4u::Mailbox;
   friend s4u::MailboxPtr s4u::Mailbox::by_name(const std::string& name);
   friend mc::CommunicationDeterminismChecker;
index 3ec6ccf..c725e83 100644 (file)
@@ -7,15 +7,15 @@
 #define SIMGRID_MC_EXIT_HPP
 #include "xbt/base.h"
 
-#define SIMGRID_MC_EXIT_SUCCESS 0
-#define SIMGRID_MC_EXIT_SAFETY 1
-#define SIMGRID_MC_EXIT_LIVENESS 2
-#define SIMGRID_MC_EXIT_DEADLOCK 3
-#define SIMGRID_MC_EXIT_NON_TERMINATION 4
-#define SIMGRID_MC_EXIT_NON_DETERMINISM 5
-#define SIMGRID_MC_EXIT_PROGRAM_CRASH 6
+constexpr int SIMGRID_MC_EXIT_SUCCESS         = 0;
+constexpr int SIMGRID_MC_EXIT_SAFETY          = 1;
+constexpr int SIMGRID_MC_EXIT_LIVENESS        = 2;
+constexpr int SIMGRID_MC_EXIT_DEADLOCK        = 3;
+constexpr int SIMGRID_MC_EXIT_NON_TERMINATION = 4;
+constexpr int SIMGRID_MC_EXIT_NON_DETERMINISM = 5;
+constexpr int SIMGRID_MC_EXIT_PROGRAM_CRASH   = 6;
 
-#define SIMGRID_MC_EXIT_ERROR 63
+constexpr int SIMGRID_MC_EXIT_ERROR           = 63;
 
 namespace simgrid {
 namespace mc {
index 1ea8e09..c588ce0 100644 (file)
 #include <unordered_map>
 #include <vector>
 
-#define MPI_REQ_PERSISTENT 0x1
-#define MPI_REQ_NON_PERSISTENT 0x2
-#define MPI_REQ_SEND 0x4
-#define MPI_REQ_RECV 0x8
-//#define MPI_REQ_RECV_DELETE 0x10
-#define MPI_REQ_ISEND 0x20
-#define MPI_REQ_SSEND 0x40
-#define MPI_REQ_PREPARED 0x80
-#define MPI_REQ_FINISHED 0x100
-#define MPI_REQ_RMA 0x200
-#define MPI_REQ_ACCUMULATE 0x400
+constexpr unsigned MPI_REQ_PERSISTENT     = 0x1;
+constexpr unsigned MPI_REQ_NON_PERSISTENT = 0x2;
+constexpr unsigned MPI_REQ_SEND           = 0x4;
+constexpr unsigned MPI_REQ_RECV           = 0x8;
+// constexpr unsigned MPI_REQ_RECV_DELETE    = 0x10;
+constexpr unsigned MPI_REQ_ISEND          = 0x20;
+constexpr unsigned MPI_REQ_SSEND          = 0x40;
+constexpr unsigned MPI_REQ_PREPARED       = 0x80;
+constexpr unsigned MPI_REQ_FINISHED       = 0x100;
+constexpr unsigned MPI_REQ_RMA            = 0x200;
+constexpr unsigned MPI_REQ_ACCUMULATE     = 0x400;
 
 enum class SmpiProcessState { UNINITIALIZED, INITIALIZING, INITIALIZED, FINALIZED };
 
-#define COLL_TAG_REDUCE -112
-#define COLL_TAG_SCATTER -223
-#define COLL_TAG_SCATTERV -334
-#define COLL_TAG_GATHER -445
-#define COLL_TAG_ALLGATHER -556
-#define COLL_TAG_ALLGATHERV -667
-#define COLL_TAG_BARRIER -778
-#define COLL_TAG_REDUCE_SCATTER -889
-#define COLL_TAG_ALLTOALLV -1000
-#define COLL_TAG_ALLTOALL -1112
-#define COLL_TAG_GATHERV -2223
-#define COLL_TAG_BCAST -3334
-#define COLL_TAG_ALLREDUCE -4445
+constexpr int COLL_TAG_REDUCE         = -112;
+constexpr int COLL_TAG_SCATTER        = -223;
+constexpr int COLL_TAG_SCATTERV       = -334;
+constexpr int COLL_TAG_GATHER         = -445;
+constexpr int COLL_TAG_ALLGATHER      = -556;
+constexpr int COLL_TAG_ALLGATHERV     = -667;
+constexpr int COLL_TAG_BARRIER        = -778;
+constexpr int COLL_TAG_REDUCE_SCATTER = -889;
+constexpr int COLL_TAG_ALLTOALLV      = -1000;
+constexpr int COLL_TAG_ALLTOALL       = -1112;
+constexpr int COLL_TAG_GATHERV        = -2223;
+constexpr int COLL_TAG_BCAST          = -3334;
+constexpr int COLL_TAG_ALLREDUCE      = -4445;
 // SMPI_RMA_TAG has to be the smallest one, as it will be decremented for accumulate ordering.
-#define SMPI_RMA_TAG -6666
+constexpr int SMPI_RMA_TAG            = -6666;
 
 /* Convert between Fortran and C */
 
index 61af1d5..b183c19 100644 (file)
 #include "smpi_keyvals.hpp"
 #include <string>
 
-#define DT_FLAG_DESTROYED     0x0001  /**< user destroyed but some other layers still have a reference */
-#define DT_FLAG_COMMITED      0x0002  /**< ready to be used for a send/recv operation */
-#define DT_FLAG_CONTIGUOUS    0x0004  /**< contiguous datatype */
-#define DT_FLAG_OVERLAP       0x0008  /**< datatype is unpropper for a recv operation */
-#define DT_FLAG_USER_LB       0x0010  /**< has a user defined LB */
-#define DT_FLAG_USER_UB       0x0020  /**< has a user defined UB */
-#define DT_FLAG_PREDEFINED    0x0040  /**< cannot be removed: initial and predefined datatypes */
-#define DT_FLAG_NO_GAPS       0x0080  /**< no gaps around the datatype */
-#define DT_FLAG_DATA          0x0100  /**< data or control structure */
-#define DT_FLAG_ONE_SIDED     0x0200  /**< datatype can be used for one sided operations */
-#define DT_FLAG_UNAVAILABLE   0x0400  /**< datatypes unavailable on the build (OS or compiler dependant) */
-#define DT_FLAG_DERIVED       0x0800  /**< is the datatype derived ? */
+constexpr unsigned DT_FLAG_DESTROYED   = 0x0001; /**< user destroyed but some other layers still have a reference */
+constexpr unsigned DT_FLAG_COMMITED    = 0x0002; /**< ready to be used for a send/recv operation */
+constexpr unsigned DT_FLAG_CONTIGUOUS  = 0x0004; /**< contiguous datatype */
+constexpr unsigned DT_FLAG_OVERLAP     = 0x0008; /**< datatype is unpropper for a recv operation */
+constexpr unsigned DT_FLAG_USER_LB     = 0x0010; /**< has a user defined LB */
+constexpr unsigned DT_FLAG_USER_UB     = 0x0020; /**< has a user defined UB */
+constexpr unsigned DT_FLAG_PREDEFINED  = 0x0040; /**< cannot be removed: initial and predefined datatypes */
+constexpr unsigned DT_FLAG_NO_GAPS     = 0x0080; /**< no gaps around the datatype */
+constexpr unsigned DT_FLAG_DATA        = 0x0100; /**< data or control structure */
+constexpr unsigned DT_FLAG_ONE_SIDED   = 0x0200; /**< datatype can be used for one sided operations */
+constexpr unsigned DT_FLAG_UNAVAILABLE = 0x0400; /**< datatypes unavailable on the build (OS or compiler dependant) */
+constexpr unsigned DT_FLAG_DERIVED     = 0x0800; /**< is the datatype derived ? */
 /*
  * We should make the difference here between the predefined contiguous and non contiguous
  * datatypes. The DT_FLAG_BASIC is held by all predefined contiguous datatypes.
  */
-#define DT_FLAG_BASIC      (DT_FLAG_PREDEFINED | DT_FLAG_CONTIGUOUS | DT_FLAG_NO_GAPS | DT_FLAG_DATA | DT_FLAG_COMMITED)
+constexpr unsigned DT_FLAG_BASIC =
+    (DT_FLAG_PREDEFINED | DT_FLAG_CONTIGUOUS | DT_FLAG_NO_GAPS | DT_FLAG_DATA | DT_FLAG_COMMITED);
 
 extern const MPI_Datatype MPI_PTR;
 
index 61f16b1..d63e822 100644 (file)
 # ifndef MAC_OS_X_VERSION_10_12
 #   define MAC_OS_X_VERSION_10_12 101200
 # endif
-# define HAVE_WORKING_MMAP (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)
+constexpr bool HAVE_WORKING_MMAP = (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12);
 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-# define HAVE_WORKING_MMAP 0
+constexpr bool HAVE_WORKING_MMAP = false;
 #else
-# define HAVE_WORKING_MMAP 1
+constexpr bool HAVE_WORKING_MMAP = true;
 #endif
 
 #if SG_HAVE_SENDFILE
@@ -398,12 +398,10 @@ static void smpi_init_options(){
     XBT_DEBUG("Running without smpi_main(); disable smpi/privatization.");
     smpi_privatize_global_variables = SmpiPrivStrategies::NONE;
   }
-#if !HAVE_WORKING_MMAP
-  if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP) {
+  if (not HAVE_WORKING_MMAP && smpi_privatize_global_variables == SmpiPrivStrategies::MMAP) {
     XBT_INFO("mmap privatization is broken on this platform, switching to dlopen privatization instead.");
     smpi_privatize_global_variables = SmpiPrivStrategies::DLOPEN;
   }
-#endif
 
   if (smpi_cpu_threshold < 0)
     smpi_cpu_threshold = DBL_MAX;
index 154d70d..77d7bfd 100644 (file)
@@ -180,11 +180,11 @@ static void *smpi_shared_malloc_local(size_t size, const char *file, int line)
 }
 
 // Align functions, from http://stackoverflow.com/questions/4840410/how-to-align-a-pointer-in-c
-#define PAGE_SIZE 0x1000
 #define ALIGN_UP(n, align) (((n) + (align)-1) & -(align))
 #define ALIGN_DOWN(n, align) ((n) & -(align))
 
-#define HUGE_PAGE_SIZE 1<<21
+constexpr unsigned PAGE_SIZE      = 0x1000;
+constexpr unsigned HUGE_PAGE_SIZE = 1U << 21;
 
 /* Similar to smpi_shared_malloc, but only sharing the blocks described by shared_block_offsets.
  * This array contains the offsets (in bytes) of the block to share.
index 4c8aa1d..c29102b 100644 (file)
@@ -8,7 +8,7 @@
 #include "src/surf/surf_interface.hpp"
 #include "surf/surf.hpp"
 
-#define EPSILON 0.000000001
+constexpr double EPSILON = 0.000000001;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_cpu_ti, surf_cpu, "Logging specific to the SURF CPU TRACE INTEGRATION module");
 
index 178b151..e15c41d 100644 (file)
@@ -19,6 +19,8 @@
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict, xbt, "Dictionaries provide the same functionalities as hash tables");
 
+constexpr int MAX_FILL_PERCENT = 80;
+
 /**
  * @brief Constructor
  * @param free_ctn function to call with (@a data as argument) when @a data is removed from the dictionary
index 424d589..6d83ae4 100644 (file)
@@ -19,8 +19,6 @@
 
 SG_BEGIN_DECL()
 
-#define MAX_FILL_PERCENT 80
-
 typedef struct s_xbt_dict {
   void_f_pvoid_t free_f;
   xbt_dictelm_t *table;
index 87bd5fe..dbd32ca 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "catch.hpp"
 
-#define NB_ELEM 5000
+constexpr int NB_ELEM = 5000;
 
 TEST_CASE("xbt::dynar: generic C vector", "dynar")
 {
index 2b2fc31..3a4f493 100644 (file)
@@ -60,10 +60,9 @@ static int worker_busy_loop_main(int argc, char* argv[])
   return 0;
 }
 
-#define DOUBLE_MAX 1e11
-
 static void test_dynamic_change(void)
 {
+  const double DOUBLE_MAX = 1e11;
   msg_host_t pm0 = MSG_host_by_name("Fafard");
 
   msg_vm_t vm0 = MSG_vm_create_core(pm0, "VM0");
index 49df392..2e8704a 100644 (file)
@@ -11,8 +11,6 @@
 #include "xbt/sysdep.h" /* time manipulation for benchmarking */
 #include "xbt/xbt_os_time.h"
 
-#define MYRANDMAX 1000
-
 #include <cstdint>
 #include <cstdio>
 #include <cstdlib>
@@ -27,12 +25,13 @@ static int myrand() {
 
 static double float_random(double max)
 {
+  constexpr double MYRANDMAX = 1000.0;
   return ((max * myrand()) / (MYRANDMAX + 1.0));
 }
 
 static unsigned int int_random(int max)
 {
-  return static_cast<uint32_t>(((max * 1.0) * myrand()) / (MYRANDMAX + 1.0));
+  return static_cast<uint32_t>(float_random(max));
 }
 
 static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limit, unsigned int pw_max_limit,
index 18fdca9..847ff6c 100644 (file)
@@ -17,8 +17,9 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"this test");
 
-#define BUFFSIZE 204800
-#define TESTSIZE 100
+constexpr int BUFFSIZE = 204800;
+constexpr int TESTSIZE = 100;
+
 #define size_of_block(i) (((i % 50)+1)* 100)
 
 static void check_block(const void* s, int c, int n)
index db7c43e..21f3fba 100644 (file)
@@ -15,9 +15,9 @@
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(parmap_bench, "Bench for parmap");
 
-#define MODES_DEFAULT 0x7
-#define ARRAY_SIZE 10007
-#define FIBO_MAX 25
+constexpr unsigned MODES_DEFAULT = 0x7;
+constexpr unsigned ARRAY_SIZE    = 10007;
+constexpr unsigned FIBO_MAX      = 25;
 
 void (*fun_to_apply)(unsigned*);