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_);
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;
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++;
}
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++;
}
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]);
/* 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 ---------------------------");
**/
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_);
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;
}
@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;
}
@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;
}
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);
}
}
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)
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);
// 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();
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);
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_();
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 {
// 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();
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);
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;
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);
}
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());
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;
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) */
// 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_);
// 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");
#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(),
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
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();
}
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
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
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
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
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;
}
*/
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)
// 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;
// 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_,
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);
}
&(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");
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");
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;
}
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();
}
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();
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;
}
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);
}
}
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) */
/* 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);
}
}
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) {
{ \
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,"")
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());
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];
}
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) {
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)
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);
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);
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;
}
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
}
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;
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++;
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.
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");
}
}
}
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;
*/
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;
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)));
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++;
}
}
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;
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
{
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);
}
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)
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 *****
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;
}
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;
}
//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);
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);
}
}
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);
> [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.
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)
} 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)");
} 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");