AMDiS.cc 4.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * 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.
 * 
 ******************************************************************************/
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

namespace AMDiS {

  using namespace std;

36
#if defined(HAVE_PARALLEL_MTL4)
37
  mtl::par::environment* mtl_environment = nullptr;
38
39
#endif

Thomas Witkowski's avatar
Thomas Witkowski committed
40
  void init(int argc, char **argv, std::string initFileName)
41
  {
42
  #ifdef HAVE_PARALLEL_MTL4
43
    mtl_environment = new mtl::par::environment(argc, argv);
44
  #elif defined HAVE_PETSC || defined HAVE_SEQ_PETSC || defined HAVE_PARALLEL_PETSC
45
    PetscInitialize(&argc, &argv, NULL, NULL);
46
47
48
49
50
  #elif defined MTL_HAS_HYPRE
    MPI_Init(&argc, &argv);
  #endif
    
  #if defined(HAVE_PARALLEL_DOMAIN_AMDIS)
51
    Parallel::mpi::startRand();
52
  #else
53
    srand(time(0));
54
55
  #endif    
    
56
  #ifdef HAVE_ZOLTAN
57
58
    float zoltanVersion = 0.0;
    Zoltan_Initialize(argc, argv, &zoltanVersion);
59
  #endif
Praetorius, Simon's avatar
Praetorius, Simon committed
60
61
    
    Parameters::clearData();
Praetorius, Simon's avatar
Praetorius, Simon committed
62
63
64
65
66
67
68
69
70
71
72
    
    // read commandline arguments
    namespace po = boost::program_options;
    
    // 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...\"");
73
74
75
76
77
78
79

    po::options_description hidden("Hidden options");
    hidden.add_options()
	("unknown", po::value<std::vector<std::string> >(), "unknown options");
	
    po::options_description cmdline_options;
    cmdline_options.add(desc).add(hidden);
Praetorius, Simon's avatar
Praetorius, Simon committed
80
81
82
83
	
    // first argument is init-filename
    po::positional_options_description p;
    p.add("init-file", 1);
84
    p.add("unknown", -1);
Praetorius, Simon's avatar
Praetorius, Simon committed
85
86
87

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

    // print help message
    if (vm.count("help")) {
      cout << desc << "\n";
      exit(1);
    }
    
    // add parameter for restart simulations
    if (vm.count("rs"))
      Parameters::add("argv->rs", vm["rs"].as<int>(), 0);
      
    // set parameters before reading the initfile
    if (vm.count("parameters"))
      Parameters::readArgv(vm["parameters"].as<std::string>());
Praetorius, Simon's avatar
Praetorius, Simon committed
104
    
Thomas Witkowski's avatar
Thomas Witkowski committed
105
    if (initFileName == "") {
Praetorius, Simon's avatar
Praetorius, Simon committed
106
107
108
109
      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
110
111
112
    } else {
      Parameters::init(initFileName);
    }
113

114
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
115
    Parameters::get("parallel->log main rank", Msg::outputMainRank);
116
#endif
117

Praetorius, Simon's avatar
Praetorius, Simon committed
118
119
120
121
122
123
    // 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);
    
124
    
Praetorius, Simon's avatar
Praetorius, Simon committed
125
126
    // initialize global strcutures using parameters
    Global::init();
127
128
129
  }


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

    Parameters::init(initFileName);
  }


141
142
143
  void finalize()
  {
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
144
145
    Parallel::MeshDistributor::globalMeshDistributor->exitParallelization();
    delete Parallel::MeshDistributor::globalMeshDistributor;
146
#endif
147
    
148
149
150
151
#ifdef HAVE_PARALLEL_MTL4
    if (mtl_environment)
      delete mtl_environment;
#elif defined HAVE_PETSC || defined HAVE_SEQ_PETSC || defined HAVE_PARALLEL_PETSC
152
    PetscFinalize();
153
154
#elif defined MTL_HAS_HYPRE
    MPI_Finalize();
155
#endif
156
    
157
158
159
  }

}