typedef struct coll_ctr_t{
int bcast_counter;
+ int reduce_counter;
} *coll_ctr;
/* Helper function */
static int spawned_recv(int argc, char *argv[])
{
m_task_t task = NULL;
- char* name = (char *) MSG_process_get_data(MSG_process_self());
+ char* name = (char *) MSG_process_self()->data;
INFO1("Receiving on %s", name);
MSG_task_receive(&task, name);
INFO1("Received %s", MSG_task_get_name(task));
+ INFO1("waiter on %s", MSG_process_self()->name);
MSG_task_send(MSG_task_create("waiter",0,0,NULL),MSG_process_self()->name);
MSG_task_destroy(task);
sprintf(name,"%s_wait",MSG_process_self()->name);
comm_helper = MSG_process_create(name,spawned_recv,
- (void *) MSG_process_get_name(MSG_process_self()),
+ (void *) MSG_process_self()->name,
MSG_host_self());
INFO1("wait: %s", name);
sprintf(task_name,"%s_wait",MSG_process_self()->name);
MSG_task_receive(&task,task_name);
+ MSG_task_destroy(task);
INFO1("waited: %s", name);
free(name);
}
}
+static void reduce(xbt_dynar_t action)
+{
+ int i;
+ char *name;
+ char task_name[80];
+ char spawn_name[80];
+ char *comm_size = xbt_dynar_get_as(action, 2, char *);
+ char *comp_size = xbt_dynar_get_as(action, 3, char *);
+ m_process_t comm_helper=NULL;
+ m_task_t task=NULL, comp_task=NULL;
+ const char* process_name;
+
+ coll_ctr counters = (coll_ctr) MSG_process_get_data(MSG_process_self());
+
+ xbt_assert0(communicator_size, "Size of Communicator is not defined"
+ ", can't use collective operations");
+
+ MSG_process_self()->data=NULL;
+
+ process_name = MSG_process_self()->name;
+
+ if (!counters){
+ DEBUG0("Initialize the counters");
+ counters = (coll_ctr) calloc (1, sizeof(struct coll_ctr_t));
+ }
+
+ name = bprintf("reduce_%d", counters->reduce_counter++);
+
+ if (!strcmp(process_name, "process0")){
+ INFO2("%s: %s is the Root",name, process_name);
+ for(i=1;i<communicator_size;i++){
+ sprintf(spawn_name,"%s_process%d", name, i);
+ sprintf(task_name,"%s_wait", spawn_name);
+ comm_helper =
+ MSG_process_create(task_name, spawned_recv,
+ (void *) xbt_strdup(spawn_name),
+ MSG_host_self());
+ }
+
+ for(i=1;i<communicator_size;i++){
+ sprintf(task_name,"%s_process%d_wait", name, i);
+ MSG_task_receive(&task,task_name);
+ MSG_task_destroy(task);
+ task=NULL;
+ }
+
+ comp_task =
+ MSG_task_create("reduce_comp", parse_double(comp_size), 0, NULL);
+ INFO1("%s: computing 'reduce_comp'", name);
+ MSG_task_execute(comp_task);
+ MSG_task_destroy(comp_task);
+ INFO1("%s: computed", name);
+ } else {
+ INFO2("%s: %s sends", name, process_name);
+ sprintf(task_name,"%s_%s", name, process_name);
+ INFO1("put on %s", task_name);
+ MSG_task_send(MSG_task_create(name, 0, parse_double(comm_size), NULL),
+ task_name);
+ }
+
+ MSG_process_set_data(MSG_process_self(), (void*)counters);
+ free(name);
+}
+
static void bcast (xbt_dynar_t action)
{
int i;
MSG_action_register("wait", wait);
MSG_action_register("barrier", barrier);
MSG_action_register("bcast", bcast);
+ MSG_action_register("reduce", reduce);
MSG_action_register("sleep", sleep);
MSG_action_register("compute", compute);