Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into S4U
[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 <stdlib.h>
15 #include <stdio.h>
16 #include "simgrid/simdag.h"
17 #include "xbt/log.h"
18 #include "xbt/ex.h"
19 #include <string.h>
20 #include "xbt/xbt_os_time.h"
21
22 XBT_LOG_NEW_DEFAULT_CATEGORY(goal, "The GOAL loader into SimDag");
23
24 typedef struct {
25   int i, j, k;
26 } s_bcast_task_t,*bcast_task_t;
27
28
29 const SD_workstation_t* ws_list;
30 int count = 0;
31
32 xbt_dynar_t reclaimed;
33
34 static void send_one(int from, int to) {
35   //XBT_DEBUG("send_one(%d, %d)",from,to);
36
37   if (count %100000 == 0)
38     XBT_INFO("Sending task #%d",count);
39   count++;
40
41   bcast_task_t bt;
42   if (!xbt_dynar_is_empty(reclaimed)) {
43      bt = xbt_dynar_pop_as(reclaimed,bcast_task_t);
44   } else {
45     bt = xbt_new(s_bcast_task_t,1);
46   }
47   bt->i=from;
48   bt->j=(from+to)/2;
49   bt->k=to;
50
51   SD_task_t task = SD_task_create_comm_e2e(NULL,bt,424242);
52
53   XBT_DEBUG("Schedule task between %d and %d",bt->i,bt->j);
54   SD_task_schedulel(task,2,ws_list[bt->i],ws_list[bt->j]);
55   SD_task_watch(task,SD_DONE);
56 }
57
58
59 int main(int argc, char **argv) {
60   xbt_os_timer_t timer = xbt_os_timer_new();
61
62   /* initialization of SD */
63   SD_init(&argc, argv);
64
65   if (argc > 1) {
66     SD_create_environment(argv[1]);
67   } else {
68     SD_create_environment("../../platforms/One_cluster_no_backbone.xml");
69   }
70
71   ws_list = SD_workstation_get_list();
72   reclaimed = xbt_dynar_new(sizeof(bcast_task_t),xbt_free_ref);
73   xbt_dynar_t done = NULL;
74
75   xbt_os_cputimer_start(timer);
76   send_one(0,SD_workstation_get_number());
77   do {
78     if (done != NULL && !xbt_dynar_is_empty(done)) {
79       unsigned int cursor;
80       SD_task_t task;
81
82       xbt_dynar_foreach(done, cursor, task) {
83         bcast_task_t bt = SD_task_get_data(task);
84
85         if (bt->i != bt->j -1)
86           send_one(bt->i,bt->j);
87         if (bt->j != bt->k -1)
88           send_one(bt->j,bt->k);
89
90         if (xbt_dynar_length(reclaimed)<100) {
91           xbt_dynar_push_as(reclaimed,bcast_task_t,bt);
92         } else {
93           free(bt);
94         }
95         SD_task_destroy(task);
96       }
97       xbt_dynar_free(&done);
98     }
99     done=SD_simulate(-1);
100   } while(!xbt_dynar_is_empty(done));
101   xbt_os_cputimer_stop(timer);
102   printf("exec_time:%f\n", xbt_os_timer_elapsed(timer) );
103
104   xbt_dynar_free(&done);
105   xbt_dynar_free(&reclaimed);
106
107   SD_exit();
108   XBT_INFO("Done. Bailing out");
109   return 0;
110 }