AMDiS.cc 3.61 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
#if defined(HAVE_PARALLEL_DOMAIN_AMDIS) && defined(HAVE_PARALLEL_MTL4)
25
  mtl::par::environment* mtl_environment = NULL;
26
27
#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
    
    // 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...\"");
58
59
60
61
62
63
64

    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
65
66
67
68
	
    // first argument is init-filename
    po::positional_options_description p;
    p.add("init-file", 1);
69
    p.add("unknown", -1);
Praetorius, Simon's avatar
Praetorius, Simon committed
70
71
72

    // parse comandline
    po::variables_map vm;
73
    po::store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).allow_unregistered().run(), vm);
Praetorius, Simon's avatar
Praetorius, Simon committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    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
89
    
Thomas Witkowski's avatar
Thomas Witkowski committed
90
    if (initFileName == "") {
Praetorius, Simon's avatar
Praetorius, Simon committed
91
92
93
94
      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
95
96
97
    } else {
      Parameters::init(initFileName);
    }
98

99
100
    Parameters::get("parallel->log main rank", Msg::outputMainRank);

Praetorius, Simon's avatar
Praetorius, Simon committed
101
102
103
104
105
106
107
108
    // 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();
109
110
111
  }


112
113
114
115
116
117
118
119
120
121
122
123
  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);
  }


124
125
126
127
128
129
  void finalize()
  {
    FUNCNAME("AMDiS::finalize()");

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    MeshDistributor::globalMeshDistributor->exitParallelization();
Thomas Witkowski's avatar
Thomas Witkowski committed
130
    delete MeshDistributor::globalMeshDistributor;
131
#ifdef HAVE_PARALLEL_MTL4
Thomas Witkowski's avatar
Thomas Witkowski committed
132
    if (mtl_environment)
133
134
      delete mtl_environment;
#else
135
    PetscFinalize();
136
#endif
137
138
139
140
#endif
  }

}