Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/gadget.cc
[mareframe] / trunk / gadget / gadget.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/gadget.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (view) (download)

1 : agomez 1 #include "ecosystem.h"
2 :     #include "maininfo.h"
3 :     #include "runid.h"
4 :     #include "gadget.h"
5 :     #include "errorhandler.h"
6 :     #include "stochasticdata.h"
7 :     #include "interrupthandler.h"
8 :     #include "global.h"
9 : ulcessvp 16 #ifdef _OPENMP
10 : ulcessvp 11 #include <omp.h>
11 :     #endif
12 : agomez 1
13 :     Ecosystem* EcoSystem;
14 : ulcessvp 11 StochasticData* data = 0;
15 :     Ecosystem** EcoSystems;
16 : agomez 1
17 :    
18 :     int main(int aNumber, char* const aVector[]) {
19 :    
20 :     MainInfo main;
21 : ulcessvp 11
22 :     // omp_set_num_threads(4);
23 :    
24 : agomez 1 int check = 0;
25 :    
26 :     //Initialise random number generator with system time [MNAA 02.02.26]
27 :     srand((int)time(NULL));
28 :    
29 :     //Test to see if the function double lgamma(double) is returning an integer.
30 :     //lgamma is a non-ansi function and on some platforms when compiled with the
31 :     //-ansi flag lgamma returns an integer value. [MNAA&AJ 05.2001]
32 :     assert(lgamma(1.2) != floor(lgamma(1.2)));
33 :    
34 :     char* workingdir = getenv("GADGET_WORKING_DIR");
35 :     if (workingdir == 0) {
36 :     if ((workingdir = (char*)malloc(LongString)) == NULL)
37 :     handle.logMessage(LOGFAIL, "Error - failed to malloc space for current working directory");
38 :     check = 1;
39 :     if (getcwd(workingdir, LongString) == NULL)
40 :     handle.logMessage(LOGFAIL, "Error - failed to get current working directory");
41 :     }
42 :     if (chdir(workingdir) != 0)
43 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
44 :    
45 :     char* inputdir = getenv("GADGET_DATA_DIR");
46 :     if (inputdir == 0)
47 :     inputdir = workingdir;
48 :     if (chdir(inputdir) != 0)
49 :     handle.logMessage(LOGFAIL, "Error - failed to change input directory to", inputdir);
50 :     if (chdir(workingdir) != 0) //JMB change back to where we were ...
51 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
52 :    
53 :     main.read(aNumber, aVector);
54 :     main.checkUsage(inputdir, workingdir);
55 :    
56 :     if (chdir(inputdir) != 0)
57 :     handle.logMessage(LOGFAIL, "Error - failed to change input directory to", inputdir);
58 :     EcoSystem = new Ecosystem(main);
59 :    
60 :     #ifdef INTERRUPT_HANDLER
61 :     //JMB dont register interrupt if doing a network run
62 :     if (!(main.runNetwork()))
63 :     registerInterrupts(&EcoSystem->interrupted);
64 :     #endif
65 :    
66 :     if (chdir(workingdir) != 0)
67 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
68 :     if ((main.getPI()).getPrint())
69 :     EcoSystem->writeInitialInformation((main.getPI()).getOutputFile());
70 :    
71 :     if (main.runStochastic()) {
72 :     if (main.runNetwork()) {
73 :     #ifdef GADGET_NETWORK //to help compiling when pvm libraries are unavailable
74 :     EcoSystem->Initialise();
75 :     data = new StochasticData();
76 :     while (data->getDataFromNetwork()) {
77 :     EcoSystem->Update(data);
78 :     EcoSystem->Simulate(main.runPrint());
79 :     data->sendDataToNetwork(EcoSystem->getLikelihood());
80 :     data->readNextLineFromNetwork();
81 :     }
82 :     delete data;
83 :     #endif
84 :    
85 :     } else if (main.getInitialParamGiven()) {
86 :     if (chdir(inputdir) != 0) //JMB need to change back to inputdir to read the file
87 :     handle.logMessage(LOGFAIL, "Error - failed to change input directory to", inputdir);
88 :     data = new StochasticData(main.getInitialParamFile());
89 :     if (chdir(workingdir) != 0)
90 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
91 :    
92 :     EcoSystem->Update(data);
93 :     EcoSystem->checkBounds();
94 :    
95 :     EcoSystem->Initialise();
96 :     if (main.printInitial()) {
97 :     EcoSystem->Reset(); //JMB only need to call reset() before the print commands
98 :     EcoSystem->writeStatus(main.getPrintInitialFile());
99 :     }
100 :    
101 :     EcoSystem->Simulate(main.runPrint());
102 :     if ((main.getPI()).getPrint())
103 :     EcoSystem->writeValues();
104 :    
105 :     while (data->isDataLeft()) {
106 :     data->readNextLine();
107 :     EcoSystem->Update(data);
108 :     EcoSystem->checkBounds();
109 :     EcoSystem->Simulate(main.runPrint());
110 :     if ((main.getPI()).getPrint())
111 :     EcoSystem->writeValues();
112 :     }
113 :     delete data;
114 :    
115 :     } else {
116 :     if (EcoSystem->numVariables() != 0)
117 :     handle.logMessage(LOGWARN, "Warning - no parameter input file given, using default values");
118 :    
119 :     EcoSystem->Initialise();
120 :     if (main.printInitial()) {
121 :     EcoSystem->Reset(); //JMB only need to call reset() before the print commands
122 :     EcoSystem->writeStatus(main.getPrintInitialFile());
123 :     }
124 :    
125 :     EcoSystem->Simulate(main.runPrint());
126 :     if ((main.getPI()).getPrint())
127 :     EcoSystem->writeValues();
128 :     }
129 :    
130 :     } else if (main.runOptimise()) {
131 : ulcessvp 11 if (EcoSystem->numVariables() == 0)
132 :     handle.logMessage(LOGFAIL, "Error - no parameters can be optimised");
133 : agomez 1
134 : ulcessvp 11 if (main.getInitialParamGiven()) {
135 :     if (chdir(inputdir) != 0) //JMB need to change back to inputdir to read the file
136 :     handle.logMessage(LOGFAIL, "Error - failed to change input directory to", inputdir);
137 :     data = new StochasticData(main.getInitialParamFile());
138 :     if (chdir(workingdir) != 0)
139 :     handle.logMessage(LOGFAIL, "Error - failed to change working directory to", workingdir);
140 : agomez 1
141 : ulcessvp 11 EcoSystem->Update(data);
142 :     EcoSystem->checkBounds();
143 :     } else
144 :     handle.logMessage(LOGFAIL, "Error - no parameter input file specified");
145 : agomez 1
146 : ulcessvp 11 EcoSystem->Initialise();
147 :     if (main.printInitial()) {
148 :     EcoSystem->Reset(); //JMB only need to call reset() before the print commands
149 :     EcoSystem->writeStatus(main.getPrintInitialFile());
150 :     }
151 : agomez 1
152 : ulcessvp 16 #ifdef _OPENMP
153 : ulcessvp 12 int numThr = omp_get_max_threads ( );
154 :     EcoSystems = new Ecosystem*[numThr];
155 :     int i;
156 :     for (i=0; i<numThr; i++)
157 :     {
158 :     EcoSystems[i] = new Ecosystem(main);
159 :     EcoSystems[i]->Update(data);
160 :     EcoSystems[i]->Initialise();
161 : ulcessvp 11 }
162 : ulcessvp 12 #endif
163 :     EcoSystem->Optimise();
164 : ulcessvp 11 delete data;
165 :     if (main.getForcePrint())
166 :     EcoSystem->Simulate(main.getForcePrint());
167 : agomez 1 }
168 :    
169 :     handle.logMessage(LOGMESSAGE, ""); //write blank line to log file
170 :     if (main.printFinal() && !(main.runNetwork()))
171 :     EcoSystem->writeStatus(main.getPrintFinalFile());
172 :    
173 :     //JMB print final values of parameters
174 :     if (!(main.runNetwork()))
175 :     EcoSystem->writeParams((main.getPI()).getParamOutFile(), (main.getPI()).getPrecision());
176 :    
177 :     if (check)
178 :     free(workingdir);
179 :    
180 :     delete EcoSystem;
181 :     handle.logFinish();
182 :     return EXIT_SUCCESS;
183 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge