Logo AND Algorithmique Numérique Distribuée

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