Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
be7b99e7e67dbe2e4df31e1866bd6442cf6786da
[simgrid.git] / examples / simdag / goal / goal_test.c
1 /* Example of scatter communication, accepting a large amount of processes. 
2  * This based the experiment of Fig. 4 in http://hal.inria.fr/hal-00650233/
3  * That experiment is a comparison to the LogOPSim simulator, that takes 
4  *  GOAL files as an input, thus the file name. But there is no actual link
5  *  to the GOAL formalism beside of this.
6  * 
7  * Copyright (c) 2011. The SimGrid Team. All rights reserved.
8  * 
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the license (GNU LGPL) which comes with this package.
11  */
12
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include "simdag/simdag.h"
16 #include "xbt/log.h"
17 #include "xbt/ex.h"
18 #include <string.h>
19 #include "xbt/xbt_os_time.h"
20
21 XBT_LOG_NEW_DEFAULT_CATEGORY(goal, "The GOAL loader into SimDag");
22
23 typedef struct {
24   int i, j, k;
25 } s_bcast_task_t,*bcast_task_t;
26
27
28 const SD_workstation_t* ws_list;
29 int count = 0;
30
31 xbt_dynar_t reclaimed;
32
33 static void send_one(int from, int to) {
34   //XBT_DEBUG("send_one(%d, %d)",from,to);
35
36   if (count %100000 == 0)
37     XBT_INFO("Sending task #%d",count);
38   count++;
39
40   bcast_task_t bt;
41   if (!xbt_dynar_is_empty(reclaimed)) {
42      bt = xbt_dynar_pop_as(reclaimed,bcast_task_t);
43   } else {
44     bt = xbt_new(s_bcast_task_t,1);
45   }
46   bt->i=from;
47   bt->j=(from+to)/2;
48   bt->k=to;
49
50   SD_task_t task = SD_task_create_comm_e2e(NULL,bt,424242);
51
52   XBT_DEBUG("Schedule task between %d and %d",bt->i,bt->j);
53   SD_task_schedulel(task,2,ws_list[bt->i],ws_list[bt->j]);
54   SD_task_watch(task,SD_DONE);
55 }
56
57
58 int main(int argc, char **argv) {
59   xbt_os_timer_t timer = xbt_os_timer_new();
60
61   /* initialization of SD */
62   SD_init(&argc, argv);
63
64   if (argc > 1) {
65     SD_create_environment(argv[1]);
66   } else {
67     SD_create_environment("../../platforms/One_cluster_no_backbone.xml");
68   }
69
70   ws_list = SD_workstation_get_list();
71   reclaimed = xbt_dynar_new(sizeof(bcast_task_t),xbt_free_ref);
72   xbt_dynar_t done = NULL;
73
74   xbt_os_timer_start(timer);
75   send_one(0,SD_workstation_get_number());
76   do {
77     if (done != NULL && !xbt_dynar_is_empty(done)) {
78       unsigned int cursor;
79       SD_task_t task;
80
81       xbt_dynar_foreach(done, cursor, task) {
82         bcast_task_t bt = SD_task_get_data(task);
83
84         if (bt->i != bt->j -1)
85           send_one(bt->i,bt->j);
86         if (bt->j != bt->k -1)
87           send_one(bt->j,bt->k);
88
89         if (xbt_dynar_length(reclaimed)<100) {
90           xbt_dynar_push_as(reclaimed,bcast_task_t,bt);
91         } else {
92           free(bt);
93         }
94         SD_task_destroy(task);
95       }
96       xbt_dynar_free(&done);
97     }
98     done=SD_simulate(-1);
99   } while(!xbt_dynar_is_empty(done));
100   xbt_os_timer_stop(timer);
101   printf("exec_time:%lf\n", xbt_os_timer_elapsed(timer) );
102
103   xbt_dynar_free(&done);
104   xbt_dynar_free(&reclaimed);
105
106   SD_exit();
107   XBT_INFO("Done. Bailing out");
108   return 0;
109 }