X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d8178c8f3d3ade4087f2d219a6312222190c85d2..9f54e5c450791e19b01f31e86c93e5a603fd0c4b:/examples/msg/actions/actions.c?ds=sidebyside diff --git a/examples/msg/actions/actions.c b/examples/msg/actions/actions.c index e1a0a70d40..2f8958d266 100644 --- a/examples/msg/actions/actions.c +++ b/examples/msg/actions/actions.c @@ -8,6 +8,7 @@ #include #include #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */ +#include "simix/simix.h" /* semaphores for the barrier */ #include "xbt.h" /* calloc, printf */ #include "simgrid_config.h" /* getline */ @@ -34,7 +35,7 @@ static double parse_double(const char *string) { /* My actions */ -static void send(xbt_dynar_t action) +static void action_send(xbt_dynar_t action) { char *name = NULL; char to[250]; @@ -94,7 +95,7 @@ static void Isend(xbt_dynar_t action) } -static void recv(xbt_dynar_t action) +static void action_recv(xbt_dynar_t action) { char *name = NULL; char mailbox_name[250]; @@ -161,7 +162,7 @@ static void Irecv(xbt_dynar_t action) } -static void wait_action(xbt_dynar_t action) +static void action_wait(xbt_dynar_t action) { char *name = NULL; char task_name[80]; @@ -181,6 +182,8 @@ static void wait_action(xbt_dynar_t action) free(name); } +/* FIXME: that's a poor man's implementation: we should take the message exchanges into account */ +smx_sem_t barrier_semaphore=NULL; static void barrier (xbt_dynar_t action) { char *name = NULL; @@ -188,9 +191,19 @@ static void barrier (xbt_dynar_t action) if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) name = xbt_str_join(action, " "); - DEBUG1("barrier: %s", name); + DEBUG1("Entering barrier: %s", name); + if (barrier_semaphore == NULL) // first arriving on the barrier + barrier_semaphore = SIMIX_sem_init(0); - THROW_UNIMPLEMENTED; + if (SIMIX_sem_get_capacity(barrier_semaphore)==-communicator_size +1) { // last arriving + SIMIX_sem_release_forever(barrier_semaphore); + SIMIX_sem_destroy(barrier_semaphore); + barrier_semaphore = NULL; + } else { // not last + SIMIX_sem_acquire(barrier_semaphore); + } + + DEBUG1("Exiting barrier: %s", name); if (XBT_LOG_ISENABLED(actions,xbt_log_priority_debug)) free(name); @@ -333,7 +346,7 @@ static void bcast (xbt_dynar_t action) } -static void sleep(xbt_dynar_t action) +static void action_sleep(xbt_dynar_t action) { char *name = NULL; char *duration = xbt_dynar_get_as(action, 2, char *); @@ -499,16 +512,16 @@ int main(int argc, char *argv[]) /* Action registration */ MSG_action_register("comm_size", comm_size); - MSG_action_register("send", send); + MSG_action_register("send", action_send); MSG_action_register("Isend", Isend); - MSG_action_register("recv", recv); + MSG_action_register("recv", action_recv); MSG_action_register("Irecv", Irecv); - MSG_action_register("wait", wait_action); + MSG_action_register("wait", action_wait); MSG_action_register("barrier", barrier); MSG_action_register("bcast", bcast); MSG_action_register("reduce", reduce); MSG_action_register("allReduce", allReduce); - MSG_action_register("sleep", sleep); + MSG_action_register("sleep", action_sleep); MSG_action_register("compute", compute);