From: Arnaud Giersch Date: Tue, 26 Feb 2019 16:23:29 +0000 (+0100) Subject: Replace #define with constexpr declarations. X-Git-Tag: v3_22~229 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b024b9e443552c94609fc56a240cdb199a329853 Replace #define with constexpr declarations. --- diff --git a/examples/s4u/app-bittorrent/s4u-bittorrent.hpp b/examples/s4u/app-bittorrent/s4u-bittorrent.hpp index d61f301dab..4b1728bfd0 100644 --- a/examples/s4u/app-bittorrent/s4u-bittorrent.hpp +++ b/examples/s4u/app-bittorrent/s4u-bittorrent.hpp @@ -10,33 +10,33 @@ #include #include -#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 { diff --git a/examples/s4u/app-bittorrent/s4u-peer.cpp b/examples/s4u/app-bittorrent/s4u-peer.cpp index 5541383e19..d36aae49e9 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.cpp +++ b/examples/s4u/app-bittorrent/s4u-peer.cpp @@ -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 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++) diff --git a/examples/s4u/app-chainsend/s4u-app-chainsend.cpp b/examples/s4u/app-chainsend/s4u-app-chainsend.cpp index 28022f4255..39ee01def8 100644 --- a/examples/s4u/app-chainsend/s4u-app-chainsend.cpp +++ b/examples/s4u/app-chainsend/s4u-app-chainsend.cpp @@ -6,9 +6,9 @@ #include "simgrid/s4u.hpp" #include -#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"); diff --git a/examples/s4u/dht-chord/s4u-dht-chord.hpp b/examples/s4u/dht-chord/s4u-dht-chord.hpp index 1bedad77c9..0ca638a9e9 100644 --- a/examples/s4u/dht-chord/s4u-dht-chord.hpp +++ b/examples/s4u/dht-chord/s4u-dht-chord.hpp @@ -10,12 +10,12 @@ #include #include -#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; diff --git a/examples/s4u/dht-kademlia/node.cpp b/examples/s4u/dht-kademlia/node.cpp index a760100d79..ead02fe4e3 100644 --- a/examples/s4u/dht-kademlia/node.cpp +++ b/examples/s4u/dht-kademlia/node.cpp @@ -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(); diff --git a/examples/s4u/dht-kademlia/routing_table.cpp b/examples/s4u/dht-kademlia/routing_table.cpp index a6c9a63286..341153ba26 100644 --- a/examples/s4u/dht-kademlia/routing_table.cpp +++ b/examples/s4u/dht-kademlia/routing_table.cpp @@ -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]; } diff --git a/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp b/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp index cd70443a0b..29d8d2b10b 100644 --- a/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp +++ b/examples/s4u/dht-kademlia/s4u-dht-kademlia.cpp @@ -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); diff --git a/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp b/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp index a66c4a91e4..05a5078235 100644 --- a/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp +++ b/examples/s4u/dht-kademlia/s4u-dht-kademlia.hpp @@ -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 diff --git a/examples/s4u/synchro-mutex/s4u-synchro-mutex.cpp b/examples/s4u/synchro-mutex/s4u-synchro-mutex.cpp index 4f8b519418..e7819f7b53 100644 --- a/examples/s4u/synchro-mutex/s4u-synchro-mutex.cpp +++ b/examples/s4u/synchro-mutex/s4u-synchro-mutex.cpp @@ -6,7 +6,7 @@ #include /* 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"); diff --git a/src/bindings/lua/lua_host.cpp b/src/bindings/lua/lua_host.cpp index f2188fdd50..175be6ec03 100644 --- a/src/bindings/lua/lua_host.cpp +++ b/src/bindings/lua/lua_host.cpp @@ -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 */ /* ********************************************************************************* */ diff --git a/src/bindings/lua/lua_platf.cpp b/src/bindings/lua/lua_platf.cpp index ca19e544df..905776d163 100644 --- a/src/bindings/lua/lua_platf.cpp +++ b/src/bindings/lua/lua_platf.cpp @@ -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 */ diff --git a/src/include/xbt/mmalloc.h b/src/include/xbt/mmalloc.h index 60e57c4963..792e9e9eaf 100644 --- a/src/include/xbt/mmalloc.h +++ b/src/include/xbt/mmalloc.h @@ -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" diff --git a/src/instr/instr_config.cpp b/src/instr/instr_config.cpp index d90153a8a8..c6cdff7c5f 100644 --- a/src/instr/instr_config.cpp +++ b/src/instr/instr_config.cpp @@ -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 trace_enabled{ "tracing", "Enable the tracing system. You have to enable this option to use other tracing options.", false}; diff --git a/src/kernel/activity/MailboxImpl.hpp b/src/kernel/activity/MailboxImpl.hpp index b88d28d22e..2620d7eb24 100644 --- a/src/kernel/activity/MailboxImpl.hpp +++ b/src/kernel/activity/MailboxImpl.hpp @@ -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; diff --git a/src/mc/mc_exit.hpp b/src/mc/mc_exit.hpp index 3ec6ccff75..c725e83913 100644 --- a/src/mc/mc_exit.hpp +++ b/src/mc/mc_exit.hpp @@ -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 { diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index 1ea8e097f8..c588ce00ea 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -13,35 +13,35 @@ #include #include -#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 */ diff --git a/src/smpi/include/smpi_datatype.hpp b/src/smpi/include/smpi_datatype.hpp index 61af1d5a19..b183c19368 100644 --- a/src/smpi/include/smpi_datatype.hpp +++ b/src/smpi/include/smpi_datatype.hpp @@ -10,23 +10,24 @@ #include "smpi_keyvals.hpp" #include -#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; diff --git a/src/smpi/internals/smpi_global.cpp b/src/smpi/internals/smpi_global.cpp index 61f16b1ccc..d63e822c17 100644 --- a/src/smpi/internals/smpi_global.cpp +++ b/src/smpi/internals/smpi_global.cpp @@ -30,11 +30,11 @@ # 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; diff --git a/src/smpi/internals/smpi_shared.cpp b/src/smpi/internals/smpi_shared.cpp index 154d70d431..77d7bfd366 100644 --- a/src/smpi/internals/smpi_shared.cpp +++ b/src/smpi/internals/smpi_shared.cpp @@ -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. diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 4c8aa1dfe4..c29102b845 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -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"); diff --git a/src/xbt/dict.cpp b/src/xbt/dict.cpp index 178b151bc7..e15c41d516 100644 --- a/src/xbt/dict.cpp +++ b/src/xbt/dict.cpp @@ -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 diff --git a/src/xbt/dict_private.h b/src/xbt/dict_private.h index 424d589a59..6d83ae4497 100644 --- a/src/xbt/dict_private.h +++ b/src/xbt/dict_private.h @@ -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; diff --git a/src/xbt/dynar_test.cpp b/src/xbt/dynar_test.cpp index 87bd5fe9c5..dbd32ca0d1 100644 --- a/src/xbt/dynar_test.cpp +++ b/src/xbt/dynar_test.cpp @@ -10,7 +10,7 @@ #include "catch.hpp" -#define NB_ELEM 5000 +constexpr int NB_ELEM = 5000; TEST_CASE("xbt::dynar: generic C vector", "dynar") { diff --git a/teshsuite/msg/cloud-capping/cloud-capping.c b/teshsuite/msg/cloud-capping/cloud-capping.c index 2b2fc31f7a..3a4f4932b2 100644 --- a/teshsuite/msg/cloud-capping/cloud-capping.c +++ b/teshsuite/msg/cloud-capping/cloud-capping.c @@ -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"); diff --git a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp index 49df392b52..2e8704af1c 100644 --- a/teshsuite/surf/maxmin_bench/maxmin_bench.cpp +++ b/teshsuite/surf/maxmin_bench/maxmin_bench.cpp @@ -11,8 +11,6 @@ #include "xbt/sysdep.h" /* time manipulation for benchmarking */ #include "xbt/xbt_os_time.h" -#define MYRANDMAX 1000 - #include #include #include @@ -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(((max * 1.0) * myrand()) / (MYRANDMAX + 1.0)); + return static_cast(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, diff --git a/teshsuite/xbt/mmalloc/mmalloc_test.cpp b/teshsuite/xbt/mmalloc/mmalloc_test.cpp index 18fdca9d4f..847ff6cee3 100644 --- a/teshsuite/xbt/mmalloc/mmalloc_test.cpp +++ b/teshsuite/xbt/mmalloc/mmalloc_test.cpp @@ -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) diff --git a/teshsuite/xbt/parmap_bench/parmap_bench.cpp b/teshsuite/xbt/parmap_bench/parmap_bench.cpp index db7c43e831..21f3fba623 100644 --- a/teshsuite/xbt/parmap_bench/parmap_bench.cpp +++ b/teshsuite/xbt/parmap_bench/parmap_bench.cpp @@ -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*);