Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first draft of the action runner
[simgrid.git] / examples / msg / actions / actions.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2009. The SimGrid team. All rights reserved.               */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include <stdio.h>
9 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
10 #include "xbt.h" /* calloc, printf */
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,"Messages specific for this msg example");
13
14 /* My actions */
15 static void send(xbt_dynar_t action) {
16         INFO1("Send: %s",xbt_str_join(action," "));
17 }
18 static void recv(xbt_dynar_t action) {
19         INFO1("Recv: %s",xbt_str_join(action," "));
20 }
21 static void sleep(xbt_dynar_t action) {
22         INFO1("Recv: %s",xbt_str_join(action," "));
23 }
24 static void compute(xbt_dynar_t action) {
25         INFO1("compute: %s",xbt_str_join(action," "));
26 }
27
28 /** Main function */
29 int main(int argc, char *argv[]){
30         MSG_error_t res = MSG_OK;
31
32         /* Check the given arguments */
33         MSG_global_init(&argc,argv);
34         if (argc < 4) {
35                 printf ("Usage: %s platform_file deployment_file action_files\n",argv[0]);
36                 printf ("example: %s msg_platform.xml msg_deployment.xml actions\n",argv[0]);
37                 exit(1);
38         }
39
40         /*  Simulation setting */
41         MSG_create_environment(argv[1]);
42
43         /* No need to register functions as in classical MSG programs: the actions get started anyway */
44         MSG_launch_application(argv[2]);
45
46         /*   Action registration */
47         MSG_action_register("send", send);
48         MSG_action_register("recv", recv);
49         MSG_action_register("sleep", sleep);
50         MSG_action_register("compute", sleep);
51
52         /* Actually do the simulation using MSG_action_trace_run */
53         res = MSG_action_trace_run(argv[3]);
54
55         INFO1("Simulation time %g",MSG_get_clock());
56         MSG_clean();
57
58         if(res==MSG_OK)
59                 return 0;
60         else
61                 return 1;
62 } /* end_of_main */