From: Martin Quinson Date: Fri, 2 Sep 2016 09:31:29 +0000 (+0200) Subject: Merge pull request #112 from glesserd/teshpy X-Git-Tag: v3_14~449^2~1 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/5701d7115728d762aca64528918880f897acb72a?hp=de5cdc6a63bc60f95f74f5bdc348679d2426c26b Merge pull request #112 from glesserd/teshpy Replace tesh.pl by tesh.py --- diff --git a/.travis.yml b/.travis.yml index 7f83eace1b..db60ae1665 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,6 +45,7 @@ addons: # Still need sudo for update-alternatives script: + - sudo pip install subprocess32 # needed by tesh - cmake -Denable_documentation=OFF -Denable_coverage=OFF -Denable_java=ON -Denable_model-checking=OFF -Denable_lua=OFF -Denable_compile_optimizations=OFF -Denable_smpi=ON -Denable_smpi_MPICH3_testsuite=OFF -Denable_compile_warnings=ON . # run make in the sonar wrapper && run the tests only if the build suceeded - ./tools/internal/travis-sonarqube.sh make VERBOSE=1 && ctest --output-on-failure --timeout 100 diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index d1c103a933..a765cd4261 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -205,7 +205,6 @@ XBT_PUBLIC(void) SIMIX_process_detach(); /*********************************** Host *************************************/ XBT_PUBLIC(sg_host_t) SIMIX_host_self(); XBT_PUBLIC(const char*) SIMIX_host_self_get_name(); -XBT_PUBLIC(void) SIMIX_host_on(sg_host_t host); XBT_PUBLIC(void) SIMIX_host_off(sg_host_t host, smx_actor_t issuer); XBT_PUBLIC(void) SIMIX_host_self_set_data(void *data); XBT_PUBLIC(void*) SIMIX_host_self_get_data(); diff --git a/src/s4u/s4u_host.cpp b/src/s4u/s4u_host.cpp index a75aea9657..d38b8e03f2 100644 --- a/src/s4u/s4u_host.cpp +++ b/src/s4u/s4u_host.cpp @@ -75,11 +75,18 @@ Host *Host::current(){ } void Host::turnOn() { - simgrid::simix::kernelImmediate(std::bind(SIMIX_host_on, this)); + if (isOff()) { + simgrid::simix::kernelImmediate([&]{ + this->extension()->turnOn(); + this->extension()->turnOn(); + }); + } } void Host::turnOff() { - simgrid::simix::kernelImmediate(std::bind(SIMIX_host_off, this, SIMIX_process_self())); + if (isOn()) { + simgrid::simix::kernelImmediate(std::bind(SIMIX_host_off, this, SIMIX_process_self())); + } } bool Host::isOn() { diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index f27e7accb6..3eb47dcbf0 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -50,46 +50,40 @@ namespace simgrid { xbt_dynar_free(&boot_processes); xbt_swag_free(process_list); } - } -} - -/** @brief Start the host if it is off */ -void SIMIX_host_on(sg_host_t h) -{ - smx_host_priv_t host = sg_host_simix(h); - - xbt_assert((host != nullptr), "Invalid parameters"); - if (h->isOff()) { - simgrid::surf::HostImpl* surf_host = h->extension(); - surf_host->turnOn(); - - unsigned int cpt; - smx_process_arg_t arg; - xbt_dynar_foreach(host->boot_processes,cpt,arg) { - XBT_DEBUG("Booting Process %s(%s) right now", - arg->name.c_str(), arg->hostname); - if (simix_global->create_process_function) { - simix_global->create_process_function(arg->name.c_str(), - arg->code, - nullptr, - arg->hostname, - arg->kill_time, - arg->properties, - arg->auto_restart, - nullptr); - } else { - simcall_process_create(arg->name.c_str(), - arg->code, - nullptr, - arg->hostname, - arg->kill_time, - arg->properties, - arg->auto_restart); + /** Re-starts all the actors that are marked as restartable. + * + * Weird things will happen if you turn on an host that is already on. S4U is fool-proof, not this. + */ + void Host::turnOn() + { + unsigned int cpt; + smx_process_arg_t arg; + xbt_dynar_foreach(boot_processes,cpt,arg) { + XBT_DEBUG("Booting Process %s(%s) right now", arg->name.c_str(), arg->hostname); + // FIXME: factorize this code by registering the simcall as default function + if (simix_global->create_process_function) { + simix_global->create_process_function(arg->name.c_str(), + arg->code, + nullptr, + arg->hostname, + arg->kill_time, + arg->properties, + arg->auto_restart, + nullptr); + } else { + simcall_process_create(arg->name.c_str(), + arg->code, + nullptr, + arg->hostname, + arg->kill_time, + arg->properties, + arg->auto_restart); + } } } - } -} + +}} // namespaces /** @brief Stop the host if it is on */ void SIMIX_host_off(sg_host_t h, smx_actor_t issuer) diff --git a/src/simix/smx_host_private.h b/src/simix/smx_host_private.h index 5cfdd36b5b..38992feef3 100644 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@ -32,6 +32,8 @@ namespace simgrid { xbt_swag_t process_list; xbt_dynar_t auto_restart_processes = nullptr; xbt_dynar_t boot_processes = nullptr; + + void turnOn(); }; } } diff --git a/src/smpi/smpi_base.cpp b/src/smpi/smpi_base.cpp index 61e473c183..bd20dacbc0 100644 --- a/src/smpi/smpi_base.cpp +++ b/src/smpi/smpi_base.cpp @@ -156,7 +156,7 @@ static double smpi_os(size_t size) // Iterate over all the sections that were specified and find the right // value. (fact.factor represents the interval sizes; we want to find the // section that has fact.factor <= size and no other such fact.factor <= size) - // Note: parse_factor() (used before) already sorts the dynar we iterate over! + // Note: parse_factor() (used before) already sorts the vector we iterate over! for (auto& fact : smpi_os_values) { if (size <= fact.factor) { // Values already too large, use the previously // computed value of current! @@ -181,7 +181,7 @@ static double smpi_ois(size_t size) double current=smpi_ois_values.empty()?0.0:smpi_ois_values[0].values[0]+smpi_ois_values[0].values[1]*size; // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size) - // Note: parse_factor() (used before) already sorts the dynar we iterate over! + // Note: parse_factor() (used before) already sorts the vector we iterate over! for (auto& fact : smpi_ois_values) { if (size <= fact.factor) { // Values already too large, use the previously computed value of current! XBT_DEBUG("ois : %zu <= %zu return %.10f", size, fact.factor, current); @@ -207,10 +207,9 @@ static double smpi_or(size_t size) // Iterate over all the sections that were specified and find the right value. (fact.factor represents the interval // sizes; we want to find the section that has fact.factor <= size and no other such fact.factor <= size) - // Note: parse_factor() (used before) already sorts the dynar we iterate over! + // Note: parse_factor() (used before) already sorts the vector we iterate over! for (auto fact : smpi_or_values) { - if (size <= fact.factor) { // Values already too large, use the previously - // computed value of current! + if (size <= fact.factor) { // Values already too large, use the previously computed value of current! XBT_DEBUG("or : %zu <= %zu return %.10f", size, fact.factor, current); return current; } else { @@ -231,9 +230,7 @@ void smpi_mpi_init() { double smpi_mpi_wtime(){ double time; - if (smpi_process_initialized() != 0 && - smpi_process_finalized() == 0 && - smpi_process_get_sampling() == 0) { + if (smpi_process_initialized() != 0 && smpi_process_finalized() == 0 && smpi_process_get_sampling() == 0) { smpi_bench_end(); time = SIMIX_get_clock(); // to avoid deadlocks if used as a break condition, such as @@ -820,8 +817,7 @@ int smpi_mpi_testall(int count, MPI_Request requests[], MPI_Status status[]) MPI_Status stat; MPI_Status *pstat = status == MPI_STATUSES_IGNORE ? MPI_STATUS_IGNORE : &stat; int flag=1; - int i; - for(i=0; iflags & PREPARED)) { if (smpi_mpi_test(&requests[i], pstat)!=1){ flag=0; @@ -1242,12 +1238,13 @@ void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm) { int system_tag = COLL_TAG_SCATTER; - int rank, size, dst, index; - MPI_Aint lb = 0, sendext = 0; + int dst; + MPI_Aint lb = 0; + MPI_Aint sendext = 0; MPI_Request *requests; - rank = smpi_comm_rank(comm); - size = smpi_comm_size(comm); + int rank = smpi_comm_rank(comm); + int size = smpi_comm_size(comm); if(rank != root) { // Recv buffer from root smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm, MPI_STATUS_IGNORE); @@ -1260,7 +1257,7 @@ void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype, } // Send buffers to receivers requests = xbt_new(MPI_Request, size - 1); - index = 0; + int index = 0; for(dst = 0; dst < size; dst++) { if(dst != root) { requests[index] = smpi_isend_init(static_cast(sendbuf) + dst * sendcount * sendext, sendcount, sendtype, dst, @@ -1282,12 +1279,13 @@ void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs, MPI_Datatype MPI_Datatype recvtype, int root, MPI_Comm comm) { int system_tag = COLL_TAG_SCATTERV; - int rank, size, dst, index; - MPI_Aint lb = 0, sendext = 0; + int dst; + MPI_Aint lb = 0; + MPI_Aint sendext = 0; MPI_Request *requests; - rank = smpi_comm_rank(comm); - size = smpi_comm_size(comm); + int rank = smpi_comm_rank(comm); + int size = smpi_comm_size(comm); if(rank != root) { // Recv buffer from root smpi_mpi_recv(recvbuf, recvcount, recvtype, root, system_tag, comm, MPI_STATUS_IGNORE); @@ -1300,7 +1298,7 @@ void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs, MPI_Datatype } // Send buffers to receivers requests = xbt_new(MPI_Request, size - 1); - index = 0; + int index = 0; for(dst = 0; dst < size; dst++) { if(dst != root) { requests[index] = smpi_isend_init(static_cast(sendbuf) + displs[dst] * sendext, sendcounts[dst], @@ -1322,16 +1320,16 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat MPI_Comm comm) { int system_tag = COLL_TAG_REDUCE; - int rank, size, src, index; - MPI_Aint lb = 0, dataext = 0; + int src, index; + MPI_Aint lb = 0; + MPI_Aint dataext = 0; MPI_Request *requests; void **tmpbufs; char* sendtmpbuf = static_cast(sendbuf); - - rank = smpi_comm_rank(comm); - size = smpi_comm_size(comm); + int rank = smpi_comm_rank(comm); + int size = smpi_comm_size(comm); //non commutative case, use a working algo from openmpi if(!smpi_op_is_commute(op)){ smpi_coll_tuned_reduce_ompi_basic_linear(sendtmpbuf, recvbuf, count, datatype, op, root, comm); @@ -1400,13 +1398,13 @@ void smpi_mpi_allreduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype da void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { int system_tag = -888; - int rank, size, other, index; + int other, index; MPI_Aint lb = 0, dataext = 0; MPI_Request *requests; void **tmpbufs; - rank = smpi_comm_rank(comm); - size = smpi_comm_size(comm); + int rank = smpi_comm_rank(comm); + int size = smpi_comm_size(comm); smpi_datatype_extent(datatype, &lb, &dataext); @@ -1462,13 +1460,13 @@ void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatyp void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm) { int system_tag = -888; - int rank, size, other, index; + int other, index; MPI_Aint lb = 0, dataext = 0; MPI_Request *requests; void **tmpbufs; int recvbuf_is_empty=1; - rank = smpi_comm_rank(comm); - size = smpi_comm_size(comm); + int rank = smpi_comm_rank(comm); + int size = smpi_comm_size(comm); smpi_datatype_extent(datatype, &lb, &dataext); @@ -1478,13 +1476,11 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat index = 0; for(other = 0; other < rank; other++) { tmpbufs[index] = smpi_get_tmp_sendbuffer(count * dataext); - requests[index] = - smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag, comm); + requests[index] = smpi_irecv_init(tmpbufs[index], count, datatype, other, system_tag, comm); index++; } for(other = rank + 1; other < size; other++) { - requests[index] = - smpi_isend_init(sendbuf, count, datatype, other, system_tag, comm); + requests[index] = smpi_isend_init(sendbuf, count, datatype, other, system_tag, comm); index++; } // Wait for completion of all comms. @@ -1499,9 +1495,9 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat if(recvbuf_is_empty){ smpi_datatype_copy(tmpbufs[index], count, datatype, recvbuf, count, datatype); recvbuf_is_empty=0; - }else - // #Request is below rank: it's a irecv - smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype); + } else + // #Request is below rank: it's a irecv + smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype); } } }else{ @@ -1512,7 +1508,8 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat if(recvbuf_is_empty){ smpi_datatype_copy(tmpbufs[other], count, datatype, recvbuf, count, datatype); recvbuf_is_empty=0; - }else smpi_op_apply(op, tmpbufs[other], recvbuf, &count, &datatype); + } else + smpi_op_apply(op, tmpbufs[other], recvbuf, &count, &datatype); } } } diff --git a/src/smpi/smpi_coll.cpp b/src/smpi/smpi_coll.cpp index 26b1f4704c..e6fae05f0e 100644 --- a/src/smpi/smpi_coll.cpp +++ b/src/smpi/smpi_coll.cpp @@ -91,9 +91,8 @@ int find_coll_description(s_mpi_coll_description_t * table, char *name, const ch if(selector_on){ // collective seems not handled by the active selector, try with default one - name=const_cast("default"); for (int i = 0; table[i].name; i++) - if (!strcmp(name, table[i].name)) { + if (!strcmp("default", table[i].name)) { return i; } } diff --git a/src/smpi/smpi_replay.cpp b/src/smpi/smpi_replay.cpp index 08e9998dad..149ec5fd31 100644 --- a/src/smpi/smpi_replay.cpp +++ b/src/smpi/smpi_replay.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #define KEY_SIZE (sizeof(int) * 2 + 1) @@ -15,7 +17,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_replay,smpi,"Trace Replay with SMPI"); int communicator_size = 0; static int active_processes = 0; -xbt_dict_t reqq = nullptr; +std::unordered_map*> reqq; MPI_Datatype MPI_DEFAULT_TYPE; MPI_Datatype MPI_CURRENT_TYPE; @@ -33,20 +35,14 @@ static void log_timed_action (const char *const *action, double clock){ } } -static xbt_dynar_t get_reqq_self() +static std::vector* get_reqq_self() { - char * key = bprintf("%d", smpi_process_index()); - xbt_dynar_t dynar_mpi_request = static_cast(xbt_dict_get(reqq, key)); - xbt_free(key); - - return dynar_mpi_request; + return reqq.at(smpi_process_index()); } -static void set_reqq_self(xbt_dynar_t mpi_request) +static void set_reqq_self(std::vector *mpi_request) { - char * key = bprintf("%d", smpi_process_index()); - xbt_dict_set(reqq, key, mpi_request, free); - xbt_free(key); + reqq.insert({smpi_process_index(), mpi_request}); } //allocate a single buffer for all sends, growing it if needed @@ -173,11 +169,7 @@ static void action_init(const char *const *action) /*initialize the number of active processes */ active_processes = smpi_process_count(); - if (reqq==nullptr) { - reqq = xbt_dict_new(); - } - - set_reqq_self(xbt_dynar_new(sizeof(MPI_Request),&xbt_free_ref)); + set_reqq_self(new std::vector); } static void action_finalize(const char *const *action) @@ -288,7 +280,7 @@ static void action_Isend(const char *const *action) TRACE_smpi_ptp_out(rank, rank, dst_traced, __FUNCTION__); request->send = 1; - xbt_dynar_push(get_reqq_self(),&request); + get_reqq_self()->push_back(request); log_timed_action (action, clock); } @@ -316,10 +308,10 @@ static void action_recv(const char *const *action) { extra->datatype1 = encode_datatype(MPI_CURRENT_TYPE, nullptr); TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, extra); - //unknow size from the receiver pov + //unknown size from the receiver point of view if(size<=0.0){ - smpi_mpi_probe(from, 0, MPI_COMM_WORLD, &status); - size=status.count; + smpi_mpi_probe(from, 0, MPI_COMM_WORLD, &status); + size=status.count; } smpi_mpi_recv(nullptr, size, MPI_CURRENT_TYPE, from, 0, MPI_COMM_WORLD, &status); @@ -365,7 +357,7 @@ static void action_Irecv(const char *const *action) TRACE_smpi_ptp_out(rank, src_traced, rank, __FUNCTION__); request->recv = 1; - xbt_dynar_push(get_reqq_self(),&request); + get_reqq_self()->push_back(request); log_timed_action (action, clock); } @@ -373,11 +365,11 @@ static void action_Irecv(const char *const *action) static void action_test(const char *const *action){ CHECK_ACTION_PARAMS(action, 0, 0) double clock = smpi_process_simulated_elapsed(); - MPI_Request request; MPI_Status status; int flag = true; - request = xbt_dynar_pop_as(get_reqq_self(),MPI_Request); + MPI_Request request = get_reqq_self()->back(); + get_reqq_self()->pop_back(); //if request is null here, this may mean that a previous test has succeeded //Different times in traced application and replayed version may lead to this //In this case, ignore the extra calls. @@ -390,8 +382,8 @@ static void action_test(const char *const *action){ flag = smpi_mpi_test(&request, &status); XBT_DEBUG("MPI_Test result: %d", flag); - /* push back request in dynar to be caught by a subsequent wait. if the test did succeed, the request is now nullptr.*/ - xbt_dynar_push_as(get_reqq_self(),MPI_Request, request); + /* push back request in vector to be caught by a subsequent wait. if the test did succeed, the request is now nullptr.*/ + get_reqq_self()->push_back(request); TRACE_smpi_testing_out(rank); } @@ -401,13 +393,12 @@ static void action_test(const char *const *action){ static void action_wait(const char *const *action){ CHECK_ACTION_PARAMS(action, 0, 0) double clock = smpi_process_simulated_elapsed(); - MPI_Request request; MPI_Status status; - xbt_assert(xbt_dynar_length(get_reqq_self()), - "action wait not preceded by any irecv or isend: %s", + xbt_assert(get_reqq_self()->size(), "action wait not preceded by any irecv or isend: %s", xbt_str_join_array(action," ")); - request = xbt_dynar_pop_as(get_reqq_self(),MPI_Request); + MPI_Request request = get_reqq_self()->back(); + get_reqq_self()->pop_back(); if (request==nullptr){ /* Assume that the trace is well formed, meaning the comm might have been caught by a MPI_test. Then just return.*/ @@ -435,68 +426,24 @@ static void action_wait(const char *const *action){ static void action_waitall(const char *const *action){ CHECK_ACTION_PARAMS(action, 0, 0) double clock = smpi_process_simulated_elapsed(); - int count_requests=0; - unsigned int i=0; - - count_requests=xbt_dynar_length(get_reqq_self()); + unsigned int count_requests=get_reqq_self()->size(); if (count_requests>0) { - MPI_Request requests[count_requests]; MPI_Status status[count_requests]; - /* The reqq is an array of dynars. Its index corresponds to the rank. - Thus each rank saves its own requests to the array request. */ - xbt_dynar_foreach(get_reqq_self(),i,requests[i]); - - //save information from requests - xbt_dynar_t srcs = xbt_dynar_new(sizeof(int), nullptr); - xbt_dynar_t dsts = xbt_dynar_new(sizeof(int), nullptr); - xbt_dynar_t recvs = xbt_dynar_new(sizeof(int), nullptr); - for (i = 0; static_cast(i) < count_requests; i++) { - if(requests[i]){ - int *asrc = xbt_new(int, 1); - int *adst = xbt_new(int, 1); - int *arecv = xbt_new(int, 1); - *asrc = requests[i]->src; - *adst = requests[i]->dst; - *arecv = requests[i]->recv; - xbt_dynar_insert_at(srcs, i, asrc); - xbt_dynar_insert_at(dsts, i, adst); - xbt_dynar_insert_at(recvs, i, arecv); - xbt_free(asrc); - xbt_free(adst); - xbt_free(arecv); - }else { - int *t = xbt_new(int, 1); - xbt_dynar_insert_at(srcs, i, t); - xbt_dynar_insert_at(dsts, i, t); - xbt_dynar_insert_at(recvs, i, t); - xbt_free(t); - } - } int rank_traced = smpi_process_index(); instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1); extra->type = TRACING_WAITALL; extra->send_size=count_requests; TRACE_smpi_ptp_in(rank_traced, -1, -1, __FUNCTION__,extra); - smpi_mpi_waitall(count_requests, requests, status); + smpi_mpi_waitall(count_requests, &(*get_reqq_self())[0], status); - for (i = 0; static_cast(i) < count_requests; i++) { - int src_traced, dst_traced, is_wait_for_receive; - xbt_dynar_get_cpy(srcs, i, &src_traced); - xbt_dynar_get_cpy(dsts, i, &dst_traced); - xbt_dynar_get_cpy(recvs, i, &is_wait_for_receive); - if (is_wait_for_receive) { - TRACE_smpi_recv(rank_traced, src_traced, dst_traced); - } + for (auto req : *(get_reqq_self())){ + if (req && req->recv) + TRACE_smpi_recv(rank_traced, req->src, req->dst); } TRACE_smpi_ptp_out(rank_traced, -1, -1, __FUNCTION__); - //clean-up of dynars - xbt_dynar_free(&srcs); - xbt_dynar_free(&dsts); - xbt_dynar_free(&recvs); - set_reqq_self(xbt_dynar_new(sizeof(MPI_Request),&xbt_free_ref)); } log_timed_action (action, clock); } @@ -928,7 +875,6 @@ static void action_allToAllv(const char *const *action) { int comm_size = smpi_comm_size(MPI_COMM_WORLD); CHECK_ACTION_PARAMS(action, 2*comm_size+2, 2) - int send_buf_size=0,recv_buf_size=0,i=0; int *sendcounts = xbt_new0(int, comm_size); int *recvcounts = xbt_new0(int, comm_size); int *senddisps = xbt_new0(int, comm_size); @@ -936,8 +882,8 @@ static void action_allToAllv(const char *const *action) { MPI_Datatype MPI_CURRENT_TYPE2; - send_buf_size=parse_double(action[2]); - recv_buf_size=parse_double(action[3+comm_size]); + int send_buf_size=parse_double(action[2]); + int recv_buf_size=parse_double(action[3+comm_size]); if(action[4+2*comm_size] && action[5+2*comm_size]) { MPI_CURRENT_TYPE=decode_datatype(action[4+2*comm_size]); MPI_CURRENT_TYPE2=decode_datatype(action[5+2*comm_size]); @@ -950,7 +896,7 @@ static void action_allToAllv(const char *const *action) { void *sendbuf = smpi_get_tmp_sendbuffer(send_buf_size* smpi_datatype_size(MPI_CURRENT_TYPE)); void *recvbuf = smpi_get_tmp_recvbuffer(recv_buf_size* smpi_datatype_size(MPI_CURRENT_TYPE2)); - for(i=0;isendcounts= xbt_new(int, comm_size); extra->num_processes = comm_size; - for(i=0; i< comm_size; i++){//copy data to avoid bad free + for(int i=0; i< comm_size; i++){//copy data to avoid bad free extra->send_size += sendcounts[i]; extra->sendcounts[i] = sendcounts[i]; extra->recv_size += recvcounts[i]; @@ -1047,14 +993,17 @@ void smpi_replay_run(int *argc, char***argv){ /* and now, finalize everything */ double sim_time= 1.; /* One active process will stop. Decrease the counter*/ - XBT_DEBUG("There are %lu elements in reqq[*]", xbt_dynar_length(get_reqq_self())); - if (xbt_dynar_is_empty(get_reqq_self())==0){ - int count_requests=xbt_dynar_length(get_reqq_self()); + XBT_DEBUG("There are %zu elements in reqq[*]", get_reqq_self()->size()); + if (!get_reqq_self()->empty()){ + unsigned int count_requests=get_reqq_self()->size(); MPI_Request requests[count_requests]; MPI_Status status[count_requests]; - unsigned int i; + unsigned int i=0; - xbt_dynar_foreach(get_reqq_self(),i,requests[i]); + for (auto req: *get_reqq_self()){ + requests[i] = req; + i++; + } smpi_mpi_waitall(count_requests, requests, status); active_processes--; } else { @@ -1069,8 +1018,6 @@ void smpi_replay_run(int *argc, char***argv){ _xbt_replay_action_exit(); xbt_free(sendbuffer); xbt_free(recvbuffer); - xbt_dict_free(&reqq); //not need, data have been freed ??? - reqq = nullptr; } instr_extra_data extra_fin = xbt_new0(s_instr_extra_data_t,1); diff --git a/src/smpi/smpi_rma.cpp b/src/smpi/smpi_rma.cpp index 039676f095..21f3e02ea0 100644 --- a/src/smpi/smpi_rma.cpp +++ b/src/smpi/smpi_rma.cpp @@ -1,4 +1,3 @@ - /* Copyright (c) 2007-2015. The SimGrid Team. * All rights reserved. */ @@ -6,6 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "private.h" +#include XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA operations)"); @@ -20,7 +20,7 @@ typedef struct s_smpi_mpi_win{ MPI_Comm comm; MPI_Info info; int assert; - xbt_dynar_t requests; + std::vector *requests; xbt_bar_t bar; MPI_Win* connected_wins; char* name; @@ -48,7 +48,7 @@ MPI_Win smpi_mpi_win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info win->name = nullptr; win->opened = 0; win->group = MPI_GROUP_NULL; - win->requests = xbt_dynar_new(sizeof(MPI_Request), nullptr); + win->requests = new std::vector(); win->connected_wins = xbt_new0(MPI_Win, comm_size); win->connected_wins[rank] = win; @@ -68,7 +68,7 @@ MPI_Win smpi_mpi_win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info int smpi_mpi_win_free( MPI_Win* win){ //As per the standard, perform a barrier to ensure every async comm is finished xbt_barrier_wait((*win)->bar); - xbt_dynar_free(&(*win)->requests); + delete (*win)->requests; xbt_free((*win)->connected_wins); if ((*win)->name != nullptr){ xbt_free((*win)->name); @@ -113,21 +113,16 @@ int smpi_mpi_win_fence( int assert, MPI_Win win){ if(assert != MPI_MODE_NOPRECEDE){ xbt_barrier_wait(win->bar); - xbt_dynar_t reqs = win->requests; - int size = xbt_dynar_length(reqs); - unsigned int cpt=0; - MPI_Request req; + std::vector *reqs = win->requests; + int size = static_cast(reqs->size()); // start all requests that have been prepared by another process - xbt_dynar_foreach(reqs, cpt, req){ - if (req->flags & PREPARED) + for(auto req: *reqs){ + if (req && (req->flags & PREPARED)) smpi_mpi_start(req); } - MPI_Request* treqs = static_cast(xbt_dynar_to_array(reqs)); - win->requests=xbt_dynar_new(sizeof(MPI_Request), nullptr); + MPI_Request* treqs = &(*reqs)[0]; smpi_mpi_waitall(size,treqs,MPI_STATUSES_IGNORE); - xbt_free(treqs); - } win->assert = assert; @@ -158,13 +153,13 @@ int smpi_mpi_put( void *origin_addr, int origin_count, MPI_Datatype origin_datat smpi_group_index(smpi_comm_group(win->comm),target_rank), RMA_TAG+1, recv_win->comm, MPI_OP_NULL); //push request to receiver's win - xbt_dynar_push_as(recv_win->requests, MPI_Request, rreq); + recv_win->requests->push_back(rreq); //start send smpi_mpi_start(sreq); //push request to sender's win - xbt_dynar_push_as(win->requests, MPI_Request, sreq); + win->requests->push_back(sreq); }else{ smpi_datatype_copy(origin_addr, origin_count, origin_datatype, recv_addr, target_count, target_datatype); } @@ -198,13 +193,13 @@ int smpi_mpi_get( void *origin_addr, int origin_count, MPI_Datatype origin_datat smpi_mpi_start(sreq); //push request to receiver's win - xbt_dynar_push_as(send_win->requests, MPI_Request, sreq); + send_win->requests->push_back(sreq); //start recv smpi_mpi_start(rreq); //push request to sender's win - xbt_dynar_push_as(win->requests, MPI_Request, rreq); + win->requests->push_back(rreq); }else{ smpi_datatype_copy(send_addr, target_count, target_datatype, origin_addr, origin_count, origin_datatype); } @@ -233,12 +228,12 @@ int smpi_mpi_accumulate( void *origin_addr, int origin_count, MPI_Datatype origi MPI_Request rreq = smpi_rma_recv_init(recv_addr, target_count, target_datatype, smpi_process_index(), smpi_group_index(smpi_comm_group(win->comm),target_rank), RMA_TAG+3, recv_win->comm, op); //push request to receiver's win - xbt_dynar_push_as(recv_win->requests, MPI_Request, rreq); + recv_win->requests->push_back(rreq); //start send smpi_mpi_start(sreq); //push request to sender's win - xbt_dynar_push_as(win->requests, MPI_Request, sreq); + win->requests->push_back(sreq); return MPI_SUCCESS; } @@ -339,22 +334,19 @@ int smpi_mpi_win_complete(MPI_Win win){ //now we can finish RMA calls - xbt_dynar_t reqqs = win->requests; - size = xbt_dynar_length(reqqs); + std::vector *reqqs = win->requests; + size = static_cast(reqqs->size()); XBT_DEBUG("Win_complete - Finishing %d RMA calls", size); - unsigned int cpt=0; - MPI_Request req; // start all requests that have been prepared by another process - xbt_dynar_foreach(reqqs, cpt, req){ - if (req->flags & PREPARED) + for (auto req: *reqqs){ + if (req && (req->flags & PREPARED)) smpi_mpi_start(req); } - MPI_Request* treqs = static_cast(xbt_dynar_to_array(reqqs)); - win->requests=xbt_dynar_new(sizeof(MPI_Request), nullptr); + MPI_Request* treqs = &(*reqqs)[0]; smpi_mpi_waitall(size,treqs,MPI_STATUSES_IGNORE); - xbt_free(treqs); + reqqs->clear(); smpi_group_unuse(win->group); win->opened--; //we're closed for business ! return MPI_SUCCESS; @@ -384,23 +376,20 @@ int smpi_mpi_win_wait(MPI_Win win){ } xbt_free(reqs); - xbt_dynar_t reqqs = win->requests; - size = xbt_dynar_length(reqqs); + std::vector *reqqs = win->requests; + size = static_cast(reqqs->size()); XBT_DEBUG("Win_complete - Finishing %d RMA calls", size); - unsigned int cpt=0; - MPI_Request req; // start all requests that have been prepared by another process - xbt_dynar_foreach(reqqs, cpt, req){ - if (req->flags & PREPARED) + for(auto req: *reqqs){ + if (req && (req->flags & PREPARED)) smpi_mpi_start(req); } - MPI_Request* treqs = static_cast(xbt_dynar_to_array(reqqs)); - win->requests=xbt_dynar_new(sizeof(MPI_Request), nullptr); + MPI_Request* treqs = &(*reqqs)[0]; smpi_mpi_waitall(size,treqs,MPI_STATUSES_IGNORE); - xbt_free(treqs); + reqqs->clear(); smpi_group_unuse(win->group); win->opened--; //we're opened for business ! return MPI_SUCCESS; diff --git a/src/surf/maxmin.cpp b/src/surf/maxmin.cpp index 6645a0d206..a96e470de0 100644 --- a/src/surf/maxmin.cpp +++ b/src/surf/maxmin.cpp @@ -1220,25 +1220,28 @@ static void lmm_remove_all_modified_set(lmm_system_t sys) } /** - * Returns total resource load + * Returns resource load (in flop per second, or byte per second, or similar) * - * \param cnst the lmm_constraint_t associated to the resource + * If the resource is shared (the default case), the load is sum of + * resource usage made by every variables located on this resource. * - * This is dead code, but we may use it later for debug/trace. + * If the resource is not shared (ie in FATPIPE mode), then the the + * load is the max (not the sum) of all resource usages located on this resource. + * . + * \param cnst the lmm_constraint_t associated to the resource */ double lmm_constraint_get_usage(lmm_constraint_t cnst) { double usage = 0.0; xbt_swag_t elem_list = &(cnst->enabled_element_set); void *_elem; - lmm_element_t elem = nullptr; xbt_swag_foreach(_elem, elem_list) { - elem = (lmm_element_t)_elem; - if ((elem->value > 0)) { + lmm_element_t elem = (lmm_element_t)_elem; + if (elem->value > 0) { if (cnst->sharing_policy) usage += elem->value * elem->variable->value; else if (usage < elem->value * elem->variable->value) - usage = elem->value * elem->variable->value; + usage = std::max(usage, elem->value * elem->variable->value); } } return usage; diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index 0ec679a93b..028b8af65b 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -48,7 +48,7 @@ In this example, the idle consumption is 95 Watts, 93 Watts and 90 Watts in each are at 200 Watts, 170 Watts, and 150 Watts respectively. To change the pstate of a given CPU, use the following functions: -#MSG_host_get_nb_pstates(), simgrid#s4u#Host#set_pstate(), #MSG_host_get_power_peak_at(). +#MSG_host_get_nb_pstates(), simgrid#s4u#Host#setPstate(), #MSG_host_get_power_peak_at(). To simulate the energy-related elements, first call the simgrid#energy#sg_energy_plugin_init() before your #MSG_init(), and then use the following function to retrieve the consumption of a given host: MSG_host_get_consumed_energy(). @@ -77,8 +77,15 @@ void HostEnergy::update() else cpu_load = lmm_constraint_get_usage(surf_host->cpu_->getConstraint()) / surf_host->cpu_->speed_.peak; - if (cpu_load > 1) // A machine with a load > 1 consumes as much as a fully loaded machine, not mores + if (cpu_load > 1) // A machine with a load > 1 consumes as much as a fully loaded machine, not more cpu_load = 1; + /* The problem with this model is that the load is always 0 or 1, never something less. + * Another possibility could be to model the total energy as + * + * X/(X+Y)*W_idle + Y/(X+Y)*W_burn + * + * where X is the amount of ideling cores, and Y the amount of computing cores. + */ double previous_energy = this->total_energy; diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 62f899e02c..c9590e81d8 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -33,7 +33,7 @@ xbt_dynar_t model_list_invoke = nullptr; /* to invoke callbacks */ simgrid::trace_mgr::future_evt_set *future_evt_set = nullptr; xbt_dynar_t surf_path = nullptr; -std::vector host_that_restart; +std::vector host_that_restart; xbt_dict_t watched_hosts_lib; namespace simgrid { diff --git a/src/surf/virtual_machine.hpp b/src/surf/virtual_machine.hpp index d3aee1a19d..47ad8c5881 100644 --- a/src/surf/virtual_machine.hpp +++ b/src/surf/virtual_machine.hpp @@ -115,10 +115,10 @@ public: * @param host_PM The real machine hosting the VM */ s4u::Host *createVM(const char *name, sg_host_t host_PM); - void adjustWeightOfDummyCpuActions() {}; + void adjustWeightOfDummyCpuActions() override {}; double next_occuring_event(double now) override; - void updateActionsState(double /*now*/, double /*delta*/) {}; + void updateActionsState(double /*now*/, double /*delta*/) override {}; };