Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
enlarge my cluster
[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 static void send_one(int from, int to) {
27   //XBT_DEBUG("send_one(%d, %d)",from,to);
28
29   if (count %1000 == 0)
30     XBT_INFO("Sending task #%d",count);
31   count++;
32
33   bcast_task_t bt = xbt_new(s_bcast_task_t,1);
34
35   bt->i=from;
36   bt->j=(from+to)/2;
37   bt->k=to;
38
39   SD_task_t t = SD_task_create_comm_e2e("Blab",bt,424242);
40   XBT_DEBUG("Schedule task between %d and %d",bt->i,bt->j);
41   SD_task_schedulel(t,2,ws_list[bt->i],ws_list[bt->j]);
42   SD_task_watch(t,SD_DONE);
43 }
44
45 int main(int argc, char **argv) {
46
47   /* initialization of SD */
48   SD_init(&argc, argv);
49
50   if (argc > 1) {
51     SD_create_environment(argv[1]);
52   } else {
53     SD_create_environment("../../platforms/One_cluster_no_backbone.xml");
54   }
55
56   ws_list = SD_workstation_get_list();
57   xbt_dynar_t done = NULL;
58   send_one(0,10000);
59   do {
60     if (done != NULL && xbt_dynar_length(done) > 0) {
61       unsigned int cursor;
62       SD_task_t task;
63
64       xbt_dynar_foreach(done, cursor, task) {
65         bcast_task_t bt = SD_task_get_data(task);
66
67         if (bt->i != bt->j -1)
68           send_one(bt->i,bt->j);
69         if (bt->j != bt->k -1)
70           send_one(bt->j,bt->k);
71
72         SD_task_destroy(task);
73         free(bt);
74       }
75       xbt_dynar_free(&done);
76     }
77     done=SD_simulate(-1);
78   } while(xbt_dynar_length(done) > 0);
79
80   SD_exit();
81   return 0;
82 }