AMDiS.cc 3.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


#include "AMDiS.h"
#include <string>
#ifdef HAVE_ZOLTAN
#include <zoltan_cpp.h>
#endif
Praetorius, Simon's avatar
Praetorius, Simon committed
18
#include "boost/program_options.hpp"
19
20
21
22
23

namespace AMDiS {

  using namespace std;

24
25
26
27
#if defined(HAVE_PARALLEL_DOMAIN_AMDIS) && defined(HAVE_PARALLEL_MTL4)
  mtl::par::environment* mtl_environment=NULL;
#endif

Thomas Witkowski's avatar
Thomas Witkowski committed
28
  void init(int argc, char **argv, std::string initFileName)
29
30
31
32
  {
    FUNCNAME("AMDiS::init()");

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
33
34
35
#ifdef HAVE_PARALLEL_MTL4
    mtl_environment = new mtl::par::environment(argc, argv);
#else
36
37
    PetscInitialize(&argc, &argv, NULL, NULL);
    mpi::startRand();
38
#endif
39
40
41
42
43
44

#ifdef HAVE_ZOLTAN
    float zoltanVersion = 0.0;
    Zoltan_Initialize(argc, argv, &zoltanVersion);
#endif
#endif
Praetorius, Simon's avatar
Praetorius, Simon committed
45
46
    
    Parameters::clearData();
Praetorius, Simon's avatar
Praetorius, Simon committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    
    // 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...\"");
	
    // first argument is init-filename
    po::positional_options_description p;
    p.add("init-file", 1);

    // parse comandline
    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
    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
81
    
Thomas Witkowski's avatar
Thomas Witkowski committed
82
    if (initFileName == "") {
Praetorius, Simon's avatar
Praetorius, Simon committed
83
84
85
86
      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
87
88
89
    } else {
      Parameters::init(initFileName);
    }
90

Praetorius, Simon's avatar
Praetorius, Simon committed
91
92
93
94
95
96
97
98
    // 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);
    
    // initialize global strcutures using parameters
    Global::init();
99
100
101
  }


102
103
104
105
106
107
108
109
110
111
112
113
  void init(std::string initFileName)
  {
    FUNCNAME("AMDiS::init()");

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    ERROR_EXIT("Does not work in parallel!\n");
#endif

    Parameters::init(initFileName);
  }


114
115
116
117
118
119
  void finalize()
  {
    FUNCNAME("AMDiS::finalize()");

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    MeshDistributor::globalMeshDistributor->exitParallelization();
120
#ifdef HAVE_PARALLEL_MTL4
Thomas Witkowski's avatar
Thomas Witkowski committed
121
    if (mtl_environment)
122
123
      delete mtl_environment;
#else
124
    PetscFinalize();
125
#endif
126
127
128
129
#endif
  }

}