Carmen Code
 All Classes Files Functions Variables Macros Pages
Functions
main.cpp File Reference

Main function. More...

#include "Carmen.h"
Include dependency graph for main.cpp:

Functions

int main (int argc, char *argv[])
 

Detailed Description

Main function.

Function Documentation

int main ( int  argc,
char *  argv[] 
)
107 {
108  // --- Init Cluster variable ---------------------------------------------------------
109 
110  // carmen 0 => local execution i.e. show time on screen
111  // carmen 1 => cluster execution i.e. refresh Performance.dat (default)
112 
113 #if defined PARMPI
114  // --- MPI Runtime system initialization
115  // size - total number of processors
116  // rnak - current CPU
117  MPI_Init(&argc,&argv);
118  MPI_Comm_size(MPI_COMM_WORLD, &size);
119  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
120 #else
121  size=1;
122  rank=0;
123 #endif
124 
125  if (argc == 2)
126  Cluster = atoi(argv[1]);
127 
128  // --- Print messages on screen- -----------------------------------------------------
129 
130  cout << "carmen: begin execution.\n\n";
131  printf("Carmen %4.2f \n",CarmenVersion);
132  cout << "Copyright (C) 2000-2005 by Olivier Roussel.\n";
133  cout << "All rights reserved.\n\n";
134 
135 #if defined PARMPI
136  //Synchronize all parallel branches
137  MPI_Barrier(MPI_COMM_WORLD);
138 #endif
139 
140  CPUTime.start();
141 
142  // --- Create first node of the tree structure ---------------------------------------
143 
144  Node *Mesh=0;
145  FineMesh *FMesh=0;
146 
147 
148  // --- Init global values (See Parameters.h and Parameters.cpp) ----------------------------
149 
150  cout << "carmen: init computation ...\n";
151  InitParameters();
152 
153  // --- Debug output information for parallel execution -------------------------------------
154 
155 #if defined PARMPI
156  if (Multiresolution)
157  {
158  printf("\nParallel Multiresolution solver not implemented yet!\n");
159  exit(0);
160  }
161 
162  printf("My Rank=%d\n",rank);
163 
164  // --- Each CPU print his coordinates in the virtual processor cart ------------------------
165  printf("Cart_i = %d; Cart_j = %d; Cart_k = %d;\n",coords[0],coords[1],coords[2]);
166 
167  // --- Each CPU print his computation domain
168  printf("Xmin = %lf; XMax = %lf;\n",XMin[1],XMax[1]);
169  printf("Ymin = %lf; YMax = %lf;\n",XMin[2],XMax[2]);
170  printf("Zmin = %lf; ZMax = %lf;\n",XMin[3],XMax[3]);
171 
172  // --- And the local scale number ----------------------------------------------------------
173  printf("ScaleNb = %d\n",ScaleNb);
174 #endif
175 
176  // --- Allocate ----------------------------------------------------------------------------
177 
178  if (Multiresolution)
179  Mesh = new Node;
180  else
181  FMesh = new FineMesh;
182 
183  // --- Init tree structure -----------------------------------------------------------------
184 
185  if (Multiresolution)
186  {
187  InitTree(Mesh);
188  RefreshTree(Mesh);
189  }
190 
191  // --- Compute initial integral values and init time step ----------------------------------
192 
193  if (Multiresolution)
194  Mesh->computeIntegral();
195  else
196  FMesh->computeIntegral();
197 
198  // -- Write integral values --
199 
200 
201  // -- Compute initial time step --
202  InitTimeStep();
203 
204  if (rank==0) PrintIntegral("Integral.dat");
205 
206  // --- Save initial values into files ------------------------------------------------------
207 
208  if (PrintEvery == 0)
209  {
210  if (Multiresolution)
211  View(Mesh, "Tree_0.dat", "Mesh_0.dat", "Average_0.vtk");
212  else
213  View(FMesh,"Average_0.vtk");
214  }
215 
216  // --- When PrintEvery != 0, save initial values into specific name format ---
217 
218  if (PrintEvery != 0)
219  {
220  if (Multiresolution)
221  ViewEvery(Mesh, 0);
222  else
223  ViewEvery(FMesh, 0);
224  }
225 
226  // --- Parallel execution only --------------------------------------------
227  // --- Save to disk DX header for ouput files -----------------------------
228  // --- This file is needed for the external postprocessing (merging files from the different processors)
229 
230 #if defined PARMPI
231 
232  real tempXMin[4];
233  real tempXMax[4];
234 
235  // --- Save original task parameters for the parallel execution
236  int tempScaleNb=ScaleNb;
237 
238  // --- Simulate sequantial running
240 
241  for (int i=0;i<4;i++)
242  {
243  tempXMin[i]=XMin[i];
244  tempXMax[i]=XMax[i];
245  // --- Simulate sequantial running
246  XMin[i]=AllXMin[i];
247  XMax[i]=AllXMax[i];
248  }
249 
250  // --- Write header with parameters, as we have run sequantial code
251  if (rank==0) FMesh->writeHeader("header.txt");
252 
253  // Restore variables
254  for (int i=0;i<4;i++)
255  {
256  XMin[i]=tempXMin[i];
257  XMax[i]=tempXMax[i];
258  }
259 
260  ScaleNb=tempScaleNb;
261 
262 #endif
263 
264  // --- Done ---
265 
266  cout << "carmen: done.\n";
267 
268  // --- Write solver type ---
269 
270  if (Multiresolution)
271  cout << "carmen: multiresolution (MR) solver.\n";
272  else
273  cout << "carmen: finite volume (FV) solver.\n";
274 
275  // --- Write number of iterations ---
276 
277  if (IterationNb == 1)
278  cout << "carmen: compute 1 iteration ...\n";
279  else
280  cout << "carmen: compute " << IterationNb << " iterations ...\n";
281 
282  printf("\n\n\n");
283 
284  // --- Begin time iteration ----------------------------------------------------------------
285 
287  {
288  // initializing eigenvalues - slopes
289  EigenvalueX = 0.;
290  EigenvalueY = 0.;
291  EigenvalueZ = 0.;
292  DIVBMax = 0.;
293 
294  // --- Time evolution procedure ---
295  if (Multiresolution)
296  TimeEvolution(Mesh);
297  else
298  TimeEvolution(FMesh);
299 
300  // --- Remesh ---
301  if (Multiresolution) Remesh(Mesh);
302 
303  // --- Check CPU Time ---
304  CPUTime.check();
305 
306  // --- Write information every (Refresh) iteration ---
307  if ((IterationNo-1)%Refresh == 0)
308  {
309  // - Write integral values -
310  if (rank==0) PrintIntegral("Integral.dat");
311 
312  if (Cluster == 0)
313  ShowTime(CPUTime); // Show time on screen
314  //else
315  if (rank==0) Performance("carmen.prf"); // Refresh file "carmen.prf"
316  }
317 
318  // --- Backup data every (10*Refresh) iteration ---
319  if ((IterationNo-1)%(10*Refresh) == 0 && UseBackup)
320  {
321  if (Multiresolution)
322  Backup(Mesh);
323  else
324  Backup(FMesh);
325  }
326 
327  // --- Print solution if IterationNo = PrintIt1 to PrintIt6 ---
328  if (Multiresolution)
329  ViewIteration(Mesh);
330  else
331  ViewIteration(FMesh);
332 
333  // --- Print solution if IterationNo is a multiple of PrintEvery ---
334 
335  if (PrintEvery != 0)
336  {
337  if (IterationNo%PrintEvery == 0)
338  {
339  if (Multiresolution)
340  ViewEvery(Mesh, IterationNo);
341  else
342  ViewEvery(FMesh, IterationNo);
343  }
344  }
345 
346  //if(ElapsedTime>=PhysicalTime)break;
347 
348  // --- End time iteration ------------------------------------------------------------------
349  }
350 
351  // --- Backup final data ------------------------------------------------------------------
352 
353  IterationNo--;
354 
355  if (UseBackup)
356  {
357  if (Multiresolution)
358  Backup(Mesh);
359  else
360  Backup(FMesh);
361  }
362 
363  // --- Write integral values ---------------------------------------------------------------
364 
365  if (rank==0) PrintIntegral("Integral.dat");
366 
367  IterationNo++;
368 
369  // --- Save values into file ---------------------------------------------------------------
370 
371  if (Multiresolution)
372  View(Mesh, "Tree.dat", "Mesh.dat", "Average.vtk");
373  else
374  View(FMesh, "Average.vtk");
375 
376  cout << "\ncarmen: done.\n";
377 
378  // --- Analyse performance and save it into file -------------------------------------------
379 
380  if (rank==0) Performance("carmen.prf");
381 
382  // --- End ---------------------------------------------------------------------------------
383 
384  if (Multiresolution)
385  delete Mesh;
386  else
387  delete FMesh;
388 
389 
390 #if defined PARMPI
391 
392  //free memory for the MPI runtime variables
393  delete[] disp;
394  delete[] blocklen;
395  int sz;
396  MPI_Buffer_detach(&MPIbuffer,&sz);
397  // for (int i = 0; i < 4*Dimension; i++) MPI_Request_free(&req[i]);
398  MPI_Finalize();
399 
400 #endif
401 
402  cout <<"carmen: end execution.\n";
403  return EXIT_SUCCESS;
404 }
int rank
Definition: Parameters.cpp:223
void RefreshTree(Node *Root)
Refresh the tree structure, i.e. compute the cell-averages of the internal nodes by projection and th...
Definition: RefreshTree.cpp:22
int IterationNb
Definition: Parameters.cpp:37
int ScaleNb
Definition: Parameters.cpp:87
real EigenvalueZ
Definition: Parameters.cpp:160
An object Node is an element of a graded tree structure, used for multiresolution computations...
Definition: Node.h:38
An object FineMesh is a regular fine mesh, used for finite volume computations. It is not used for mu...
Definition: FineMesh.h:40
real XMax[4]
Definition: Parameters.cpp:77
void Remesh(Node *Root)
Remesh the tree structure after a time evolution. The root node is Root. Only for multiresolution com...
Definition: Remesh.cpp:22
void InitTree(Node *Root)
Inits tree structure from initial condition, starting form the node Root. Only for multiresolution co...
Definition: InitTree.cpp:22
real DIVBMax
Definition: Parameters.cpp:137
void PrintIntegral(const char *FileName)
Writes the integral values, like e.g flame velocity, global error, into file FileName.
Definition: PrintIntegral.cpp:30
void computeIntegral()
Computes integral values like e.g. flame velocity, global error, etc.
Definition: FineMesh.cpp:965
int Cluster
Definition: Parameters.cpp:170
int coords[3]
Definition: Parameters.cpp:230
void TimeEvolution(FineMesh *Root)
Computes a time evolution on the regular fine mesh Root. Only for finite volume computations.
Definition: TimeEvolution.cpp:77
real AllXMax[4]
Definition: Parameters.cpp:226
int AllTaskScaleNb
Definition: Parameters.cpp:227
int IterationNo
Definition: Parameters.cpp:168
real CarmenVersion
Definition: Parameters.cpp:28
int Refresh
Definition: Parameters.cpp:42
void ViewIteration(FineMesh *Root)
Same as previous for a fine mesh Root. Only for finite volume computations.
Definition: ViewIteration.cpp:60
void ViewEvery(FineMesh *Root, int arg)
Same as previous for a fine mesh Root. Only for finite volume computations.
Definition: ViewEvery.cpp:53
real AllXMin[4]
Definition: Parameters.cpp:226
real XMin[4]
Definition: Parameters.cpp:76
void start()
Starts timer.
Definition: Timer.cpp:62
bool UseBackup
Definition: Parameters.cpp:58
void ShowTime(Timer arg)
Writes on screen the estimation of total and remaining CPU times. These informations are stored in th...
Definition: ShowTime.cpp:23
void computeIntegral()
Computes integral values like e.g. flame velocity, global error, etc.
Definition: Node.cpp:2470
void Performance(const char *FileName)
Computes the performance of the computation and, for cluster computations, write it into file FileNam...
Definition: Performance.cpp:22
void check()
Adds CPU time and real time to their buffers and resets. For long computations, it is recommended to ...
Definition: Timer.cpp:103
real EigenvalueY
Definition: Parameters.cpp:159
int size
Definition: Parameters.cpp:224
void InitTimeStep()
Inits time step and all the parameters which depend on it.
Definition: InitTimeStep.cpp:22
bool Multiresolution
Definition: Parameters.cpp:84
void View(FineMesh *Root, const char *AverageFileName)
Writes the current cel–averages of the fine mesh Root into file AverageFileName. Only for finite volu...
Definition: View.cpp:87
void Backup(Node *Root)
Stores the tree structure and data in order to restart a multiresolution computation.
Definition: Backup.cpp:30
void InitParameters()
Inits parameters from file carmen.par. If a parameter is not mentioned in this file, the default value is used.
Definition: Parameters.cpp:283
real EigenvalueX
Definition: Parameters.cpp:158
Timer CPUTime
Definition: Parameters.cpp:169
int PrintEvery
Definition: Parameters.cpp:56
void writeHeader(const char *FileName) const
Write header for GNUplot, Data Explorer, TecPLot and VTK into file FileName.
Definition: FineMesh.cpp:1096
#define real
Definition: PreProcessor.h:31