#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 {
* 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)
// 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++)
#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");
#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;
/* 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);
}
}
/**
- * 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)
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;
/* 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();
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 */
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();
/** @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;
{
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;
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];
}
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");
/* 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);
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
#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");
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 */
/* ********************************************************************************* */
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 */
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"
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};
#include "src/kernel/activity/CommImpl.hpp"
#include "src/simix/ActorImpl.hpp"
-#define MAX_MAILBOX_SIZE 10000000
namespace simgrid {
namespace kernel {
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;
#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 {
#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 */
#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;
# 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
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;
}
// 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.
#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");
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
SG_BEGIN_DECL()
-#define MAX_FILL_PERCENT 80
-
typedef struct s_xbt_dict {
void_f_pvoid_t free_f;
xbt_dictelm_t *table;
#include "catch.hpp"
-#define NB_ELEM 5000
+constexpr int NB_ELEM = 5000;
TEST_CASE("xbt::dynar: generic C vector", "dynar")
{
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");
#include "xbt/sysdep.h" /* time manipulation for benchmarking */
#include "xbt/xbt_os_time.h"
-#define MYRANDMAX 1000
-
#include <cstdint>
#include <cstdio>
#include <cstdlib>
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,
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)
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*);