Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
application.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2005-03-17
7 
8  Copyright (C) 2005,2006,2009 EPFL
9  Copyright (C) 2007,2008 Université Joseph Fourier (Grenoble I)
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Lesser General Public
13  License as published by the Free Software Foundation; either
14  version 3.0 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public
22  License along with this library; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
30 #ifndef __application_H
31 #define __application_H 1
32 
33 #include <boost/optional.hpp>
34 #include <boost/format.hpp>
35 #include <boost/ptr_container/ptr_list.hpp>
36 
37 #include <feel/feelcore/feel.hpp>
39 #include <feel/feelcore/about.hpp>
40 #include <feel/feelcore/simget.hpp>
41 
42 #include <iostream>
43 #include <boost/archive/binary_iarchive.hpp>
44 #include <boost/archive/binary_oarchive.hpp>
45 #include <boost/archive/text_iarchive.hpp>
46 #include <boost/archive/text_oarchive.hpp>
47 #include <boost/archive/xml_iarchive.hpp>
48 #include <boost/archive/xml_oarchive.hpp>
49 #include <boost/serialization/string.hpp> // Needed to send/receive strings!
50 
51 #include <boost/mpi.hpp>
52 #if defined(FEELPP_HAS_MPI_H)
53 #include <mpi.h>
54 #endif /* FEELPP_HAS_MPI_H */
55 
56 #if defined(FEELPP_HAS_TAU)
57 #include <Profile/Profiler.h>
58 #endif /* FEELPP_HAS_TAU */
59 
60 
61 namespace Feel
62 {
63 namespace mpi = boost::mpi;
72 {
73 public:
74 
75 
79 
81  typedef boost::ptr_list<Simget> simgets_type;
82 
84  typedef simgets_type::iterator simget_iterator;
85 
87 
91 
92  Application();
93 
100 #if defined( FEELPP_HAS_MPI )
101  Application( AboutData const& ad, MPI_Comm Comm = MPI_COMM_WORLD );
102 #else
103  Application( AboutData const& ad );
104 #endif
105 
113 #if defined( FEELPP_HAS_MPI )
114  Application( AboutData const& ad, po::options_description const& od, MPI_Comm Comm = MPI_COMM_WORLD );
115 #else
116  Application( AboutData const& ad, po::options_description const& od );
117 #endif
118 
127 #if defined( FEELPP_HAS_MPI )
128  Application( int argc, char** argv, AboutData const& ad, MPI_Comm Comm = MPI_COMM_WORLD );
129 #else
130  Application( int argc, char** argv, AboutData const& ad );
131 #endif
132 
142 #if defined( FEELPP_HAS_MPI )
143  Application( int argc, char** argv, AboutData const& ad, po::options_description const& od, MPI_Comm Comm = MPI_COMM_WORLD );
144 #else
145  Application( int argc, char** argv, AboutData const& ad, po::options_description const& od );
146 #endif
147 
152  Application( Application const & app );
153 
154  virtual ~Application();
155 
157 
161 
162 
164 
168 
175  po::options_description const& optionsDescription() const
176  {
177  return M_desc;
178  }
179 
186  po::variables_map const& vm() const
187  {
188  return M_vm;
189  }
190 
198  AboutData const& about() const
199  {
200  return M_about;
201  }
202 
206  int unknownArgc() const
207  {
208  return M_to_pass_further.size()+1;
209  }
210 
214  char** unknownArgv() const;
215 
219  uint16_type nProcess()
220  {
221  return uint16_type( M_comm.size() );
222  }
223 
227  uint16_type processId()
228  {
229  return uint16_type( M_comm.rank() );
230  }
231 
235  bool isMPIInitialized() const
236  {
237  return mpi::environment::initialized();
238  }
239 
246  static bool initialized()
247  {
248  return mpi::environment::initialized();
249  }
250 
257  static bool finalized()
258  {
259  return mpi::environment::finalized();
260  }
261 
271  static std::string processorName()
272  {
273 #if defined( FEELPP_HAS_MPI )
274  return mpi::environment::processor_name();
275 #else
276  // fallback
277  return std::string( "localhost" );
278 #endif
279  }
280 
282  std::string rootRepository() const;
283 
286  {
287  return M_simgets.begin();
288  }
289 
292  {
293  return M_simgets.end();
294  }
295 
298  {
299  return M_simgets.size();
300  }
301 
306  bool verbose() const
307  {
308  return M_vm.count( "verbose" );
309  }
310 
312 
316 
320  void setName1( std::string const& name1 );
321 
325  void setName2( std::string const& name2 );
326 
330  void setH( double h, int precision = 4 );
331 
335  void setDimension( int dim );
336 
337 
339 
343 
347  Application& changeRepository( boost::format );
348 
349 #if defined( FEELPP_HAS_MPI )
350  static MPI_Comm COMM_WORLD;
351 #endif // FEELPP_HAS_MPI
352 
356  WorldComm& comm()
357  {
358  return M_comm;
359  }
360 
364  WorldComm const& comm() const
365  {
366  return M_comm;
367  }
368 
372  void barrier()
373  {
374  M_comm.barrier();
375  }
376 
380  void add( Simget* simget );
381 
385  virtual void run();
386 
394  virtual void run( const double* X, unsigned long P, double* Y, unsigned long N );
395 
396  enum Stats
397  {
398  FLAT = 1<<1,
399  HEADER = 1<<2,
400  ERRORS = 1<<3,
401  TIME = 1<<4,
402  DATA = 1<<5,
403  NUMBERS = 1<<6,
404  ALL = ERRORS | TIME | DATA | NUMBERS
405  };
406 
410  void setStats( std::vector<std::string> const& keys );
411 
415  void printStats( std::ostream& out, size_type stats = ALL ) const;
416 
417 
421  void printStats( std::ostream& out, std::vector<std::string> const& keys, size_type stats = ALL ) const;
422 
426  std::string resultFileName() const;
427 
429 
430 
431 
432 protected:
433 
439  void doOptions( int argc, char** argv );
440 
446  void processGenericOptions();
447 
448 
455  void parseAndStoreOptions( po::command_line_parser parser, bool extra_parser = false );
456 
461  void setLogs();
462 
463 private:
464 
465  void initMPI( int, char**, MPI_Comm );
466  void initPETSc();
467  void initTrilinos();
468 
469 private:
470 
471  AboutData M_about;
472 
473  po::options_description M_desc;
474  po::variables_map M_vm;
475 
476  boost::optional<std::string> M_name1;
477  boost::optional<std::string> M_name2;
478  boost::optional<std::pair<double, int> > M_h;
479  boost::optional<int> M_dim;
480 
481  std::vector<std::string> M_to_pass_further;
482 
483 
484  boost::shared_ptr<mpi::environment> M_env;
485  WorldComm M_comm;
486 
487  simgets_type M_simgets;
488  std::map<std::string,std::vector<ptree::ptree> > M_stats;
489  std::vector<std::string> M_keys;
490 
491 };
492 }
493 #endif /* __Application_H */
Simulation Object.
Definition: simget.hpp:60
provides information about the Application
Definition: application.hpp:71
static bool initialized()
Definition: application.hpp:246
static bool finalized()
Definition: application.hpp:257
WorldComm & comm()
Definition: application.hpp:356
boost::ptr_list< Simget > simgets_type
Simget collection type.
Definition: application.hpp:81
void setLogs()
Definition: application.cpp:687
int unknownArgc() const
Definition: application.hpp:206
void add(Simget *simget)
Definition: application.cpp:877
std::string rootRepository() const
Definition: application.cpp:812
bool verbose() const
Definition: application.hpp:306
simget_iterator begin()
Definition: application.hpp:285
Application & changeRepository(boost::format)
Definition: application.cpp:818
uint16_type nProcess()
Definition: application.hpp:219
static std::string processorName()
Definition: application.hpp:271
Holds information needed by the &quot;About&quot; box and other classes.
Definition: about.hpp:173
void setName2(std::string const &name2)
Definition: application.cpp:665
simget_iterator end()
Definition: application.hpp:291
void setStats(std::vector< std::string > const &keys)
Definition: application.cpp:1232
po::options_description const & optionsDescription() const
Definition: application.hpp:175
void printStats(std::ostream &out, size_type stats=ALL) const
Definition: application.cpp:1237
void setH(double h, int precision=4)
Definition: application.cpp:671
std::string resultFileName() const
Definition: application.cpp:682
size_type nSimgets() const
Definition: application.hpp:297
char ** unknownArgv() const
Definition: application.cpp:636
po::variables_map const & vm() const
Definition: application.hpp:186
size_t size_type
Indices (starting from 0)
Definition: feelcore/feel.hpp:319
void setName1(std::string const &name1)
Definition: application.cpp:659
void barrier()
Definition: application.hpp:372
void doOptions(int argc, char **argv)
Definition: application.cpp:520
virtual void run()
Definition: application.cpp:947
void setDimension(int dim)
Definition: application.cpp:677
bool isMPIInitialized() const
Definition: application.hpp:235
WorldComm const & comm() const
Definition: application.hpp:364
AboutData const & about() const
Definition: application.hpp:198
uint16_type processId()
Definition: application.hpp:227
simgets_type::iterator simget_iterator
Simget iterator over the collection.
Definition: application.hpp:84

Generated on Sun Dec 22 2013 13:10:54 for Feel++ by doxygen 1.8.5