Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
713baed2c0f89357cad9ab858c75d350d3359984
[simgrid.git] / src / cxx / Simulation.cxx
1 /*
2  * Simulation.cxx
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           
5  * All right reserved. 
6  *
7  * This program is free software; you can redistribute 
8  * it and/or modify it under the terms of the license 
9  *(GNU LGPL) which comes with this package. 
10  *
11  */
12  
13  /* Simulation member functions implementation.
14   */  
15   
16
17 #include <Application.hpp>
18 #include <Environment.hpp>
19
20 #include <Msg.hpp>
21
22 #include <Simulation.hpp>
23
24
25 #include <msg/msg.h> 
26
27 namespace SimGrid
28 {
29         namespace Msg
30         {
31                 int Simulation::execute(int argc, char** argv)
32                 {
33                         if(argc < 3) 
34                         {
35                       info("Usage: Msg platform_file deployment_file");
36                       return 1;
37                     }
38                     
39                          // initialize the MSG simulator. Must be done before anything else (even logging).
40                 init(argc, argv);
41                         
42                         // the environment to load
43                         Environment env;
44                         
45                         // the application to deploy
46                         Application app;
47
48                         
49                         // try to load the environment described by the xml file (argv[1])
50                         try
51                         {
52                                 env.load(argv[1]);
53                         }
54                         catch(FileNotFoundException e)
55                         {
56                                 info(e.toString());
57                                 finalize();
58                                 return 1;
59                         }
60                                 
61                         // try to deploy the application described by the xml file deployment (argv[2])
62                         try
63                         {
64                                 app.deploy(argv[2]);
65                         }
66                         catch(FileNotFoundException e)
67                         {
68                                 info(e.toString());
69                                 finalize();
70                                 return 1;
71                         }
72                         
73                         //try to run the simulation the given application on the given environment
74                         try
75                         {
76                                 run();
77                         }
78                         catch(MsgException e)
79                         {
80                                 info(e.toString());
81                                 finalize();
82                                 return 1;
83                         }
84                         
85                         // finalize the MSG simulator
86                         try
87                         {
88                                 finalize();
89                         }
90                         catch(MsgException e)
91                         {
92                                 info(e.toString());
93                                 return 1;
94                         }
95                         
96                         return 0;
97                 }
98                 
99                 void Simulation::run(void)
100                 throw (MsgException)
101                 {
102                         if(MSG_OK != MSG_main())
103                                 throw MsgException("MSG_main() failed");
104                 }
105         } // namespace Msg
106 } // namespace SimGrid
107
108