Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
23d774c50cb0d96c0dbc06813a99f3c980e4fbd3
[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
8 /* Copyright (c) 2011-2015. The SimGrid Team.
9  * All rights reserved.                                                     */
10
11 /* This program is free software; you can redistribute it and/or modify it
12  * under the terms of the license (GNU LGPL) which comes with this package. */
13
14 #include "simgrid/simdag.h"
15 #include "xbt/log.h"
16 #include "xbt/xbt_os_time.h"
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(goal, "The GOAL loader into SimDag");
19
20 typedef struct {
21   int i, j, k;
22 } s_bcast_task_t,*bcast_task_t;
23
24 const sg_host_t* ws_list;
25 int count = 0;
26
27 xbt_dynar_t reclaimed;
28
29 static void send_one(int from, int to) {
30   //XBT_DEBUG("send_one(%d, %d)",from,to);
31
32   if (count %100000 == 0)
33     XBT_INFO("Sending task #%d",count);
34   count++;
35
36   bcast_task_t bt;
37   if (!xbt_dynar_is_empty(reclaimed)) {
38      bt = xbt_dynar_pop_as(reclaimed,bcast_task_t);
39   } else {
40     bt = xbt_new(s_bcast_task_t,1);
41   }
42   bt->i=from;
43   bt->j=(from+to)/2;
44   bt->k=to;
45
46   SD_task_t task = SD_task_create_comm_e2e(NULL,bt,424242);
47
48   XBT_DEBUG("Schedule task between %d and %d",bt->i,bt->j);
49   SD_task_schedulel(task,2,ws_list[bt->i],ws_list[bt->j]);
50   SD_task_watch(task,SD_DONE);
51 }
52
53 int main(int argc, char **argv) {
54   xbt_os_timer_t timer = xbt_os_timer_new();
55
56   /* initialization of SD */
57   SD_init(&argc, argv);
58
59   if (argc > 1) {
60     SD_create_environment(argv[1]);
61   } else {
62     SD_create_environment("../../platforms/One_cluster_no_backbone.xml");
63   }
64
65   ws_list = sg_host_list();
66   reclaimed = xbt_dynar_new(sizeof(bcast_task_t),xbt_free_ref);
67   xbt_dynar_t done = NULL;
68
69   xbt_os_cputimer_start(timer);
70   send_one(0,sg_host_count());
71   do {
72     if (done != NULL && !xbt_dynar_is_empty(done)) {
73       unsigned int cursor;
74       SD_task_t task;
75
76       xbt_dynar_foreach(done, cursor, task) {
77         bcast_task_t bt = SD_task_get_data(task);
78
79         if (bt->i != bt->j -1)
80           send_one(bt->i,bt->j);
81         if (bt->j != bt->k -1)
82           send_one(bt->j,bt->k);
83
84         if (xbt_dynar_length(reclaimed)<100) {
85           xbt_dynar_push_as(reclaimed,bcast_task_t,bt);
86         } else {
87           free(bt);
88         }
89         SD_task_destroy(task);
90       }
91       xbt_dynar_free(&done);
92     }
93     done=SD_simulate(-1);
94   } while(!xbt_dynar_is_empty(done));
95   xbt_os_cputimer_stop(timer);
96   printf("exec_time:%f\n", xbt_os_timer_elapsed(timer) );
97
98   xbt_dynar_free(&done);
99   xbt_dynar_free(&reclaimed);
100
101   SD_exit();
102   XBT_INFO("Done. Bailing out");
103   return 0;
104 }