AMDiS.cc 4.47 KB
Newer Older
1
2
3
4
5
6
7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9
10
11
12
13
14
15
16
17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
 ******************************************************************************/
20
21
22
23
24
25
26


#include "AMDiS.h"
#include <string>
#ifdef HAVE_ZOLTAN
#include <zoltan_cpp.h>
#endif
27
28
29
#ifdef MTL_HAS_HYPRE
#include "mpi.h"
#endif
Praetorius, Simon's avatar
Praetorius, Simon committed
30
#include "boost/program_options.hpp"
31

32
33
34
35
#if defined HAVE_PETSC || defined HAVE_SEQ_PETSC || defined HAVE_PARALLEL_PETSC
#include <petsc.h>
#endif

36
37
38
39
namespace AMDiS {

  using namespace std;

40
#if defined(HAVE_PARALLEL_MTL4)
41
  mtl::par::environment* mtl_environment = NULL;
42
43
#endif

Thomas Witkowski's avatar
Thomas Witkowski committed
44
  void init(int argc, char **argv, std::string initFileName)
45
  {
46
  #ifdef HAVE_PARALLEL_MTL4
47
    mtl_environment = new mtl::par::environment(argc, argv);
48
  #elif defined HAVE_PETSC || defined HAVE_SEQ_PETSC || defined HAVE_PARALLEL_PETSC
49
    PetscInitialize(&argc, &argv, NULL, NULL);
50
51
52
  #elif defined MTL_HAS_HYPRE
    MPI_Init(&argc, &argv);
  #endif
53

54
  #if defined(HAVE_PARALLEL_DOMAIN_AMDIS)
55
    Parallel::mpi::startRand();
56
  #else
57
    srand(time(0));
58
59
  #endif

60
  #ifdef HAVE_ZOLTAN
61
62
    float zoltanVersion = 0.0;
    Zoltan_Initialize(argc, argv, &zoltanVersion);
63
  #endif
64

Praetorius, Simon's avatar
Praetorius, Simon committed
65
    Parameters::clearData();
66

Praetorius, Simon's avatar
Praetorius, Simon committed
67
68
    // read commandline arguments
    namespace po = boost::program_options;
69

Praetorius, Simon's avatar
Praetorius, Simon committed
70
71
72
73
74
75
76
    // Declare the supported options.
    po::options_description desc("Usage: " + std::string(argv[0]) + " init-file [options]\nAllowed options");
    desc.add_options()
	("help", "produce help message")
	("init-file", po::value<std::string>(), "set init file")
	("rs", po::value<int>(), "set restart parameter")
	("parameters", po::value<std::string>(), "set parameter in init file\nsyntax: \"key1: value1; key2: value2...\"");
77
78
79
80

    po::options_description hidden("Hidden options");
    hidden.add_options()
	("unknown", po::value<std::vector<std::string> >(), "unknown options");
81

82
83
    po::options_description cmdline_options;
    cmdline_options.add(desc).add(hidden);
84

Praetorius, Simon's avatar
Praetorius, Simon committed
85
86
87
    // first argument is init-filename
    po::positional_options_description p;
    p.add("init-file", 1);
88
    p.add("unknown", -1);
Praetorius, Simon's avatar
Praetorius, Simon committed
89
90
91

    // parse comandline
    po::variables_map vm;
92
    po::store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).allow_unregistered().run(), vm);
93
    po::notify(vm);
Praetorius, Simon's avatar
Praetorius, Simon committed
94
95
96
97
98
99

    // print help message
    if (vm.count("help")) {
      cout << desc << "\n";
      exit(1);
    }
100

Praetorius, Simon's avatar
Praetorius, Simon committed
101
102
103
    // add parameter for restart simulations
    if (vm.count("rs"))
      Parameters::add("argv->rs", vm["rs"].as<int>(), 0);
104

Praetorius, Simon's avatar
Praetorius, Simon committed
105
106
107
    // set parameters before reading the initfile
    if (vm.count("parameters"))
      Parameters::readArgv(vm["parameters"].as<std::string>());
108

Thomas Witkowski's avatar
Thomas Witkowski committed
109
    if (initFileName == "") {
Praetorius, Simon's avatar
Praetorius, Simon committed
110
111
112
113
      if (vm.count("init-file"))
	Parameters::init(vm["init-file"].as<std::string>());
      else
	throw(std::runtime_error("No init file specified!"));
Thomas Witkowski's avatar
Thomas Witkowski committed
114
115
116
    } else {
      Parameters::init(initFileName);
    }
117

118
#if defined(HAVE_PARALLEL_DOMAIN_AMDIS) || defined(HAVE_OPENMP) || defined(HAVE_MPI)
119
    Parameters::get("parallel->log main rank", Msg::outputMainRank);
120
#endif
121

Praetorius, Simon's avatar
Praetorius, Simon committed
122
123
124
125
126
    // reset parameters from command line
    bool ignoreCommandline = false;
    Parameters::get("ignore commandline options", ignoreCommandline);
    if (vm.count("parameters") && !ignoreCommandline)
      Parameters::readArgv(vm["parameters"].as<std::string>(),0);
127
128


Praetorius, Simon's avatar
Praetorius, Simon committed
129
130
    // initialize global strcutures using parameters
    Global::init();
131
132
133
  }


134
135
136
  void init(std::string initFileName)
  {
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
137
    FUNCNAME("AMDiS::init()");
138
139
140
141
142
143
144
    ERROR_EXIT("Does not work in parallel!\n");
#endif

    Parameters::init(initFileName);
  }


145
146
147
  void finalize()
  {
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
148
149
    Parallel::MeshDistributor::globalMeshDistributor->exitParallelization();
    delete Parallel::MeshDistributor::globalMeshDistributor;
150
#endif
151

152
153
154
155
#ifdef HAVE_PARALLEL_MTL4
    if (mtl_environment)
      delete mtl_environment;
#elif defined HAVE_PETSC || defined HAVE_SEQ_PETSC || defined HAVE_PARALLEL_PETSC
156
    PetscFinalize();
157
158
#elif defined MTL_HAS_HYPRE
    MPI_Finalize();
159
#endif
160

161
162
163
  }

}