From 84637d5a56f373e75eb6619d1afb54b7da3f5e36 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 2 Jul 2019 15:47:05 +0200 Subject: [PATCH] Throw std::invalid_argument. --- examples/deprecated/simdag/test/sd_test.cpp | 20 +++++-------- examples/s4u/app-bittorrent/s4u-peer.cpp | 4 +-- examples/s4u/app-bittorrent/s4u-tracker.cpp | 2 +- src/kernel/routing/DijkstraZone.cpp | 13 ++++---- src/kernel/routing/FloydZone.cpp | 3 +- src/simdag/sd_task.cpp | 30 +++++++++++-------- src/simix/popping_generated.cpp | 5 ++-- src/simix/simcalls.py | 5 ++-- src/simix/smx_deployment.cpp | 2 +- src/smpi/colls/allgather/allgather-2dmesh.cpp | 2 +- src/smpi/colls/allgather/allgather-3dmesh.cpp | 3 +- .../colls/allgather/allgather-SMP-NTS.cpp | 3 +- .../colls/allgather/allgather-loosely-lr.cpp | 4 ++- .../colls/allgather/allgather-mvapich-smp.cpp | 8 +++-- src/smpi/colls/allgather/allgather-pair.cpp | 2 +- src/smpi/colls/allgather/allgather-rhv.cpp | 2 +- .../colls/allgather/allgather-smp-simple.cpp | 4 ++- src/smpi/colls/allgatherv/allgatherv-pair.cpp | 2 +- src/smpi/colls/allreduce/allreduce-rab1.cpp | 2 +- .../allreduce/allreduce-smp-rsag-rab.cpp | 3 +- .../alltoall/alltoall-pair-light-barrier.cpp | 2 +- .../alltoall/alltoall-pair-mpi-barrier.cpp | 2 +- .../alltoall/alltoall-pair-one-barrier.cpp | 2 +- src/smpi/colls/alltoall/alltoall-pair.cpp | 2 +- .../alltoallv-pair-light-barrier.cpp | 2 +- .../alltoallv/alltoallv-pair-mpi-barrier.cpp | 2 +- .../alltoallv/alltoallv-pair-one-barrier.cpp | 2 +- src/smpi/colls/alltoallv/alltoallv-pair.cpp | 2 +- src/smpi/colls/reduce/reduce-rab.cpp | 2 +- .../reduce_scatter/reduce_scatter-ompi.cpp | 3 +- src/xbt/log.cpp | 9 +++--- src/xbt/xbt_str.cpp | 18 ++++++----- src/xbt/xbt_str_test.cpp | 4 +-- 33 files changed, 94 insertions(+), 77 deletions(-) diff --git a/examples/deprecated/simdag/test/sd_test.cpp b/examples/deprecated/simdag/test/sd_test.cpp index 2112647b59..59fead5068 100644 --- a/examples/deprecated/simdag/test/sd_test.cpp +++ b/examples/deprecated/simdag/test/sd_test.cpp @@ -69,33 +69,29 @@ int main(int argc, char **argv) try { SD_task_dependency_add(taskA, taskA); /* shouldn't work and must raise an exception */ xbt_die("Hey, I can add a dependency between Task A and Task A!"); - } catch (xbt_ex& ex) { - if (ex.category != arg_error) - throw; /* this is a serious error */ + } catch (const std::invalid_argument& e) { + XBT_DEBUG("Caught invalid_argument: %s", e.what()); } try { SD_task_dependency_add(taskB, taskA); /* shouldn't work and must raise an exception */ xbt_die("Oh oh, I can add an already existing dependency!"); - } catch (xbt_ex& ex) { - if (ex.category != arg_error) - throw; + } catch (const std::invalid_argument& e) { + XBT_DEBUG("Caught invalid_argument: %s", e.what()); } try { SD_task_dependency_remove(taskA, taskC); /* shouldn't work and must raise an exception */ xbt_die("Dude, I can remove an unknown dependency!"); - } catch (xbt_ex& ex) { - if (ex.category != arg_error) - throw; + } catch (const std::invalid_argument& e) { + XBT_DEBUG("Caught invalid_argument: %s", e.what()); } try { SD_task_dependency_remove(taskC, taskC); /* shouldn't work and must raise an exception */ xbt_die("Wow, I can remove a dependency between Task C and itself!"); - } catch (xbt_ex& ex) { - if (ex.category != arg_error) - throw; + } catch (const std::invalid_argument& e) { + XBT_DEBUG("Caught invalid_argument: %s", e.what()); } /* if everything is ok, no exception is forwarded or rethrown by main() */ diff --git a/examples/s4u/app-bittorrent/s4u-peer.cpp b/examples/s4u/app-bittorrent/s4u-peer.cpp index 53317ba98f..6d133cc240 100644 --- a/examples/s4u/app-bittorrent/s4u-peer.cpp +++ b/examples/s4u/app-bittorrent/s4u-peer.cpp @@ -34,13 +34,13 @@ Peer::Peer(std::vector args) id = std::stoi(args[1]); mailbox_ = simgrid::s4u::Mailbox::by_name(std::to_string(id)); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid ID:") + args[1].c_str()); + throw std::invalid_argument("Invalid ID:" + args[1]); } try { deadline = std::stod(args[2]); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid deadline:") + args[2].c_str()); + throw std::invalid_argument("Invalid deadline:" + args[2]); } xbt_assert(deadline > 0, "Wrong deadline supplied"); diff --git a/examples/s4u/app-bittorrent/s4u-tracker.cpp b/examples/s4u/app-bittorrent/s4u-tracker.cpp index b7bd4cd05f..a8a34461b2 100644 --- a/examples/s4u/app-bittorrent/s4u-tracker.cpp +++ b/examples/s4u/app-bittorrent/s4u-tracker.cpp @@ -18,7 +18,7 @@ Tracker::Tracker(std::vector args) try { deadline = std::stod(args[1]); } catch (const std::invalid_argument&) { - throw std::invalid_argument(std::string("Invalid deadline:") + args[1].c_str()); + throw std::invalid_argument("Invalid deadline:" + args[1]); } xbt_assert(deadline > 0, "Wrong deadline supplied"); diff --git a/src/kernel/routing/DijkstraZone.cpp b/src/kernel/routing/DijkstraZone.cpp index 3645a4fda9..1b6902fd1b 100644 --- a/src/kernel/routing/DijkstraZone.cpp +++ b/src/kernel/routing/DijkstraZone.cpp @@ -8,6 +8,7 @@ #include "src/surf/network_interface.hpp" #include "src/surf/xml/platf_private.hpp" #include "surf/surf.hpp" +#include "xbt/string.hpp" #include #include @@ -124,7 +125,7 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr xbt_edge_t edge = xbt_graph_get_edge(route_graph_, node_s_v, node_e_v); if (edge == nullptr) - THROWF(arg_error, 0, "No route from '%s' to '%s'", src->get_cname(), dst->get_cname()); + throw std::invalid_argument(xbt::string_printf("No route from '%s' to '%s'", src->get_cname(), dst->get_cname())); RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); @@ -193,7 +194,7 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr xbt_edge_t edge = xbt_graph_get_edge(route_graph_, node_pred_v, node_v); if (edge == nullptr) - THROWF(arg_error, 0, "No route from '%s' to '%s'", src->get_cname(), dst->get_cname()); + throw std::invalid_argument(xbt::string_printf("No route from '%s' to '%s'", src->get_cname(), dst->get_cname())); RouteCreationArgs* e_route = static_cast(xbt_graph_edge_get_data(edge)); @@ -265,10 +266,12 @@ void DijkstraZone::new_edge(int src_id, int dst_id, simgrid::kernel::routing::Ro // Make sure that this graph edge was not already added to the graph if (xbt_graph_get_edge(route_graph_, src, dst) != nullptr) { if (route->gw_dst == nullptr || route->gw_src == nullptr) - THROWF(arg_error, 0, "Route from %s to %s already exists", route->src->get_cname(), route->dst->get_cname()); + throw std::invalid_argument( + xbt::string_printf("Route from %s to %s already exists", route->src->get_cname(), route->dst->get_cname())); else - THROWF(arg_error, 0, "Route from %s@%s to %s@%s already exists", route->src->get_cname(), - route->gw_src->get_cname(), route->dst->get_cname(), route->gw_dst->get_cname()); + throw std::invalid_argument(xbt::string_printf("Route from %s@%s to %s@%s already exists", + route->src->get_cname(), route->gw_src->get_cname(), + route->dst->get_cname(), route->gw_dst->get_cname())); } // Finally add it diff --git a/src/kernel/routing/FloydZone.cpp b/src/kernel/routing/FloydZone.cpp index e791ece6ec..c7bb065442 100644 --- a/src/kernel/routing/FloydZone.cpp +++ b/src/kernel/routing/FloydZone.cpp @@ -8,6 +8,7 @@ #include "src/surf/network_interface.hpp" #include "src/surf/xml/platf_private.hpp" #include "surf/surf.hpp" +#include "xbt/string.hpp" #include #include @@ -57,7 +58,7 @@ void FloydZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* do { int pred = TO_FLOYD_PRED(src->id(), cur); if (pred == -1) - THROWF(arg_error, 0, "No route from '%s' to '%s'", src->get_cname(), dst->get_cname()); + throw std::invalid_argument(xbt::string_printf("No route from '%s' to '%s'", src->get_cname(), dst->get_cname())); route_stack.push_back(TO_FLOYD_LINK(pred, cur)); cur = pred; } while (cur != src->id()); diff --git a/src/simdag/sd_task.cpp b/src/simdag/sd_task.cpp index 3bdc2f063a..85cc1f390e 100644 --- a/src/simdag/sd_task.cpp +++ b/src/simdag/sd_task.cpp @@ -15,7 +15,8 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_task, sd, "Logging specific to SimDag (task)" static void __SD_task_destroy_scheduling_data(SD_task_t task) { if (task->state != SD_SCHEDULED && task->state != SD_RUNNABLE) - THROWF(arg_error, 0, "Task '%s' must be SD_SCHEDULED or SD_RUNNABLE", SD_task_get_name(task)); + throw std::invalid_argument( + simgrid::xbt::string_printf("Task '%s' must be SD_SCHEDULED or SD_RUNNABLE", SD_task_get_name(task))); xbt_free(task->flops_amount); xbt_free(task->bytes_amount); @@ -534,19 +535,21 @@ void SD_task_dotty(SD_task_t task, void *out) void SD_task_dependency_add(SD_task_t src, SD_task_t dst) { if (src == dst) - THROWF(arg_error, 0, "Cannot add a dependency between task '%s' and itself", SD_task_get_name(src)); + throw std::invalid_argument( + simgrid::xbt::string_printf("Cannot add a dependency between task '%s' and itself", SD_task_get_name(src))); if (src->state == SD_DONE || src->state == SD_FAILED) - THROWF(arg_error, 0, "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, SD_RUNNABLE, or SD_RUNNING", - src->name); + throw std::invalid_argument(simgrid::xbt::string_printf( + "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, SD_RUNNABLE, or SD_RUNNING", src->name)); if (dst->state == SD_DONE || dst->state == SD_FAILED || dst->state == SD_RUNNING) - THROWF(arg_error, 0, "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, or SD_RUNNABLE", - dst->name); + throw std::invalid_argument(simgrid::xbt::string_printf( + "Task '%s' must be SD_NOT_SCHEDULED, SD_SCHEDULABLE, SD_SCHEDULED, or SD_RUNNABLE", dst->name)); if (dst->inputs->find(src) != dst->inputs->end() || src->outputs->find(dst) != src->outputs->end() || src->successors->find(dst) != src->successors->end() || dst->predecessors->find(src) != dst->predecessors->end()) - THROWF(arg_error, 0, "A dependency already exists between task '%s' and task '%s'", src->name, dst->name); + throw std::invalid_argument(simgrid::xbt::string_printf( + "A dependency already exists between task '%s' and task '%s'", src->name, dst->name)); XBT_DEBUG("SD_task_dependency_add: src = %s, dst = %s", src->name, dst->name); @@ -607,8 +610,9 @@ void SD_task_dependency_remove(SD_task_t src, SD_task_t dst) XBT_DEBUG("SD_task_dependency_remove: src = %s, dst = %s", SD_task_get_name(src), SD_task_get_name(dst)); if (src->successors->find(dst) == src->successors->end() && src->outputs->find(dst) == src->outputs->end()) - THROWF(arg_error, 0, "No dependency found between task '%s' and '%s': task '%s' is not a successor of task '%s'", - src->name, dst->name, dst->name, src->name); + throw std::invalid_argument(simgrid::xbt::string_printf( + "No dependency found between task '%s' and '%s': task '%s' is not a successor of task '%s'", src->name, + dst->name, dst->name, src->name)); if (src->kind == SD_TASK_COMM_E2E || src->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK){ if (dst->kind == SD_TASK_COMP_SEQ || dst->kind == SD_TASK_COMP_PAR_AMDAHL) @@ -642,7 +646,7 @@ void SD_task_dependency_remove(SD_task_t src, SD_task_t dst) void SD_task_watch(SD_task_t task, e_SD_task_state_t state) { if (state & SD_NOT_SCHEDULED) - THROWF(arg_error, 0, "Cannot add a watch point for state SD_NOT_SCHEDULED"); + throw std::invalid_argument("Cannot add a watch point for state SD_NOT_SCHEDULED"); task->watch_points = task->watch_points | state; } @@ -699,7 +703,8 @@ double SD_task_get_execution_time(SD_task_t /*task*/, int host_count, const sg_h static inline void SD_task_do_schedule(SD_task_t task) { if (SD_task_get_state(task) > SD_SCHEDULABLE) - THROWF(arg_error, 0, "Task '%s' has already been scheduled", SD_task_get_name(task)); + throw std::invalid_argument( + simgrid::xbt::string_printf("Task '%s' has already been scheduled", SD_task_get_name(task))); if (task->predecessors->empty() && task->inputs->empty()) SD_task_set_state(task, SD_RUNNABLE); @@ -764,7 +769,8 @@ void SD_task_schedule(SD_task_t task, int host_count, const sg_host_t * host_lis void SD_task_unschedule(SD_task_t task) { if (task->state == SD_NOT_SCHEDULED || task->state == SD_SCHEDULABLE) - THROWF(arg_error, 0, "Task %s: the state must be SD_SCHEDULED, SD_RUNNABLE, SD_RUNNING or SD_FAILED", task->name); + throw std::invalid_argument(simgrid::xbt::string_printf( + "Task %s: the state must be SD_SCHEDULED, SD_RUNNABLE, SD_RUNNING or SD_FAILED", task->name)); if ((task->state == SD_SCHEDULED || task->state == SD_RUNNABLE) /* if the task is scheduled or runnable */ && ((task->kind == SD_TASK_COMP_PAR_AMDAHL) || (task->kind == SD_TASK_COMM_PAR_MXN_1D_BLOCK))) { diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index a78e0f4fb4..98f51cf723 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -173,8 +173,9 @@ void SIMIX_simcall_handle(smx_simcall_t simcall, int value) { case NUM_SIMCALLS: break; case SIMCALL_NONE: - THROWF(arg_error, 0, "Asked to do the noop syscall on %s@%s", simcall->issuer->get_cname(), - sg_host_get_name(simcall->issuer->get_host())); + throw std::invalid_argument(simgrid::xbt::string_printf("Asked to do the noop syscall on %s@%s", + simcall->issuer->get_cname(), + sg_host_get_name(simcall->issuer->get_host()))); default: THROW_IMPOSSIBLE; } diff --git a/src/simix/simcalls.py b/src/simix/simcalls.py index 622ae8ba3c..80fa19774b 100755 --- a/src/simix/simcalls.py +++ b/src/simix/simcalls.py @@ -354,8 +354,9 @@ if __name__ == '__main__': fd.write(' case NUM_SIMCALLS:\n') fd.write(' break;\n') fd.write(' case SIMCALL_NONE:\n') - fd.write(' THROWF(arg_error, 0, "Asked to do the noop syscall on %s@%s", simcall->issuer->get_cname(),\n') - fd.write(' sg_host_get_name(simcall->issuer->get_host()));\n') + fd.write(' throw std::invalid_argument(simgrid::xbt::string_printf("Asked to do the noop syscall on %s@%s",\n') + fd.write(' simcall->issuer->get_cname(),\n') + fd.write(' sg_host_get_name(simcall->issuer->get_host())));\n') fd.write(' default:\n') fd.write(' THROW_IMPOSSIBLE;\n') fd.write(' }\n') diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index 78196650e2..8468165933 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -125,7 +125,7 @@ void SIMIX_process_set_function(const char* process_host, const char* process_fu sg_host_t host = sg_host_by_name(process_host); if (not host) - THROWF(arg_error, 0, "Host '%s' unknown", process_host); + throw std::invalid_argument(simgrid::xbt::string_printf("Host '%s' unknown", process_host)); actor.host = process_host; actor.args.push_back(process_function); /* add arguments */ diff --git a/src/smpi/colls/allgather/allgather-2dmesh.cpp b/src/smpi/colls/allgather/allgather-2dmesh.cpp index cb7ed513fc..b6b06fcb6e 100644 --- a/src/smpi/colls/allgather/allgather-2dmesh.cpp +++ b/src/smpi/colls/allgather/allgather-2dmesh.cpp @@ -130,7 +130,7 @@ Coll_allgather_2dmesh::allgather(const void *send_buff, int send_count, MPI_Data block_size = extent * send_count; if (not is_2dmesh(num_procs, &X, &Y)) - THROWF(arg_error,0, "allgather_2dmesh algorithm can't be used with this number of processes! "); + throw std::invalid_argument("allgather_2dmesh algorithm can't be used with this number of processes!"); my_row_base = (rank / Y) * Y; my_col_base = rank % Y; diff --git a/src/smpi/colls/allgather/allgather-3dmesh.cpp b/src/smpi/colls/allgather/allgather-3dmesh.cpp index 8d99c071a8..b189670d0d 100644 --- a/src/smpi/colls/allgather/allgather-3dmesh.cpp +++ b/src/smpi/colls/allgather/allgather-3dmesh.cpp @@ -113,8 +113,7 @@ int Coll_allgather_3dmesh::allgather(const void *send_buff, int send_count, extent = send_type->get_extent(); if (not is_3dmesh(num_procs, &X, &Y, &Z)) - THROWF(arg_error,0, "allgather_3dmesh algorithm can't be used with this number of processes! "); - + throw std::invalid_argument("allgather_3dmesh algorithm can't be used with this number of processes!"); num_reqs = X; diff --git a/src/smpi/colls/allgather/allgather-SMP-NTS.cpp b/src/smpi/colls/allgather/allgather-SMP-NTS.cpp index 0e4e3dba1c..cb1acffd89 100644 --- a/src/smpi/colls/allgather/allgather-SMP-NTS.cpp +++ b/src/smpi/colls/allgather/allgather-SMP-NTS.cpp @@ -41,7 +41,8 @@ int Coll_allgather_SMP_NTS::allgather(const void *sbuf, int scount, int num_core_in_current_smp = num_core; if(comm_size%num_core) - THROWF(arg_error,0, "allgather SMP NTS algorithm can't be used with non multiple of NUM_CORE=%d number of processes ! ", num_core); + throw std::invalid_argument(xbt::string_printf( + "allgather SMP NTS algorithm can't be used with non multiple of NUM_CORE=%d number of processes!", num_core)); /* for too small number of processes, use default implementation */ if (comm_size <= num_core) { diff --git a/src/smpi/colls/allgather/allgather-loosely-lr.cpp b/src/smpi/colls/allgather/allgather-loosely-lr.cpp index 3da2263999..5596db8867 100644 --- a/src/smpi/colls/allgather/allgather-loosely-lr.cpp +++ b/src/smpi/colls/allgather/allgather-loosely-lr.cpp @@ -32,7 +32,9 @@ if(comm->get_leaders_comm()==MPI_COMM_NULL){ } if(comm_size%num_core) - THROWF(arg_error,0, "allgather loosely lr algorithm can't be used with non multiple of NUM_CORE=%d number of processes ! ",num_core); + throw std::invalid_argument(xbt::string_printf( + "allgather loosely lr algorithm can't be used with non multiple of NUM_CORE=%d number of processes!", + num_core)); rank = comm->rank(); MPI_Aint rextent, sextent; diff --git a/src/smpi/colls/allgather/allgather-mvapich-smp.cpp b/src/smpi/colls/allgather/allgather-mvapich-smp.cpp index 993efeafe6..1a73c48f8b 100644 --- a/src/smpi/colls/allgather/allgather-mvapich-smp.cpp +++ b/src/smpi/colls/allgather/allgather-mvapich-smp.cpp @@ -54,10 +54,12 @@ int Coll_allgather_mvapich2_smp::allgather(const void *sendbuf,int sendcnt, MPI_ } if (not comm->is_uniform() || not comm->is_blocked()) - THROWF(arg_error,0, "allgather MVAPICH2 smp algorithm can't be used with irregular deployment. Please insure that processes deployed on the same node are contiguous and that each node has the same number of processes"); + throw std::invalid_argument("allgather MVAPICH2 smp algorithm can't be used with irregular deployment. Please " + "insure that processes deployed on the same node are contiguous and that each node has " + "the same number of processes"); - if (recvcnt == 0) { - return MPI_SUCCESS; + if (recvcnt == 0) { + return MPI_SUCCESS; } rank = comm->rank(); diff --git a/src/smpi/colls/allgather/allgather-pair.cpp b/src/smpi/colls/allgather/allgather-pair.cpp index 7f0ec36bfa..5794d95fd8 100644 --- a/src/smpi/colls/allgather/allgather-pair.cpp +++ b/src/smpi/colls/allgather/allgather-pair.cpp @@ -88,7 +88,7 @@ Coll_allgather_pair::allgather(const void *send_buff, int send_count, unsigned int num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "allgather pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("allgather pair algorithm can't be used with non power of two number of processes!"); extent = send_type->get_extent(); diff --git a/src/smpi/colls/allgather/allgather-rhv.cpp b/src/smpi/colls/allgather/allgather-rhv.cpp index bcbb4d1cd3..9673350aac 100644 --- a/src/smpi/colls/allgather/allgather-rhv.cpp +++ b/src/smpi/colls/allgather/allgather-rhv.cpp @@ -32,7 +32,7 @@ Coll_allgather_rhv::allgather(const void *sbuf, int send_count, unsigned int num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "allgather rhv algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("allgather rhv algorithm can't be used with non power of two number of processes!"); unsigned int rank = comm->rank(); diff --git a/src/smpi/colls/allgather/allgather-smp-simple.cpp b/src/smpi/colls/allgather/allgather-smp-simple.cpp index dcaaecd19e..c11d643ba4 100644 --- a/src/smpi/colls/allgather/allgather-smp-simple.cpp +++ b/src/smpi/colls/allgather/allgather-smp-simple.cpp @@ -27,7 +27,9 @@ int Coll_allgather_smp_simple::allgather(const void *send_buf, int scount, } if(comm_size%num_core) - THROWF(arg_error,0, "allgather SMP simple algorithm can't be used with non multiple of NUM_CORE=%d number of processes ! ", num_core); + throw std::invalid_argument(xbt::string_printf( + "allgather SMP simple algorithm can't be used with non multiple of NUM_CORE=%d number of processes!", + num_core)); rank = comm->rank(); MPI_Aint rextent, sextent; diff --git a/src/smpi/colls/allgatherv/allgatherv-pair.cpp b/src/smpi/colls/allgatherv/allgatherv-pair.cpp index f066747815..1e490a8d58 100644 --- a/src/smpi/colls/allgatherv/allgatherv-pair.cpp +++ b/src/smpi/colls/allgatherv/allgatherv-pair.cpp @@ -87,7 +87,7 @@ Coll_allgatherv_pair::allgatherv(const void *send_buff, int send_count, unsigned int num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "allgatherv pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("allgatherv pair algorithm can't be used with non power of two number of processes!"); extent = send_type->get_extent(); diff --git a/src/smpi/colls/allreduce/allreduce-rab1.cpp b/src/smpi/colls/allreduce/allreduce-rab1.cpp index e5ff57aaca..34be1cdfeb 100644 --- a/src/smpi/colls/allreduce/allreduce-rab1.cpp +++ b/src/smpi/colls/allreduce/allreduce-rab1.cpp @@ -23,7 +23,7 @@ int Coll_allreduce_rab1::allreduce(const void *sbuff, void *rbuff, unsigned int nprocs = comm->size(); if((nprocs&(nprocs-1))) - THROWF(arg_error,0, "allreduce rab1 algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("allreduce rab1 algorithm can't be used with non power of two number of processes!"); extent = dtype->get_extent(); diff --git a/src/smpi/colls/allreduce/allreduce-smp-rsag-rab.cpp b/src/smpi/colls/allreduce/allreduce-smp-rsag-rab.cpp index ad9c9bdfc9..b4bfaccd42 100644 --- a/src/smpi/colls/allreduce/allreduce-smp-rsag-rab.cpp +++ b/src/smpi/colls/allreduce/allreduce-smp-rsag-rab.cpp @@ -39,7 +39,8 @@ int Coll_allreduce_smp_rsag_rab::allreduce(const void *sbuf, void *rbuf, int cou comm_size = comm->size(); if((comm_size&(comm_size-1))) - THROWF(arg_error,0, "allreduce smp rsag rab algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument( + "allreduce smp rsag rab algorithm can't be used with non power of two number of processes!"); rank = comm->rank(); MPI_Aint extent; diff --git a/src/smpi/colls/alltoall/alltoall-pair-light-barrier.cpp b/src/smpi/colls/alltoall/alltoall-pair-light-barrier.cpp index 34e2897394..35bc2933db 100644 --- a/src/smpi/colls/alltoall/alltoall-pair-light-barrier.cpp +++ b/src/smpi/colls/alltoall/alltoall-pair-light-barrier.cpp @@ -49,7 +49,7 @@ Coll_alltoall_pair_light_barrier::alltoall(const void *send_buff, int send_count num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "alltoall pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("alltoall pair algorithm can't be used with non power of two number of processes!"); send_chunk = send_type->get_extent(); recv_chunk = recv_type->get_extent(); diff --git a/src/smpi/colls/alltoall/alltoall-pair-mpi-barrier.cpp b/src/smpi/colls/alltoall/alltoall-pair-mpi-barrier.cpp index 2c40264a8a..2e9e926e59 100644 --- a/src/smpi/colls/alltoall/alltoall-pair-mpi-barrier.cpp +++ b/src/smpi/colls/alltoall/alltoall-pair-mpi-barrier.cpp @@ -46,7 +46,7 @@ Coll_alltoall_pair_mpi_barrier::alltoall(const void *send_buff, int send_count, num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "alltoall pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("alltoall pair algorithm can't be used with non power of two number of processes!"); send_chunk = send_type->get_extent(); recv_chunk = recv_type->get_extent(); diff --git a/src/smpi/colls/alltoall/alltoall-pair-one-barrier.cpp b/src/smpi/colls/alltoall/alltoall-pair-one-barrier.cpp index d626bab949..b427fca19b 100644 --- a/src/smpi/colls/alltoall/alltoall-pair-one-barrier.cpp +++ b/src/smpi/colls/alltoall/alltoall-pair-one-barrier.cpp @@ -47,7 +47,7 @@ Coll_alltoall_pair_one_barrier::alltoall(const void *send_buff, int send_count, num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "alltoall pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("alltoall pair algorithm can't be used with non power of two number of processes!"); send_chunk = send_type->get_extent(); recv_chunk = recv_type->get_extent(); diff --git a/src/smpi/colls/alltoall/alltoall-pair.cpp b/src/smpi/colls/alltoall/alltoall-pair.cpp index 652a40ef9b..bd1095d820 100644 --- a/src/smpi/colls/alltoall/alltoall-pair.cpp +++ b/src/smpi/colls/alltoall/alltoall-pair.cpp @@ -81,7 +81,7 @@ int Coll_alltoall_pair::alltoall(const void *send_buff, int send_count, num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "alltoall pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("alltoall pair algorithm can't be used with non power of two number of processes!"); send_chunk = send_type->get_extent(); recv_chunk = recv_type->get_extent(); diff --git a/src/smpi/colls/alltoallv/alltoallv-pair-light-barrier.cpp b/src/smpi/colls/alltoallv/alltoallv-pair-light-barrier.cpp index f171d0f103..b5d4073a25 100644 --- a/src/smpi/colls/alltoallv/alltoallv-pair-light-barrier.cpp +++ b/src/smpi/colls/alltoallv/alltoallv-pair-light-barrier.cpp @@ -49,7 +49,7 @@ Coll_alltoallv_pair_light_barrier::alltoallv(const void *send_buff, const int *s num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "alltoallv pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("alltoallv pair algorithm can't be used with non power of two number of processes!"); send_chunk = send_type->get_extent(); recv_chunk = recv_type->get_extent(); diff --git a/src/smpi/colls/alltoallv/alltoallv-pair-mpi-barrier.cpp b/src/smpi/colls/alltoallv/alltoallv-pair-mpi-barrier.cpp index 2055ef1a2f..d942226807 100644 --- a/src/smpi/colls/alltoallv/alltoallv-pair-mpi-barrier.cpp +++ b/src/smpi/colls/alltoallv/alltoallv-pair-mpi-barrier.cpp @@ -46,7 +46,7 @@ Coll_alltoallv_pair_mpi_barrier::alltoallv(const void *send_buff, const int *sen num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "alltoallv pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("alltoallv pair algorithm can't be used with non power of two number of processes!"); send_chunk = send_type->get_extent(); recv_chunk = recv_type->get_extent(); diff --git a/src/smpi/colls/alltoallv/alltoallv-pair-one-barrier.cpp b/src/smpi/colls/alltoallv/alltoallv-pair-one-barrier.cpp index dd5b2f7eb6..f2298f4faf 100644 --- a/src/smpi/colls/alltoallv/alltoallv-pair-one-barrier.cpp +++ b/src/smpi/colls/alltoallv/alltoallv-pair-one-barrier.cpp @@ -46,7 +46,7 @@ Coll_alltoallv_pair_one_barrier::alltoallv(const void *send_buff, const int *sen num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "alltoallv pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("alltoallv pair algorithm can't be used with non power of two number of processes!"); send_chunk = send_type->get_extent(); recv_chunk = recv_type->get_extent(); diff --git a/src/smpi/colls/alltoallv/alltoallv-pair.cpp b/src/smpi/colls/alltoallv/alltoallv-pair.cpp index c3ed962e2c..8dfd02f79d 100644 --- a/src/smpi/colls/alltoallv/alltoallv-pair.cpp +++ b/src/smpi/colls/alltoallv/alltoallv-pair.cpp @@ -46,7 +46,7 @@ int Coll_alltoallv_pair::alltoallv(const void *send_buff, const int *send_counts num_procs = comm->size(); if((num_procs&(num_procs-1))) - THROWF(arg_error,0, "alltoallv pair algorithm can't be used with non power of two number of processes ! "); + throw std::invalid_argument("alltoallv pair algorithm can't be used with non power of two number of processes!"); send_chunk = send_type->get_extent(); recv_chunk = recv_type->get_extent(); diff --git a/src/smpi/colls/reduce/reduce-rab.cpp b/src/smpi/colls/reduce/reduce-rab.cpp index 584ffd8823..351979c61b 100644 --- a/src/smpi/colls/reduce/reduce-rab.cpp +++ b/src/smpi/colls/reduce/reduce-rab.cpp @@ -540,7 +540,7 @@ static int MPI_I_anyReduce(const void* Sendbuf, void* Recvbuf, int count, MPI_Da else if(mpi_datatype==MPI_DOUBLE ) datatype=MPIM_DOUBLE; else if(mpi_datatype==MPI_BYTE ) datatype=MPIM_BYTE; else - THROWF(arg_error,0, "reduce rab algorithm can't be used with this datatype ! "); + throw std::invalid_argument("reduce rab algorithm can't be used with this datatype!"); if (mpi_op==MPI_MAX ) op=MPIM_MAX; else if(mpi_op==MPI_MIN ) op=MPIM_MIN; diff --git a/src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp b/src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp index 6594111219..905d637ccc 100644 --- a/src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp +++ b/src/smpi/colls/reduce_scatter/reduce_scatter-ompi.cpp @@ -63,7 +63,8 @@ Coll_reduce_scatter_ompi_basic_recursivehalving::reduce_scatter(const void *sbuf XBT_DEBUG("coll:tuned:reduce_scatter_ompi_basic_recursivehalving, rank %d", rank); if ((op != MPI_OP_NULL && not op->is_commutative())) - THROWF(arg_error,0, " reduce_scatter ompi_basic_recursivehalving can only be used for commutative operations! "); + throw std::invalid_argument( + "reduce_scatter ompi_basic_recursivehalving can only be used for commutative operations!"); /* Find displacements and the like */ int* disps = new int[size]; diff --git a/src/xbt/log.cpp b/src/xbt/log.cpp index ec4939dfd0..a72858e6ac 100644 --- a/src/xbt/log.cpp +++ b/src/xbt/log.cpp @@ -5,11 +5,12 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "src/xbt_modinter.h" #include "src/xbt/log_private.hpp" +#include "src/xbt_modinter.h" #include "xbt/asserts.h" #include "xbt/dynar.h" #include "xbt/str.h" +#include "xbt/string.hpp" #include #include @@ -405,8 +406,8 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) }else if (i < xbt_log_priority_infinite) { set.thresh = (e_xbt_log_priority_t)i; } else { - THROWF(arg_error, 0, - "Unknown priority name: %s (must be one of: trace,debug,verbose,info,warning,error,critical)", value); + throw std::invalid_argument(simgrid::xbt::string_printf( + "Unknown priority name: %s (must be one of: trace,debug,verbose,info,warning,error,critical)", value)); } } else if (strncmp(option, "additivity", option_len) == 0) { set.additivity = (strcasecmp(value, "ON") == 0 || strcasecmp(value, "YES") == 0 || strcmp(value, "1") == 0); @@ -422,7 +423,7 @@ static xbt_log_setting_t _xbt_log_parse_setting(const char *control_string) } else if (strcmp(value, "stdout") == 0) { set.appender = xbt_log_appender_stream(stdout); } else { - THROWF(arg_error, 0, "Unknown appender log type: '%s'", value); + throw std::invalid_argument(simgrid::xbt::string_printf("Unknown appender log type: '%s'", value)); } } else if (strncmp(option, "fmt", option_len) == 0) { set.fmt = std::string(value); diff --git a/src/xbt/xbt_str.cpp b/src/xbt/xbt_str.cpp index bfaeff97ac..b38ad7dbe3 100644 --- a/src/xbt/xbt_str.cpp +++ b/src/xbt/xbt_str.cpp @@ -8,6 +8,7 @@ #include "simgrid/Exception.hpp" #include "xbt/misc.h" #include "xbt/str.h" /* headers of these functions */ +#include "xbt/string.hpp" /** @brief Splits a string into a dynar of strings * @@ -101,7 +102,7 @@ xbt_dynar_t xbt_str_split_quoted_in_place(char *s) { /* Protected char; move it closer */ memmove(end, end + 1, strlen(end)); if (*end == '\0') - THROWF(arg_error, 0, "String ends with \\"); + throw std::invalid_argument("String ends with \\"); end++; /* Pass the protected char */ break; case '\'': @@ -129,7 +130,8 @@ xbt_dynar_t xbt_str_split_quoted_in_place(char *s) { case '\n': case '\0': if (*end == '\0' && (in_simple_quote || in_double_quote)) { - THROWF(arg_error, 0, "End of string found while searching for %c in %s", (in_simple_quote ? '\'' : '"'), s); + throw std::invalid_argument(simgrid::xbt::string_printf("End of string found while searching for %c in %s", + (in_simple_quote ? '\'' : '"'), s)); } if (in_simple_quote || in_double_quote) { end++; @@ -195,17 +197,17 @@ xbt_dynar_t xbt_str_split_quoted(const char *s) /** @brief Parse an integer out of a string, or raise an error * * The @a str is passed as argument to your @a error_msg, as follows: - * @verbatim THROWF(arg_error, 0, error_msg, str); @endverbatim + * @verbatim throw std::invalid_argument(simgrid::xbt::string_printf(error_msg, str)); @endverbatim */ long int xbt_str_parse_int(const char* str, const char* error_msg) { char* endptr; if (str == nullptr || str[0] == '\0') - THROWF(arg_error, 0, error_msg, str); + throw std::invalid_argument(simgrid::xbt::string_printf(error_msg, str)); long int res = strtol(str, &endptr, 10); if (endptr[0] != '\0') - THROWF(arg_error, 0, error_msg, str); + throw std::invalid_argument(simgrid::xbt::string_printf(error_msg, str)); return res; } @@ -213,17 +215,17 @@ long int xbt_str_parse_int(const char* str, const char* error_msg) /** @brief Parse a double out of a string, or raise an error * * The @a str is passed as argument to your @a error_msg, as follows: - * @verbatim THROWF(arg_error, 0, error_msg, str); @endverbatim + * @verbatim throw std::invalid_argument(simgrid::xbt::string_printf(error_msg, str)); @endverbatim */ double xbt_str_parse_double(const char* str, const char* error_msg) { char *endptr; if (str == nullptr || str[0] == '\0') - THROWF(arg_error, 0, error_msg, str); + throw std::invalid_argument(simgrid::xbt::string_printf(error_msg, str)); double res = strtod(str, &endptr); if (endptr[0] != '\0') - THROWF(arg_error, 0, error_msg, str); + throw std::invalid_argument(simgrid::xbt::string_printf(error_msg, str)); return res; } diff --git a/src/xbt/xbt_str_test.cpp b/src/xbt/xbt_str_test.cpp index 48fe51b93f..e1e76005ab 100644 --- a/src/xbt/xbt_str_test.cpp +++ b/src/xbt/xbt_str_test.cpp @@ -29,9 +29,7 @@ void test_split_quoted(const std::string& name, const char* input, const std::ve template void test_parse_error(F function, const std::string& name, const char* str) { INFO(name); - REQUIRE_THROWS_MATCHES(function(str, "Parse error"), xbt_ex, - Catch::Matchers::Predicate([](xbt_ex const& e) { return e.category == arg_error; }, - "category arg_error")); + REQUIRE_THROWS_AS(function(str, "Parse error"), std::invalid_argument); } template void test_parse_ok(F function, const std::string& name, const char* str, T value) -- 2.20.1