Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change "if(...) xbt_die(...)" to "xbt_assert(...)".
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 31 Mar 2021 09:58:57 +0000 (11:58 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 2 Apr 2021 08:39:10 +0000 (10:39 +0200)
Some of them could certainly be improved to report the error to the user code,
for example with a proper exception, but it's another work.

49 files changed:
doc/doxygen/uhood_switch.doc
examples/c/dht-pastry/dht-pastry.c
examples/cpp/dht-chord/s4u-dht-chord.cpp
examples/cpp/maestro-set/s4u-maestro-set.cpp
examples/deprecated/simdag/ptg-dotload/sd_ptg-dotload.c
include/simgrid/kernel/future.hpp
include/xbt/sysdep.h
src/bindings/java/jmsg_task.cpp
src/instr/instr_interface.cpp
src/instr/instr_platform.cpp
src/kernel/activity/CommImpl.cpp
src/kernel/activity/SynchroRaw.cpp
src/kernel/context/ContextSwapped.cpp
src/mc/ModelChecker.cpp
src/mc/checker/CommunicationDeterminismChecker.cpp
src/mc/checker/simgrid_mc.cpp
src/mc/inspect/LocationList.cpp
src/mc/inspect/mc_dwarf.cpp
src/mc/mc_config.cpp
src/mc/mc_record.cpp
src/mc/remote/AppSide.cpp
src/mc/remote/RemoteProcess.cpp
src/mc/sosp/PageStore.cpp
src/mc/sosp/Snapshot.cpp
src/plugins/file_system/s4u_FileSystem.cpp
src/s4u/s4u_Host.cpp
src/simdag/sd_daxloader.cpp
src/smpi/bindings/smpi_pmpi.cpp
src/smpi/colls/bcast/bcast-scatter-rdb-allgather.cpp
src/smpi/colls/smpi_coll.cpp
src/smpi/internals/smpi_bench.cpp
src/smpi/internals/smpi_global.cpp
src/smpi/internals/smpi_memory.cpp
src/smpi/internals/smpi_shared.cpp
src/smpi/internals/smpi_utils.cpp
src/smpi/mpi/smpi_file.cpp
src/smpi/mpi/smpi_request.cpp
src/smpi/mpi/smpi_win.cpp
src/surf/cpu_ti.cpp
src/surf/network_ns3.cpp
src/surf/surf_interface.cpp
src/surf/xml/surfxml_parseplatf.cpp
src/xbt/automaton/automatonparse_promela.c
src/xbt/config.cpp
src/xbt/string.cpp
src/xbt/xbt_log_appender_file.cpp
teshsuite/simdag/flatifier/flatifier.cpp
teshsuite/smpi/coll-allreduce-with-leaks/coll-allreduce-with-leaks.tesh
teshsuite/xbt/mmalloc/mmalloc_test.cpp

index ae65213..4521722 100644 (file)
@@ -260,8 +260,7 @@ T simgrid::kernel::Future::get()
 template<class T>
 T simgrid::kernel::FutureState<T>::get()
 {
-  if (status_ != FutureStatus::ready)
-    xbt_die("Deadlock: this future is not ready");
+  xbt_assert(status_ == FutureStatus::ready, "Deadlock: this future is not ready");
   status_ = FutureStatus::done;
   if (exception_) {
     std::exception_ptr exception = std::move(exception_);
@@ -478,8 +477,7 @@ template<class F>
 auto kernel_sync(F code) -> decltype(code().get())
 {
   typedef decltype(code().get()) T;
-  if (SIMIX_is_maestro())
-    xbt_die("Can't execute blocking call in kernel mode");
+  xbt_assert(not SIMIX_is_maestro(), "Can't execute blocking call in kernel mode");
 
   smx_actor_t self = SIMIX_process_self();
   simgrid::xbt::Result<T> result;
index 10f21ac..0c1f981 100644 (file)
@@ -526,12 +526,10 @@ int main(int argc, char* argv[])
       XBT_DEBUG("Set nb_bits to %d", nb_bits);
     } else {
       length = strlen("-timeout=");
-      if (!strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) {
-        timeout = (int)xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s");
-        XBT_DEBUG("Set timeout to %d", timeout);
-      } else {
-        xbt_die("Invalid pastry option '%s'", options[0]);
-      }
+      xbt_assert(strncmp(options[0], "-timeout=", length) == 0 && strlen(options[0]) > length,
+                 "Invalid pastry option '%s'", options[0]);
+      timeout = (int)xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s");
+      XBT_DEBUG("Set timeout to %d", timeout);
     }
     options++;
   }
index 6651af6..bc2fb64 100644 (file)
@@ -26,12 +26,10 @@ int main(int argc, char* argv[])
       XBT_DEBUG("Set nb_bits to %d", nb_bits);
     } else {
       length = strlen("-timeout=");
-      if (not strncmp(options[0], "-timeout=", length) && strlen(options[0]) > length) {
-        timeout = static_cast<int>(xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s"));
-        XBT_DEBUG("Set timeout to %d", timeout);
-      } else {
-        xbt_die("Invalid chord option '%s'", options[0]);
-      }
+      xbt_assert(strncmp(options[0], "-timeout=", length) == 0 && strlen(options[0]) > length,
+                 "Invalid chord option '%s'", options[0]);
+      timeout = static_cast<int>(xbt_str_parse_int(options[0] + length, "Invalid timeout parameter: %s"));
+      XBT_DEBUG("Set timeout to %d", timeout);
     }
     options++;
   }
index 3f5e8d8..5ffa6e6 100644 (file)
@@ -68,10 +68,9 @@ int main(int argc, char* argv[])
 
   simgrid::s4u::Engine e(&argc, argv);
 
-  if (argc != 2) {
-    XBT_CRITICAL("Usage: %s platform_file\n", argv[0]);
-    xbt_die("example: %s ../platforms/small_platform.xml\n", argv[0]);
-  }
+  xbt_assert(argc == 2, "Usage: %s platform_file\n"
+                        "example: %s ../platforms/small_platform.xml\n",
+             argv[0], argv[0]);
 
   e.load_platform(argv[1]);
 
index de67161..4f3bf64 100644 (file)
@@ -26,9 +26,7 @@ int main(int argc, char **argv){
 
   /* load the DOT file */
   dot = SD_PTG_dotload(argv[2]);
-  if(dot == NULL){
-    xbt_die("No dot load may be you have a cycle in your graph");
-  }
+  xbt_assert(dot != NULL, "No dot load may be you have a cycle in your graph");
 
   /* Display all the tasks */
   XBT_INFO("------------------- Display all tasks of the loaded DAG ---------------------------");
index 897e4c2..e3a2468 100644 (file)
@@ -116,8 +116,7 @@ protected:
    **/
   void resolve()
   {
-    if (status_ != FutureStatus::ready)
-      xbt_die("Deadlock: this future is not ready");
+    xbt_assert(status_ == FutureStatus::ready, "Deadlock: this future is not ready");
     status_ = FutureStatus::done;
     if (exception_) {
       std::exception_ptr exception = std::move(exception_);
index 9640735..6a132f7 100644 (file)
@@ -40,8 +40,7 @@ static XBT_ALWAYS_INLINE char *xbt_strdup(const char *s) {
   char *res = NULL;
   if (s) {
     res = strdup(s);
-    if (!res)
-      xbt_die("memory allocation error (strdup returned NULL)");
+    xbt_assert(res, "memory allocation error (strdup returned NULL)");
   }
   return res;
 }
@@ -50,8 +49,7 @@ static XBT_ALWAYS_INLINE char *xbt_strdup(const char *s) {
     @hideinitializer */
 static XBT_ALWAYS_INLINE void *xbt_malloc(size_t n) {
   void* res = malloc(n);
-  if (!res)
-    xbt_die("Memory allocation of %lu bytes failed", (unsigned long)n);
+  xbt_assert(res, "Memory allocation of %lu bytes failed", (unsigned long)n);
   return res;
 }
 
@@ -59,8 +57,7 @@ static XBT_ALWAYS_INLINE void *xbt_malloc(size_t n) {
     @hideinitializer */
 static XBT_ALWAYS_INLINE void *xbt_malloc0(size_t n) {
   void* res = calloc(n, 1);
-  if (!res)
-    xbt_die("Memory callocation of %lu bytes failed", (unsigned long)n);
+  xbt_assert(res, "Memory callocation of %lu bytes failed", (unsigned long)n);
   return res;
 }
 
@@ -71,8 +68,7 @@ static XBT_ALWAYS_INLINE void *xbt_realloc(void *p, size_t s) {
   if (s) {
     if (p) {
       res = realloc(p, s);
-      if (!res)
-        xbt_die("memory (re)allocation of %lu bytes failed", (unsigned long)s);
+      xbt_assert(res, "memory (re)allocation of %lu bytes failed", (unsigned long)s);
     } else {
       res = xbt_malloc(s);
     }
index 798d8f2..fc8c867 100644 (file)
@@ -115,8 +115,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_cancel(JNIEnv * env, jobject jt
   }
 
   msg_error_t rv = MSG_task_cancel(ptask);
-  if (rv != MSG_OK)
-    xbt_die("MSG_task_cancel() unexpectedly failed with error code %d. Please report this bug", rv);
+  xbt_assert(rv == MSG_OK, "MSG_task_cancel() unexpectedly failed with error code %d. Please report this bug", rv);
 }
 
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_execute(JNIEnv * env, jobject jtask)
index d6c2d30..245e609 100644 (file)
@@ -297,12 +297,10 @@ static void instr_user_srcdst_variable(double time, const char *src, const char
                               const char *father_type, double value, InstrUserVariable what)
 {
   simgrid::kernel::routing::NetPoint* src_elm = sg_netpoint_by_name_or_null(src);
-  if (not src_elm)
-    xbt_die("Element '%s' not found!",src);
+  xbt_assert(src_elm, "Element '%s' not found!", src);
 
   simgrid::kernel::routing::NetPoint* dst_elm = sg_netpoint_by_name_or_null(dst);
-  if (not dst_elm)
-    xbt_die("Element '%s' not found!",dst);
+  xbt_assert(dst_elm, "Element '%s' not found!", dst);
 
   std::vector<simgrid::kernel::resource::LinkImpl*> route;
   simgrid::kernel::routing::NetZoneImpl::get_global_route(src_elm, dst_elm, route, nullptr);
index 9e4594c..0ae2219 100644 (file)
@@ -75,9 +75,7 @@ static void linkContainers(simgrid::instr::Container* src, simgrid::instr::Conta
 
   // find common father
   simgrid::instr::Container* father = lowestCommonAncestor(src, dst);
-  if (not father) {
-    xbt_die("common father unknown, this is a tracing problem");
-  }
+  xbt_assert(father, "common father unknown, this is a tracing problem");
 
   // check if we already register this pair (we only need one direction)
   std::string aux1 = src->get_name() + dst->get_name();
index f51af06..44dcf48 100644 (file)
@@ -290,8 +290,7 @@ void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, simgrid::kernel::activi
                                   double timeout)
 {
   if (MC_is_active() || MC_record_replay_is_active()) {
-    if (timeout > 0.0)
-      xbt_die("Timeout not implemented for waitany in the model-checker");
+    xbt_assert(timeout <= 0.0, "Timeout not implemented for waitany in the model-checker");
     int idx                 = simcall->mc_value_;
     auto* comm              = comms[idx];
     comm->simcalls_.push_back(simcall);
index a549337..5b8950c 100644 (file)
@@ -76,8 +76,9 @@ void RawImpl::finish()
     XBT_DEBUG("RawImpl::finish(): host '%s' failed", simcall->issuer_->get_host()->get_cname());
     simcall->issuer_->context_->set_wannadie();
     simcall->issuer_->exception_ = std::make_exception_ptr(HostFailureException(XBT_THROW_POINT, "Host failed"));
-  } else if (state_ != State::SRC_TIMEOUT) {
-    xbt_die("Internal error in RawImpl::finish() unexpected synchro state %d", static_cast<int>(state_));
+  } else {
+    xbt_assert(state_ == State::SRC_TIMEOUT, "Internal error in RawImpl::finish() unexpected synchro state %d",
+               static_cast<int>(state_));
   }
 
   finish_callback_();
index bd913fb..d93d602 100644 (file)
@@ -97,25 +97,22 @@ SwappedContext::SwappedContext(std::function<void()>&& code, smx_actor_t actor,
       reinterpret_cast<unsigned char**>(stack_)[-1] = alloc;
 #elif !defined(_WIN32)
       void* alloc;
-      if (posix_memalign(&alloc, xbt_pagesize, size) != 0)
-        xbt_die("Failed to allocate stack.");
+      xbt_assert(posix_memalign(&alloc, xbt_pagesize, size) == 0, "Failed to allocate stack.");
       this->stack_ = static_cast<unsigned char*>(alloc);
 #else
       this->stack_ = static_cast<unsigned char*>(_aligned_malloc(size, xbt_pagesize));
 #endif
 
 #ifndef _WIN32
-      if (mprotect(this->stack_, smx_context_guard_size, PROT_NONE) == -1) {
-        xbt_die(
-            "Failed to protect stack: %s.\n"
-            "If you are running a lot of actors, you may be exceeding the amount of mappings allowed per process.\n"
-            "On Linux systems, change this value with sudo sysctl -w vm.max_map_count=newvalue (default value: 65536)\n"
-            "Please see "
-            "https://simgrid.org/doc/latest/Configuring_SimGrid.html#configuring-the-user-code-virtualization for more "
-            "information.",
-            strerror(errno));
-        /* This is fatal. We are going to fail at some point when we try reusing this. */
-      }
+      /* This is fatal. We are going to fail at some point when we try reusing this. */
+      xbt_assert(
+          mprotect(this->stack_, smx_context_guard_size, PROT_NONE) != -1,
+          "Failed to protect stack: %s.\n"
+          "If you are running a lot of actors, you may be exceeding the amount of mappings allowed per process.\n"
+          "On Linux systems, change this value with sudo sysctl -w vm.max_map_count=newvalue (default value: 65536)\n"
+          "Please see https://simgrid.org/doc/latest/Configuring_SimGrid.html#configuring-the-user-code-virtualization "
+          "for more information.",
+          strerror(errno));
 #endif
       this->stack_ = this->stack_ + smx_context_guard_size;
     } else {
index 3a9fb85..88a52a4 100644 (file)
@@ -64,9 +64,8 @@ void ModelChecker::start()
   // The model-checked process SIGSTOP itself to signal it's ready:
   const pid_t pid = remote_process_->pid();
 
-  pid_t res = waitpid(pid, &status, WAITPID_CHECKED_FLAGS);
-  if (res < 0 || not WIFSTOPPED(status) || WSTOPSIG(status) != SIGSTOP)
-    xbt_die("Could not wait model-checked process");
+  xbt_assert(waitpid(pid, &status, WAITPID_CHECKED_FLAGS) == pid && WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP,
+             "Could not wait model-checked process");
 
   if (not _sg_mc_dot_output_file.get().empty())
     MC_init_dot_output();
index 276fd77..ed9f983 100644 (file)
@@ -236,8 +236,7 @@ void CommunicationDeterminismChecker::complete_comm_pattern(RemotePtr<kernel::ac
   auto current_comm_pattern =
       std::find_if(begin(incomplete_pattern), end(incomplete_pattern),
                    [&comm_addr](const PatternCommunication* comm) { return (comm->comm_addr == comm_addr); });
-  if (current_comm_pattern == std::end(incomplete_pattern))
-    xbt_die("Corresponding communication not found!");
+  xbt_assert(current_comm_pattern != std::end(incomplete_pattern), "Corresponding communication not found!");
 
   update_comm_pattern(*current_comm_pattern, comm_addr);
   std::unique_ptr<PatternCommunication> comm_pattern(*current_comm_pattern);
index 767c0bf..649562e 100644 (file)
@@ -31,8 +31,7 @@ char** argvdup(int argc, char** argv)
 
 int main(int argc, char** argv)
 {
-  if (argc < 2)
-    xbt_die("Missing arguments.\n");
+  xbt_assert(argc >= 2, "Missing arguments");
 
   // Currently, we need this before sg_config_init:
   _sg_do_model_check = 1;
index 426b97b..7bfb61f 100644 (file)
@@ -53,11 +53,10 @@ Location resolve(simgrid::dwarf::LocationList const& locations, simgrid::mc::Obj
                  unw_cursor_t* c, void* frame_pointer_address, const simgrid::mc::AddressSpace* address_space)
 {
   unw_word_t ip = 0;
-  if (c && unw_get_reg(c, UNW_REG_IP, &ip))
-    xbt_die("Could not resolve IP");
+  if (c)
+    xbt_assert(unw_get_reg(c, UNW_REG_IP, &ip) == 0, "Could not resolve IP");
   simgrid::dwarf::DwarfExpression const* expression = find_expression(locations, ip);
-  if (not expression)
-    xbt_die("Could not resolve location");
+  xbt_assert(expression != nullptr, "Could not resolve location");
   return simgrid::dwarf::resolve(*expression, object_info, c, frame_pointer_address, address_space);
 }
 
@@ -76,8 +75,7 @@ LocationList location_list(const simgrid::mc::ObjectInformation& info, Dwarf_Att
 
     if (offset == 0)
       break;
-    else if (offset == -1)
-      xbt_die("Error while loading location list");
+    xbt_assert(offset != -1, "Error while loading location list");
 
     auto base_address = reinterpret_cast<std::uint64_t>(info.base_address());
 
index d7b1868..90277e1 100644 (file)
@@ -399,10 +399,10 @@ static void MC_dwarf_fill_member_location(const simgrid::mc::Type* type, simgrid
   xbt_assert(not dwarf_hasattr(child, DW_AT_data_bit_offset), "Can't groke DW_AT_data_bit_offset.");
 
   if (not dwarf_hasattr_integrate(child, DW_AT_data_member_location)) {
-    if (type->type == DW_TAG_union_type)
-      return;
-    xbt_die("Missing DW_AT_data_member_location field in DW_TAG_member %s of type <%" PRIx64 ">%s",
-            member->name.c_str(), (uint64_t)type->id, type->name.c_str());
+    xbt_assert(type->type == DW_TAG_union_type,
+               "Missing DW_AT_data_member_location field in DW_TAG_member %s of type <%" PRIx64 ">%s",
+               member->name.c_str(), (uint64_t)type->id, type->name.c_str());
+    return;
   }
 
   Dwarf_Attribute attr;
index 39c3491..78c86b6 100644 (file)
@@ -25,10 +25,10 @@ simgrid::mc::ReductionMode reduction_mode = simgrid::mc::ReductionMode::unset;
 
 static void _mc_cfg_cb_check(const char* spec, bool more_check = true)
 {
-  if (_sg_cfg_init_status && not _sg_do_model_check && more_check)
-    xbt_die("You are specifying a %s after the initialization (through MSG_config?), but the program was not run under "
-            "the model-checker (with simgrid-mc)). This won't work, sorry.",
-            spec);
+  xbt_assert(_sg_cfg_init_status == 0 || _sg_do_model_check || not more_check,
+             "You are specifying a %s after the initialization (through MSG_config?), but the program was not run "
+             "under the model-checker (with simgrid-mc)). This won't work, sorry.",
+             spec);
 }
 
 /* Replay (this part is enabled even if MC it disabled) */
index d8be674..bc2b30c 100644 (file)
@@ -30,13 +30,10 @@ void replay(RecordTrace const& trace)
 
     // Choose a request:
     kernel::actor::ActorImpl* actor = kernel::actor::ActorImpl::by_pid(transition.aid_);
-    if (actor == nullptr)
-      xbt_die("Unexpected actor (id:%ld).", transition.aid_);
+    xbt_assert(actor != nullptr, "Unexpected actor (id:%ld).", transition.aid_);
     const s_smx_simcall* simcall = &(actor->simcall_);
-    if (simcall->call_ == simix::Simcall::NONE)
-      xbt_die("No simcall for process %ld.", transition.aid_);
-    if (not simgrid::mc::request_is_visible(simcall) || not simgrid::mc::actor_is_enabled(actor))
-      xbt_die("Unexpected simcall.");
+    xbt_assert(simcall->call_ != simix::Simcall::NONE, "No simcall for process %ld.", transition.aid_);
+    xbt_assert(simgrid::mc::request_is_visible(simcall) && simgrid::mc::actor_is_enabled(actor), "Unexpected simcall.");
 
     // Execute the request:
     simcall->issuer_->simcall_handle(transition.times_considered_);
index b19fd09..27c7277 100644 (file)
@@ -46,8 +46,7 @@ AppSide* AppSide::initialize()
   // Check the socket type/validity:
   int type;
   socklen_t socklen = sizeof(type);
-  if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &socklen) != 0)
-    xbt_die("Could not check socket type");
+  xbt_assert(getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &socklen) == 0, "Could not check socket type");
   xbt_assert(type == SOCK_SEQPACKET, "Unexpected socket type %i", type);
   XBT_DEBUG("Model-checked application found expected socket type");
 
@@ -62,8 +61,8 @@ AppSide* AppSide::initialize()
 #else
 #error "no ptrace equivalent coded for this platform"
 #endif
-  if (errno != 0 || raise(SIGSTOP) != 0)
-    xbt_die("Could not wait for the model-checker (errno = %d: %s)", errno, strerror(errno));
+  xbt_assert(errno == 0 && raise(SIGSTOP) == 0, "Could not wait for the model-checker (errno = %d: %s)", errno,
+             strerror(errno));
 
   s_mc_message_initial_addresses_t message{
       MessageType::INITIAL_ADDRESSES, mmalloc_preinit(), simgrid::kernel::actor::get_maxpid_addr(),
@@ -97,8 +96,7 @@ void AppSide::handle_simcall_execute(const s_mc_message_simcall_handle_t* messag
   kernel::actor::ActorImpl* process = kernel::actor::ActorImpl::by_pid(message->aid_);
   xbt_assert(process != nullptr, "Invalid pid %lu", message->aid_);
   process->simcall_handle(message->times_considered_);
-  if (channel_.send(MessageType::WAITING))
-    xbt_die("Could not send MESSAGE_WAITING to model-checker");
+  xbt_assert(channel_.send(MessageType::WAITING) == 0, "Could not send MESSAGE_WAITING to model-checker");
 }
 
 void AppSide::handle_actor_enabled(const s_mc_message_actor_enabled_t* msg) const
@@ -231,8 +229,7 @@ void AppSide::main_loop() const
 
 void AppSide::report_assertion_failure() const
 {
-  if (channel_.send(MessageType::ASSERTION_FAILED))
-    xbt_die("Could not send assertion to model-checker");
+  xbt_assert(channel_.send(MessageType::ASSERTION_FAILED) == 0, "Could not send assertion to model-checker");
   this->handle_messages();
 }
 
@@ -242,8 +239,7 @@ void AppSide::ignore_memory(void* addr, std::size_t size) const
   message.type = MessageType::IGNORE_MEMORY;
   message.addr = (std::uintptr_t)addr;
   message.size = size;
-  if (channel_.send(message))
-    xbt_die("Could not send IGNORE_MEMORY message to model-checker");
+  xbt_assert(channel_.send(message) == 0, "Could not send IGNORE_MEMORY message to model-checker");
 }
 
 void AppSide::ignore_heap(void* address, std::size_t size) const
@@ -263,8 +259,7 @@ void AppSide::ignore_heap(void* address, std::size_t size) const
     heap->heapinfo[message.block].busy_frag.ignore[message.fragment]++;
   }
 
-  if (channel_.send(message))
-    xbt_die("Could not send ignored region to MCer");
+  xbt_assert(channel_.send(message) == 0, "Could not send ignored region to MCer");
 }
 
 void AppSide::unignore_heap(void* address, std::size_t size) const
@@ -273,21 +268,18 @@ void AppSide::unignore_heap(void* address, std::size_t size) const
   message.type = MessageType::UNIGNORE_HEAP;
   message.addr = (std::uintptr_t)address;
   message.size = size;
-  if (channel_.send(message))
-    xbt_die("Could not send IGNORE_HEAP message to model-checker");
+  xbt_assert(channel_.send(message) == 0, "Could not send IGNORE_HEAP message to model-checker");
 }
 
 void AppSide::declare_symbol(const char* name, int* value) const
 {
   s_mc_message_register_symbol_t message;
   message.type = MessageType::REGISTER_SYMBOL;
-  if (strlen(name) + 1 > message.name.size())
-    xbt_die("Symbol is too long");
+  xbt_assert(strlen(name) + 1 <= message.name.size(), "Symbol is too long");
   strncpy(message.name.data(), name, message.name.size());
   message.callback = nullptr;
   message.data     = value;
-  if (channel_.send(message))
-    xbt_die("Could send REGISTER_SYMBOL message to model-checker");
+  xbt_assert(channel_.send(message) == 0, "Could send REGISTER_SYMBOL message to model-checker");
 }
 
 void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) const
@@ -304,8 +296,7 @@ void AppSide::declare_stack(void* stack, size_t size, ucontext_t* context) const
   s_mc_message_stack_region_t message;
   message.type         = MessageType::STACK_REGION;
   message.stack_region = region;
-  if (channel_.send(message))
-    xbt_die("Could not send STACK_REGION to model-checker");
+  xbt_assert(channel_.send(message) == 0, "Could not send STACK_REGION to model-checker");
 }
 } // namespace mc
 } // namespace simgrid
index 64b83b5..eef3b18 100644 (file)
@@ -444,8 +444,8 @@ std::string RemoteProcess::read_string(RemotePtr<char> address) const
 
 void* RemoteProcess::read_bytes(void* buffer, std::size_t size, RemotePtr<void> address, ReadOptions /*options*/) const
 {
-  if (pread_whole(this->memory_file, buffer, size, (size_t)address.address()) < 0)
-    xbt_die("Read at %p from process %lli failed", (void*)address.address(), (long long)this->pid_);
+  xbt_assert(pread_whole(this->memory_file, buffer, size, (size_t)address.address()) != -1,
+             "Read at %p from process %lli failed", (void*)address.address(), (long long)this->pid_);
   return buffer;
 }
 
@@ -457,8 +457,8 @@ void* RemoteProcess::read_bytes(void* buffer, std::size_t size, RemotePtr<void>
  */
 void RemoteProcess::write_bytes(const void* buffer, size_t len, RemotePtr<void> address) const
 {
-  if (pwrite_whole(this->memory_file, buffer, len, (size_t)address.address()) < 0)
-    xbt_die("Write to process %lli failed", (long long)this->pid_);
+  xbt_assert(pwrite_whole(this->memory_file, buffer, len, (size_t)address.address()) != -1,
+             "Write to process %lli failed", (long long)this->pid_);
 }
 
 static void zero_buffer_init(const void** zero_buffer, size_t zero_buffer_size)
index 58fe243..07ff287 100644 (file)
@@ -42,8 +42,7 @@ PageStore::PageStore(std::size_t size) : capacity_(size)
   // Using mmap in order to be able to expand the region by relocating it somewhere else in the virtual memory space:
   void* memory =
       ::mmap(nullptr, size << xbt_pagebits, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0);
-  if (memory == MAP_FAILED)
-    xbt_die("Could not mmap initial snapshot pages.");
+  xbt_assert(memory != MAP_FAILED, "Could not mmap initial snapshot pages.");
 
   this->top_index_ = 0;
   this->memory_    = memory;
@@ -65,15 +64,13 @@ void PageStore::resize(std::size_t size)
   // virtual memory address if necessary:
 #if HAVE_MREMAP
   new_memory = mremap(this->memory_, old_bytesize, new_bytesize, MREMAP_MAYMOVE);
-  if (new_memory == MAP_FAILED)
-    xbt_die("Could not mremap snapshot pages.");
+  xbt_assert(new_memory != MAP_FAILED, "Could not mremap snapshot pages.");
 #else
   if (new_bytesize > old_bytesize) {
     // Grow: first try to add new space after current map
     new_memory = mmap((char*)this->memory_ + old_bytesize, new_bytesize - old_bytesize, PROT_READ | PROT_WRITE,
                       MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0);
-    if (new_memory == MAP_FAILED)
-      xbt_die("Could not mremap snapshot pages.");
+    xbt_assert(new_memory != MAP_FAILED, "Could not mremap snapshot pages.");
     // Check if expanding worked
     if (new_memory != (char*)this->memory_ + old_bytesize) {
       // New memory segment could not be put at the end of this->memory_,
@@ -81,8 +78,7 @@ void PageStore::resize(std::size_t size)
       munmap(new_memory, new_bytesize - old_bytesize);
       new_memory =
           mmap(nullptr, new_bytesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE, -1, 0);
-      if (new_memory == MAP_FAILED)
-        xbt_die("Could not mremap snapshot pages.");
+      xbt_assert(new_memory != MAP_FAILED, "Could not mremap snapshot pages.");
       memcpy(new_memory, this->memory_, old_bytesize);
       munmap(this->memory_, old_bytesize);
     }
index 82702f9..b195356 100644 (file)
@@ -72,8 +72,7 @@ static void fill_local_variables_values(mc_stack_frame_t stack_frame, Frame* sco
                                                          &(stack_frame->unw_cursor), (void*)stack_frame->frame_base,
                                                          &mc_model_checker->get_remote_process());
 
-      if (not location.in_memory())
-        xbt_die("Cannot handle non-address variable");
+      xbt_assert(location.in_memory(), "Cannot handle non-address variable");
       new_var.address = location.address();
     } else
       xbt_die("No address");
@@ -137,10 +136,8 @@ static std::vector<s_mc_stack_frame_t> unwind_stack_frames(UnwindContext* stack_
       break;
 
     int ret = unw_step(&c);
-    if (ret == 0)
-      xbt_die("Unexpected end of stack.");
-    else if (ret < 0)
-      xbt_die("Error while unwinding stack");
+    xbt_assert(ret >= 0, "Error while unwinding stack");
+    xbt_assert(ret != 0, "Unexpected end of stack.");
   }
 
   xbt_assert(not result.empty(), "unw_init_local failed");
index 46dcac8..1807a0d 100644 (file)
@@ -53,15 +53,15 @@ Disk* File::find_local_disk_on(const Host* host)
       longest_prefix_length = current_mount.length();
       d                     = disk;
     }
-    if (longest_prefix_length > 0) { /* Mount point found, split fullpath_ into mount_name and path+filename*/
-      mount_point_ = fullpath_.substr(0, longest_prefix_length);
-      if (mount_point_ == std::string("/"))
-        path_ = fullpath_;
-      else
-        path_ = fullpath_.substr(longest_prefix_length, fullpath_.length());
-      XBT_DEBUG("%s + %s", mount_point_.c_str(), path_.c_str());
-    } else
-      xbt_die("Can't find mount point for '%s' on '%s'", fullpath_.c_str(), host->get_cname());
+    xbt_assert(longest_prefix_length > 0, "Can't find mount point for '%s' on '%s'", fullpath_.c_str(),
+               host->get_cname());
+    /* Mount point found, split fullpath_ into mount_name and path+filename*/
+    mount_point_ = fullpath_.substr(0, longest_prefix_length);
+    if (mount_point_ == std::string("/"))
+      path_ = fullpath_;
+    else
+      path_ = fullpath_.substr(longest_prefix_length, fullpath_.length());
+    XBT_DEBUG("%s + %s", mount_point_.c_str(), path_.c_str());
   }
   return d;
 }
index 81aa555..fdaf2ca 100644 (file)
@@ -69,8 +69,7 @@ Host* Host::by_name_or_null(const std::string& name)
 Host* Host::current()
 {
   kernel::actor::ActorImpl* self = kernel::actor::ActorImpl::self();
-  if (self == nullptr)
-    xbt_die("Cannot call Host::current() from the maestro context");
+  xbt_assert(self != nullptr, "Cannot call Host::current() from the maestro context");
   return self->get_host();
 }
 
index 61383ba..af8a699 100644 (file)
@@ -154,9 +154,7 @@ xbt_dynar_t SD_daxload(const char *filename)
   xbt_dynar_push(result, &root_task);
   SD_task_t end_task = SD_task_create_comp_seq("end", nullptr, 0);
 
-  int res = dax_lex();
-  if (res != 0)
-    xbt_die("Parse error in %s: %s", filename, dax__parse_err_msg());
+  xbt_assert(dax_lex() == 0, "Parse error in %s: %s", filename, dax__parse_err_msg());
   dax__delete_buffer(input_buffer);
   fclose(in_file);
   dax_lex_destroy();
index 39846ef..73a9d6b 100644 (file)
@@ -152,15 +152,13 @@ int PMPI_Get_address(const void *location, MPI_Aint * address)
 
 MPI_Aint PMPI_Aint_add(MPI_Aint address, MPI_Aint disp)
 {
-  if(address > PTRDIFF_MAX - disp)
-    xbt_die("overflow in MPI_Aint_add");
+  xbt_assert(address <= PTRDIFF_MAX - disp, "overflow in MPI_Aint_add");
   return address + disp;
 }
 
 MPI_Aint PMPI_Aint_diff(MPI_Aint address, MPI_Aint disp)
 {
-  if(address < PTRDIFF_MIN + disp)
-    xbt_die("underflow in MPI_Aint_diff");
+  xbt_assert(address >= PTRDIFF_MIN + disp, "underflow in MPI_Aint_diff");
   return address - disp;
 }
 
index 8f2d24d..70c043a 100644 (file)
@@ -164,8 +164,7 @@ int bcast__scatter_rdb_allgather(
       position = 0;
       if (rank == root) {
         mpi_errno = datatype->pack(buffer, count, tmp_buf, nbytes, &position, comm);
-        if (mpi_errno)
-          xbt_die("crash while packing %d", mpi_errno);
+        xbt_assert(mpi_errno == 0, "crash while packing %d", mpi_errno);
       }
     }
 
@@ -174,9 +173,7 @@ int bcast__scatter_rdb_allgather(
 
     mpi_errno = scatter_for_bcast(root, comm,
                                   nbytes, tmp_buf);
-    if (mpi_errno) {
-      xbt_die("crash while scattering %d", mpi_errno);
-    }
+    xbt_assert(mpi_errno == 0, "crash while scattering %d", mpi_errno);
 
     /* curr_size is the amount of data that this process now has stored in
      * buffer at byte offset (relative_rank*scatter_size) */
@@ -316,16 +313,13 @@ int bcast__scatter_rdb_allgather(
 
     /* check that we received as much as we expected */
     /* recvd_size may not be accurate for packed heterogeneous data */
-    if (is_homogeneous && curr_size != nbytes) {
-      xbt_die("we didn't receive enough !");
-    }
+    xbt_assert(not is_homogeneous || curr_size == nbytes, "we didn't receive enough !");
 
     if (not is_contig || not is_homogeneous) {
       if (rank != root) {
         position  = 0;
         mpi_errno = MPI_Unpack(tmp_buf, nbytes, &position, buffer, count, datatype, comm);
-        if (mpi_errno)
-          xbt_die("error when unpacking %d", mpi_errno);
+        xbt_assert(mpi_errno == 0, "error when unpacking %d", mpi_errno);
       }
     }
 
index 5d75930..6e78241 100644 (file)
@@ -237,16 +237,14 @@ std::map<std::string, std::vector<s_mpi_coll_description_t>, std::less<>> smpi_c
 std::vector<s_mpi_coll_description_t>* colls::get_smpi_coll_descriptions(const std::string& name)
 {
   auto iter = smpi_coll_descriptions.find(name);
-  if (iter == smpi_coll_descriptions.end())
-    xbt_die("No collective named %s. This is a bug.", name.c_str());
+  xbt_assert(iter != smpi_coll_descriptions.end(), "No collective named %s. This is a bug.", name.c_str());
   return &iter->second;
 }
 
 static s_mpi_coll_description_t* find_coll_description(const std::string& collective, const std::string& algo)
 {
   std::vector<s_mpi_coll_description_t>* table = colls::get_smpi_coll_descriptions(collective);
-  if (table->empty())
-    xbt_die("No registered algorithm for collective '%s'! This is a bug.", collective.c_str());
+  xbt_assert(not table->empty(), "No registered algorithm for collective '%s'! This is a bug.", collective.c_str());
 
   for (auto& desc : *table) {
     if (algo == desc.name) {
@@ -289,8 +287,7 @@ void (*colls::smpi_coll_cleanup_callback)();
   {                                                                                                                    \
     auto desc = find_coll_description(_XBT_STRINGIFY(cat), name);                                                      \
     cat       = reinterpret_cast<ret(*) args>(desc->coll);                                                             \
-    if (cat == nullptr)                                                                                                \
-      xbt_die("Collective " _XBT_STRINGIFY(cat) " set to nullptr!");                                                   \
+    xbt_assert(cat != nullptr, "Collective " _XBT_STRINGIFY(cat) " set to nullptr!");                                  \
   }
 COLL_APPLY(COLL_SETTER, COLL_GATHER_SIG, "")
 COLL_APPLY(COLL_SETTER,COLL_ALLGATHER_SIG,"")
index 0e4e852..b3cf6c8 100644 (file)
@@ -90,9 +90,9 @@ void smpi_bench_begin()
   if (not smpi_cfg_papi_events_file().empty()) {
     int event_set = smpi_process()->papi_event_set();
     // PAPI_start sets everything to 0! See man(3) PAPI_start
-    if (PAPI_LOW_LEVEL_INITED == PAPI_is_initialized() && event_set && PAPI_start(event_set) != PAPI_OK) {
-      xbt_die("Could not start PAPI counters (TODO: this needs some proper handling).");
-    }
+    if (PAPI_LOW_LEVEL_INITED == PAPI_is_initialized() && event_set)
+      xbt_assert(PAPI_start(event_set) == PAPI_OK,
+                 "Could not start PAPI counters (TODO: this needs some proper handling).");
   }
 #endif
   xbt_os_threadtimer_start(smpi_process()->timer());
@@ -129,8 +129,8 @@ void smpi_bench_end()
     int event_set                       = smpi_process()->papi_event_set();
     std::vector<long long> event_values(counter_data.size());
 
-    if (event_set && PAPI_stop(event_set, &event_values[0]) != PAPI_OK) // Error
-      xbt_die("Could not stop PAPI counters.");
+    if (event_set)
+      xbt_assert(PAPI_stop(event_set, &event_values[0]) == PAPI_OK, "Could not stop PAPI counters.");
     for (unsigned int i = 0; i < counter_data.size(); i++)
       counter_data[i].second += event_values[i];
   }
@@ -364,8 +364,8 @@ int smpi_sample_2(int global, const char *file, int line, int iter_count)
 
   XBT_DEBUG("sample2 %s %d", loc.c_str(), iter_count);
   auto sample = samples.find(loc);
-  if (sample == samples.end())
-    xbt_die("Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
+  xbt_assert(sample != samples.end(),
+             "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   const LocalData& data = sample->second;
 
   if (data.benching) {
@@ -400,8 +400,8 @@ void smpi_sample_3(int global, const char *file, int line)
 
   XBT_DEBUG("sample3 %s", loc.c_str());
   auto sample = samples.find(loc);
-  if (sample == samples.end())
-    xbt_die("Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
+  xbt_assert(sample != samples.end(),
+             "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   LocalData& data = sample->second;
 
   if (not data.benching)
@@ -432,9 +432,9 @@ int smpi_sample_exit(int global, const char *file, int line, int iter_count){
 
     XBT_DEBUG("sample exit %s", loc.c_str());
     auto sample = samples.find(loc);
-    if (sample == samples.end())
-      xbt_die("Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
-  
+    xbt_assert(sample != samples.end(),
+               "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
+
     if (smpi_process()->sampling()){//end of loop, but still sampling needed
       const LocalData& data = sample->second;
       smpi_process()->set_sampling(0);
index 72c5425..30d81d3 100644 (file)
@@ -363,10 +363,10 @@ static void smpi_copy_file(const std::string& src, const std::string& target, of
     close(fdin);
     close(fdout);
     return;
-  } else if (sent_size != -1 || errno != ENOSYS) {
-    xbt_die("Error while copying %s: only %zd bytes copied instead of %" PRIdMAX " (errno: %d -- %s)", target.c_str(),
-            sent_size, static_cast<intmax_t>(fdin_size), errno, strerror(errno));
   }
+  xbt_assert(sent_size == -1 && errno == ENOSYS,
+             "Error while copying %s: only %zd bytes copied instead of %" PRIdMAX " (errno: %d -- %s)", target.c_str(),
+             sent_size, static_cast<intmax_t>(fdin_size), errno, strerror(errno));
 #endif
   // If this point is reached, sendfile() actually is not available.  Copy file by hand.
   std::vector<unsigned char> buf(1024 * 1024 * 4);
index f425e22..c542a20 100644 (file)
@@ -159,20 +159,18 @@ Ask the Internet about tutorials on how to increase the files limit such as: htt
 void* smpi_temp_shm_mmap(int fd, size_t size)
 {
   struct stat st;
-  if (fstat(fd, &st) != 0)
-    xbt_die("Could not stat fd %d: %s", fd, strerror(errno));
-  if (static_cast<off_t>(size) > st.st_size && ftruncate(fd, static_cast<off_t>(size)) != 0)
-    xbt_die("Could not truncate fd %d to %zu: %s", fd, size, strerror(errno));
+  xbt_assert(fstat(fd, &st) == 0, "Could not stat fd %d: %s", fd, strerror(errno));
+  xbt_assert(static_cast<off_t>(size) <= st.st_size || ftruncate(fd, static_cast<off_t>(size)) == 0,
+             "Could not truncate fd %d to %zu: %s", fd, size, strerror(errno));
   void* mem = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-  if (mem == MAP_FAILED) {
-    xbt_die("Failed to map fd %d with size %zu: %s\n"
-            "If you are running a lot of ranks, you may be exceeding the amount of mappings allowed per process.\n"
-            "On Linux systems, change this value with sudo sysctl -w vm.max_map_count=newvalue (default value: 65536)\n"
-            "Please see "
-            "https://simgrid.org/doc/latest/Configuring_SimGrid.html#configuring-the-user-code-virtualization for more "
-            "information.",
-            fd, size, strerror(errno));
-  }
+  xbt_assert(
+      mem != MAP_FAILED,
+      "Failed to map fd %d with size %zu: %s\n"
+      "If you are running a lot of ranks, you may be exceeding the amount of mappings allowed per process.\n"
+      "On Linux systems, change this value with sudo sysctl -w vm.max_map_count=newvalue (default value: 65536)\n"
+      "Please see https://simgrid.org/doc/latest/Configuring_SimGrid.html#configuring-the-user-code-virtualization for "
+      "more information.",
+      fd, size, strerror(errno));
   return mem;
 }
 
@@ -194,9 +192,9 @@ void smpi_switch_data_segment(simgrid::s4u::ActorPtr actor)
   XBT_DEBUG("Switching data frame to the one of process %ld", actor->get_pid());
   const simgrid::smpi::ActorExt* process = smpi_process_remote(actor);
   int current                     = process->privatized_region()->file_descriptor;
-  const void* tmp = mmap(TOPAGE(smpi_data_exe_start), smpi_data_exe_size, PROT_RW, MAP_FIXED | MAP_SHARED, current, 0);
-  if (tmp != TOPAGE(smpi_data_exe_start))
-    xbt_die("Couldn't map the new region (errno %d): %s", errno, strerror(errno));
+  xbt_assert(mmap(TOPAGE(smpi_data_exe_start), smpi_data_exe_size, PROT_RW, MAP_FIXED | MAP_SHARED, current, 0) ==
+                 TOPAGE(smpi_data_exe_start),
+             "Couldn't map the new region (errno %d): %s", errno, strerror(errno));
   smpi_loaded_page = actor->get_pid();
 #endif
 }
index 34e70d2..b495246 100644 (file)
@@ -208,9 +208,8 @@ void* smpi_shared_malloc_partial(size_t size, const size_t* shared_block_offsets
     smpi_shared_malloc_bogusfile = mkstemp(name);
     XBT_DEBUG("bogusfile         : %s\n", name);
     unlink(name);
-    int err = ftruncate(smpi_shared_malloc_bogusfile, smpi_shared_malloc_blocksize);
-    if (err != 0)
-      xbt_die("Could not write bogus file for shared malloc");
+    xbt_assert(ftruncate(smpi_shared_malloc_bogusfile, smpi_shared_malloc_blocksize) == 0,
+               "Could not write bogus file for shared malloc");
   }
 
   int mmap_base_flag = MAP_FIXED | MAP_SHARED | MAP_POPULATE;
index a8cbb44..784db99 100644 (file)
@@ -58,9 +58,8 @@ std::vector<s_smpi_factor_t> parse_factor(const std::string& smpi_coef_string)
     XBT_DEBUG("token : %s", token_iter->c_str());
     Tokenizer factor_values(*token_iter, factor_separator);
     s_smpi_factor_t fact;
-    if (factor_values.begin() == factor_values.end()) {
-      xbt_die("Malformed radical for smpi factor: '%s'", smpi_coef_string.c_str());
-    }
+    xbt_assert(factor_values.begin() != factor_values.end(), "Malformed radical for smpi factor: '%s'",
+               smpi_coef_string.c_str());
     unsigned int iteration = 0;
     for (Tokenizer::iterator factor_iter = factor_values.begin(); factor_iter != factor_values.end(); ++factor_iter) {
       iteration++;
index 911ee58..48647a5 100644 (file)
@@ -30,8 +30,8 @@ namespace smpi{
     if (info_ != MPI_INFO_NULL)
       info_->ref();
     std::string fullname=filename;
-    if (simgrid::s4u::Host::current()->get_disks().empty())
-      xbt_die("SMPI/IO : Trying to open file on a diskless host ! Add one to your platform file");
+    xbt_assert(not simgrid::s4u::Host::current()->get_disks().empty(),
+               "SMPI/IO : Trying to open file on a diskless host ! Add one to your platform file");
 
     size_t found=fullname.find('/');
     //in case no fullpath is provided ... just pick the first mountpoint.
index 14bc5ce..633fcd7 100644 (file)
@@ -73,31 +73,29 @@ void Request::ref(){
 
 void Request::unref(MPI_Request* request)
 {
-  if((*request) != MPI_REQUEST_NULL){
-    (*request)->refcount_--;
-    if((*request)->refcount_ < 0) {
-      (*request)->print_request("wrong refcount");
-      xbt_die("Whoops, wrong refcount");
-    }
-    if((*request)->refcount_==0){
-      if ((*request)->flags_ & MPI_REQ_GENERALIZED){
-        ((*request)->generalized_funcs)->free_fn(((*request)->generalized_funcs)->extra_state);
-      }else{
-        Comm::unref((*request)->comm_);
-        Datatype::unref((*request)->old_type_);
-      }
-      if ((*request)->op_!=MPI_REPLACE && (*request)->op_!=MPI_OP_NULL)
-        Op::unref(&(*request)->op_);
+  xbt_assert(*request != MPI_REQUEST_NULL, "freeing an already free request");
 
-      (*request)->print_request("Destroying");
-      F2C::free_f((*request)->c2f());
-      delete *request;
-      *request = MPI_REQUEST_NULL;
-    }else{
-      (*request)->print_request("Decrementing");
+  (*request)->refcount_--;
+  if ((*request)->refcount_ < 0) {
+    (*request)->print_request("wrong refcount");
+    xbt_die("Whoops, wrong refcount");
+  }
+  if ((*request)->refcount_ == 0) {
+    if ((*request)->flags_ & MPI_REQ_GENERALIZED) {
+      ((*request)->generalized_funcs)->free_fn(((*request)->generalized_funcs)->extra_state);
+    } else {
+      Comm::unref((*request)->comm_);
+      Datatype::unref((*request)->old_type_);
     }
-  }else{
-    xbt_die("freeing an already free request");
+    if ((*request)->op_ != MPI_REPLACE && (*request)->op_ != MPI_OP_NULL)
+      Op::unref(&(*request)->op_);
+
+    (*request)->print_request("Destroying");
+    F2C::free_f((*request)->c2f());
+    delete *request;
+    *request = MPI_REQUEST_NULL;
+  } else {
+    (*request)->print_request("Decrementing");
   }
 }
 
index bc35012..b04f1b7 100644 (file)
@@ -520,8 +520,7 @@ int Win::post(MPI_Group group, int /*assert*/)
 }
 
 int Win::complete(){
-  if(opened_==0)
-    xbt_die("Complete called on already opened MPI_Win");
+  xbt_assert(opened_ != 0, "Complete called on already opened MPI_Win");
 
   XBT_DEBUG("Entering MPI_Win_Complete");
   int i             = 0;
index bce17e5..b51fe9c 100644 (file)
@@ -56,11 +56,10 @@ CpuTiProfile::CpuTiProfile(const profile::Profile* profile)
  */
 double CpuTiTmgr::integrate(double a, double b) const
 {
-  if ((a < 0.0) || (a > b)) {
-    xbt_die("Error, invalid integration interval [%.2f,%.2f]. "
-            "You probably have a task executing with negative computation amount. Check your code.",
-            a, b);
-  }
+  xbt_assert(a >= 0.0 && a <= b,
+             "Error, invalid integration interval [%.2f,%.2f]. You probably have a task executing with negative "
+             "computation amount. Check your code.",
+             a, b);
   if (fabs(a - b) < EPSILON)
     return 0.0;
 
index 0dbd1ef..1195cc7 100644 (file)
@@ -105,8 +105,8 @@ static void zoneCreation_cb(simgrid::s4u::NetZone const& zone)
   int mcs_value    = mcs ? atoi(mcs) : 3;
   int nss_value    = nss ? atoi(nss) : 1;
 #if NS3_MINOR_VERSION < 30
-  if (nss_value != 1 + (mcs_value / 8))
-    xbt_die("On NS3 < 3.30, NSS value has to satisfy NSS == 1+(MCS/8) constraint. Bailing out");
+  xbt_assert(nss_value == 1 + (mcs_value / 8),
+             "On NS3 < 3.30, NSS value has to satisfy NSS == 1+(MCS/8) constraint. Bailing out");
 #endif
   wifi.SetRemoteStationManager("ns3::ConstantRateWifiManager", "ControlMode", ns3::StringValue("HtMcs0"), "DataMode",
                                ns3::StringValue("HtMcs" + std::to_string(mcs_value)));
@@ -574,33 +574,32 @@ void ns3_add_direct_route(simgrid::kernel::routing::NetPoint* src, simgrid::kern
   xbt_assert(host_src != nullptr, "Network element %s does not seem to be ns-3-ready", src->get_cname());
   xbt_assert(host_dst != nullptr, "Network element %s does not seem to be ns-3-ready", dst->get_cname());
 
-  if (policy == simgrid::s4u::Link::SharingPolicy::WIFI) {
-    xbt_die("The wifi sharing policy is not supported for links. You want to use a wifi zone (see documentation).");
-  } else {
-    ns3::PointToPointHelper pointToPoint;
+  xbt_assert(policy != simgrid::s4u::Link::SharingPolicy::WIFI,
+             "The wifi sharing policy is not supported for links. You want to use a wifi zone (see documentation).");
 
-    XBT_DEBUG("\tAdd PTP from %s to %s bw:'%f Bps' lat:'%fs'", src->get_cname(), dst->get_cname(), bw, lat);
-    pointToPoint.SetDeviceAttribute("DataRate",
-                                    ns3::DataRateValue(ns3::DataRate(bw * 8))); // ns-3 takes bps, but we provide Bps
-    pointToPoint.SetChannelAttribute("Delay", ns3::TimeValue(ns3::Seconds(lat)));
+  ns3::PointToPointHelper pointToPoint;
 
-    netA.Add(pointToPoint.Install(host_src->ns3_node_, host_dst->ns3_node_));
+  XBT_DEBUG("\tAdd PTP from %s to %s bw:'%f Bps' lat:'%fs'", src->get_cname(), dst->get_cname(), bw, lat);
+  pointToPoint.SetDeviceAttribute("DataRate",
+                                  ns3::DataRateValue(ns3::DataRate(bw * 8))); // ns-3 takes bps, but we provide Bps
+  pointToPoint.SetChannelAttribute("Delay", ns3::TimeValue(ns3::Seconds(lat)));
 
-    std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links);
-    address.SetBase(addr.c_str(), "255.255.0.0");
-    XBT_DEBUG("\tInterface stack '%s'", addr.c_str());
+  netA.Add(pointToPoint.Install(host_src->ns3_node_, host_dst->ns3_node_));
 
-    auto addresses = address.Assign(netA);
+  std::string addr = simgrid::xbt::string_printf("%d.%d.0.0", number_of_networks, number_of_links);
+  address.SetBase(addr.c_str(), "255.255.0.0");
+  XBT_DEBUG("\tInterface stack '%s'", addr.c_str());
 
-    host_src->ipv4_address_ = transformIpv4Address(addresses.GetAddress(0));
-    host_dst->ipv4_address_ = transformIpv4Address(addresses.GetAddress(1));
+  auto addresses = address.Assign(netA);
 
-    if (number_of_links == 255) {
-      xbt_assert(number_of_networks < 255, "Number of links and networks exceed 255*255");
-      number_of_links = 1;
-      number_of_networks++;
-    } else {
-      number_of_links++;
-    }
+  host_src->ipv4_address_ = transformIpv4Address(addresses.GetAddress(0));
+  host_dst->ipv4_address_ = transformIpv4Address(addresses.GetAddress(1));
+
+  if (number_of_links == 255) {
+    xbt_assert(number_of_networks < 255, "Number of links and networks exceed 255*255");
+    number_of_links = 1;
+    number_of_networks++;
+  } else {
+    number_of_links++;
   }
 }
index 4eec01a..3e020d7 100644 (file)
@@ -194,8 +194,7 @@ int find_model_description(const std::vector<surf_model_description_t>& table, c
   if (pos != table.end())
     return static_cast<int>(std::distance(table.begin(), pos));
 
-  if (table.empty())
-    xbt_die("No model is valid! This is a bug.");
+  xbt_assert(not table.empty(), "No model is valid! This is a bug.");
 
   std::string sep;
   std::string name_list;
index 59e24db..5201996 100644 (file)
@@ -78,10 +78,8 @@ void parse_platform_file(const std::string& file)
     luaL_loadfile(L, cfile); // This loads the file without executing it.
 
     /* Run the script */
-    if (lua_pcall(L, 0, 0, 0)) {
-      XBT_ERROR("FATAL ERROR:\n  %s: %s\n\n", "Lua call failed. Error message:", lua_tostring(L, -1));
-      xbt_die("Lua call failed. See Log");
-    }
+    xbt_assert(lua_pcall(L, 0, 0, 0) == 0, "FATAL ERROR:\n  %s: %s\n\n", "Lua call failed. Error message:",
+               lua_tostring(L, -1));
     lua_close(L);
     return;
 #else
index 7c7c90a..a257d01 100644 (file)
@@ -64,8 +64,7 @@ void xbt_automaton_load(xbt_automaton_t a, const char *file)
 {
   parsed_automaton = a;
   yyin = fopen(file, "r");
-  if (yyin == NULL)
-    xbt_die("Failed to open automaton file `%s': %s", file, strerror(errno));
+  xbt_assert(yyin != NULL, "Failed to open automaton file `%s': %s", file, strerror(errno));
   yyparse();
   fclose(yyin);
 }
index f213bb1..7cb1f63 100644 (file)
@@ -56,12 +56,10 @@ double parse_double(const char* value)
   double res = std::strtod(value, &end);
   if (errno == ERANGE)
     throw std::range_error("out of range");
-  else if (errno)
-    xbt_die("Unexpected errno");
+  xbt_assert(errno == 0, "Unexpected errno: %d", errno);
   if (end == value || *end != '\0')
     throw std::range_error("invalid double");
-  else
-    return res;
+  return res;
 }
 
 long int parse_long(const char* value)
@@ -69,17 +67,12 @@ long int parse_long(const char* value)
   char* end;
   errno = 0;
   long int res = std::strtol(value, &end, 0);
-  if (errno) {
-    if (res == LONG_MIN && errno == ERANGE)
-      throw std::range_error("underflow");
-    else if (res == LONG_MAX && errno == ERANGE)
-      throw std::range_error("overflow");
-    xbt_die("Unexpected errno");
-  }
+  if (errno == ERANGE)
+    throw std::range_error(res == LONG_MIN ? "underflow" : "overflow");
+  xbt_assert(errno == 0, "Unexpected errno: %d", errno);
   if (end == value || *end != '\0')
     throw std::range_error("invalid integer");
-  else
-    return res;
+  return res;
 }
 
 // ***** ConfigType *****
index 1b11219..7468c3b 100644 (file)
@@ -26,14 +26,13 @@ std::string string_vprintf(const char *fmt, va_list ap)
   va_copy(ap2, ap);
   int size = std::vsnprintf(nullptr, 0, fmt, ap2);
   va_end(ap2);
-  if (size < 0)
-    xbt_die("string_vprintf error");
+  xbt_assert(size >= 0, "string_vprintf error");
 
   // Allocate the string and format:
   std::string res;
   res.resize(size);
-  if (size != 0 && std::vsnprintf(&res[0], size + 1, fmt, ap) != size)
-    xbt_die("string_vprintf error");
+  if (size != 0)
+    xbt_assert(std::vsnprintf(&res[0], size + 1, fmt, ap) == size, "string_vprintf error");
   return res;
 }
 
index 928ef18..e014939 100644 (file)
@@ -41,8 +41,7 @@ xbt_log_appender_t xbt_log_appender_file_new(const char* arg)
   res->do_append         = &append_file;
   res->free_             = &free_;
   res->data              = static_cast<void*>(fopen(arg, "w"));
-  if (res->data == nullptr)
-    xbt_die("Cannot open file: %s: %s", arg, strerror(errno));
+  xbt_assert(res->data != nullptr, "Cannot open file: %s: %s", arg, strerror(errno));
   return res;
 }
 
@@ -62,8 +61,7 @@ static void open_append2_file(xbt_log_append2_file_t data){
     //Roll
     if (!data->file) {
       data->file= fopen(data->filename, "w");
-      if (data->file == nullptr)
-        xbt_die("Cannot open file: %s: %s", data->filename, strerror(errno));
+      xbt_assert(data->file != nullptr, "Cannot open file: %s: %s", data->filename, strerror(errno));
     } else {
       fputs(APPEND2_END_TOKEN_CLEAR,data->file);
       fseek(data->file,0,SEEK_SET);
@@ -81,8 +79,7 @@ static void open_append2_file(xbt_log_append2_file_t data){
     std::string newname = pre + std::to_string(data->count) + post;
     data->count++;
     data->file = fopen(newname.c_str(), "w");
-    if (data->file == nullptr)
-      xbt_die("Cannot open file: %s: %s", newname.c_str(), strerror(errno));
+    xbt_assert(data->file != nullptr, "Cannot open file: %s: %s", newname.c_str(), strerror(errno));
     xbt_free(pre);
   }
 }
index 46668da..44583a1 100644 (file)
@@ -202,8 +202,8 @@ int main(int argc, char** argv)
 
   sg4::Engine e(&argc, argv);
 
-  if (not parse_cmdline(&timings, &platformFile, argc, argv) || not platformFile)
-    xbt_die("Invalid command line arguments: expected [--timings] platformFile");
+  xbt_assert(parse_cmdline(&timings, &platformFile, argc, argv) && platformFile,
+             "Invalid command line arguments: expected [--timings] platformFile");
 
   XBT_DEBUG("%d,%s", timings, platformFile);
 
index db31cd0..a4ac497 100644 (file)
@@ -20,7 +20,7 @@ $ $VALGRIND_NO_LEAK_CHECK ${bindir:=.}/../../../smpi_script/bin/smpirun -map -ho
 > [rank 14] -> Ginette
 > [rank 15] -> Ginette
 > If this is too much, consider sharing allocations for computation buffers.
-> Largest allocation at once from a single process was 64 bytes, at sysdep.h:61. It was called 32 times during the whole simulation.
+> Largest allocation at once from a single process was 64 bytes, at sysdep.h:59. It was called 32 times during the whole simulation.
 > Running smpirun with -wrapper "valgrind --leak-check=full" can provide more information
 > This can be done automatically by setting --cfg=smpi/auto-shared-malloc-thresh to the minimum size wanted size (this can alter execution if data content is necessary)
 > [0.023768] [smpi_utils/INFO] Probable memory leaks in your code: SMPI detected 31 unfreed MPI handles : display types and addresses (n max) with --cfg=smpi/list-leaks:n.
index b610e1f..1a370eb 100644 (file)
@@ -27,8 +27,7 @@ constexpr int TESTSIZE = 100;
 static void check_block(const unsigned char* p, unsigned char b, int n)
 {
   for (int i = 0; i < n; i++)
-    if (p[i] != b)
-      xbt_die("value mismatch: %p[%d] = %#hhx, expected %#hhx", p, i, p[i], b);
+    xbt_assert(p[i] == b, "value mismatch: %p[%d] = %#hhx, expected %#hhx", p, i, p[i], b);
 }
 
 int main(int argc, char**argv)
@@ -80,8 +79,7 @@ int main(int argc, char**argv)
     } catch (const simgrid::Exception&) {
       gotit = true;
     }
-    if (not gotit)
-      xbt_die("FAIL: A double-free went undetected (for size:%d)",size_of_block(i));
+    xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i));
   }
 
   XBT_INFO("free again all blocks (to really check that double free are correctly caught)");
@@ -92,8 +90,7 @@ int main(int argc, char**argv)
     } catch (const simgrid::Exception&) {
       gotit = true;
     }
-    if (not gotit)
-      xbt_die("FAIL: A double-free went undetected (for size:%d)",size_of_block(i));
+    xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i));
   }
 
   XBT_INFO("Let's try different codepaths for mrealloc");