From: Martin Quinson Date: Tue, 4 Feb 2020 09:18:07 +0000 (+0100) Subject: no dynar in the new C interface (+cleanups in CMakeLists) X-Git-Tag: v3.26~1058 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/17b3d85fb091cd19e28757287829d65a8debe3e3 no dynar in the new C interface (+cleanups in CMakeLists) --- diff --git a/include/simgrid/comm.h b/include/simgrid/comm.h index ea808a9160..933cd70b1c 100644 --- a/include/simgrid/comm.h +++ b/include/simgrid/comm.h @@ -12,7 +12,7 @@ /* C interface */ SG_BEGIN_DECL -XBT_PUBLIC int sg_comm_wait_any_for(const xbt_dynar_t comms, double timeout); +XBT_PUBLIC int sg_comm_wait_any_for(sg_comm_t* comms, size_t count, double timeout); SG_END_DECL diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index 4391ce07fb..9eabf307d3 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -254,16 +254,14 @@ Actor* Comm::get_sender() } // namespace s4u } // namespace simgrid /* **************************** Public C interface *************************** */ -int sg_comm_wait_any_for(const xbt_dynar_t comms, double timeout) +int sg_comm_wait_any_for(sg_comm_t* comms, size_t count, double timeout) { std::vector s4u_comms; - unsigned int i; - sg_comm_t comm; - xbt_dynar_foreach (comms, i, comm) { - s4u_comms.emplace_back(comm); + for (unsigned int i = 0; i < count; i++) { + s4u_comms.emplace_back(comms[i]); } int pos = simgrid::s4u::Comm::wait_any_for(&s4u_comms, timeout); if (pos != -1) - intrusive_ptr_release(xbt_dynar_get_as(comms, pos, sg_comm_t)); + s4u_comms[pos]->unref(); return pos; } diff --git a/teshsuite/c/CMakeLists.txt b/teshsuite/c/CMakeLists.txt index cf5815fc05..29e6483c40 100644 --- a/teshsuite/c/CMakeLists.txt +++ b/teshsuite/c/CMakeLists.txt @@ -12,9 +12,8 @@ set(teshsuite_src ${teshsuite_src} PARENT_SCOPE) set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/async-waitany_d.xml PARENT_SCOPE) foreach(x async-waitany) - ADD_TESH_FACTORIES(tesh-msg-${x} "raw" - --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms - --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/c/${x} - --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/c/${x} - ${CMAKE_HOME_DIRECTORY}/teshsuite/c/${x}/${x}.tesh) + ADD_TESH(tesh-c-${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms + --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/c/${x} + --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/c/${x} + ${CMAKE_HOME_DIRECTORY}/teshsuite/c/${x}/${x}.tesh) endforeach() diff --git a/teshsuite/c/async-waitany/async-waitany.c b/teshsuite/c/async-waitany/async-waitany.c index c7475e5796..d1b2d2188b 100644 --- a/teshsuite/c/async-waitany/async-waitany.c +++ b/teshsuite/c/async-waitany/async-waitany.c @@ -23,35 +23,36 @@ static int sender(int argc, char* argv[]) long msg_size = xbt_str_parse_int(argv[2], "Invalid communication size: %s"); long receivers_count = xbt_str_parse_int(argv[3], "Invalid amount of receivers: %s"); - /* Dynar in which we store all ongoing communications */ - xbt_dynar_t pending_comms = xbt_dynar_new(sizeof(sg_comm_t), NULL); + /* Array in which we store all ongoing communications */ + sg_comm_t* pending_comms = malloc(sizeof(sg_comm_t) * (messages_count + receivers_count)); + int pending_comms_count = 0; - /* Make a dynar of the mailboxes to use */ - xbt_dynar_t mboxes = xbt_dynar_new(sizeof(sg_mailbox_t), NULL); + /* Make an array of the mailboxes to use */ + sg_mailbox_t* mboxes = malloc(sizeof(sg_mailbox_t) * receivers_count); for (long i = 0; i < receivers_count; i++) { char mailbox_name[80]; snprintf(mailbox_name, 79, "receiver-%ld", (i)); sg_mailbox_t mbox = sg_mailbox_by_name(mailbox_name); - xbt_dynar_push(mboxes, &mbox); + mboxes[i] = mbox; } /* Start dispatching all messages to receivers, in a round robin fashion */ for (int i = 0; i < messages_count; i++) { char msg_content[80]; snprintf(msg_content, 79, "Message_%d", i); - sg_mailbox_t mbox = xbt_dynar_get_as(mboxes, i % receivers_count, sg_mailbox_t); + sg_mailbox_t mbox = mboxes[i % receivers_count]; XBT_INFO("Send '%s' to '%s'", msg_content, sg_mailbox_get_name(mbox)); - sg_comm_t comm = sg_mailbox_put_async(mbox, xbt_strdup(msg_content), msg_size); - xbt_dynar_push(pending_comms, &comm); + sg_comm_t comm = sg_mailbox_put_async(mbox, xbt_strdup(msg_content), msg_size); + pending_comms[pending_comms_count++] = comm; } /* Start sending messages to let the workers know that they should stop */ for (int i = 0; i < receivers_count; i++) { XBT_INFO("Send 'finalize' to 'receiver-%d'", i); - char* end_msg = xbt_strdup("finalize"); - sg_mailbox_t mbox = xbt_dynar_get_as(mboxes, i % receivers_count, sg_mailbox_t); - sg_comm_t comm = sg_mailbox_put_async(mbox, end_msg, 0); - xbt_dynar_push(pending_comms, &comm); + char* end_msg = xbt_strdup("finalize"); + sg_mailbox_t mbox = mboxes[i % receivers_count]; + sg_comm_t comm = sg_mailbox_put_async(mbox, end_msg, 0); + pending_comms[pending_comms_count++] = comm; } XBT_INFO("Done dispatching all messages"); @@ -62,16 +63,19 @@ static int sender(int argc, char* argv[]) * terminated * Even in this simple example, the pending comms do not terminate in the exact same order of creation. */ - while (!xbt_dynar_is_empty(pending_comms)) { - int changed_pos = sg_comm_wait_any_for(pending_comms, -1); - xbt_dynar_remove_at(pending_comms, changed_pos, NULL); + while (pending_comms_count != 0) { + int changed_pos = sg_comm_wait_any_for(pending_comms, pending_comms_count, -1); + memmove(pending_comms + changed_pos, pending_comms + changed_pos + 1, + sizeof(sg_comm_t) * (pending_comms_count - changed_pos - 1)); + pending_comms_count--; + if (changed_pos != 0) XBT_INFO("Remove the %dth pending comm: it terminated earlier than another comm that was initiated first.", changed_pos); } - xbt_dynar_free(&pending_comms); - xbt_dynar_free(&mboxes); + free(pending_comms); + free(mboxes); XBT_INFO("Goodbye now!"); return 0; diff --git a/teshsuite/s4u/CMakeLists.txt b/teshsuite/s4u/CMakeLists.txt index 464fb573f4..01d3643955 100644 --- a/teshsuite/s4u/CMakeLists.txt +++ b/teshsuite/s4u/CMakeLists.txt @@ -12,10 +12,10 @@ foreach(x actor actor-autorestart endforeach() ## Add the tests. -## Some need to be run with all factories, some need not tesh to run +## Some need to be run with all factories, some don't need tesh to run foreach(x actor actor-autorestart activity-lifecycle wait-any-for - cloud-interrupt-migration concurrent_rw) # TODO: actor-autorestart is disabled for now + cloud-interrupt-migration concurrent_rw) set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh) ADD_TESH_FACTORIES(tesh-s4u-${x} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x} --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_BINARY_DIR}/teshsuite/s4u/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/s4u/${x}/${x}.tesh) endforeach()