Flow123d
master-f44eb46
src
main.cc
Go to the documentation of this file.
1
/*!
2
*
3
* Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4
*
5
* This program is free software; you can redistribute it and/or modify it under
6
* the terms of the GNU General Public License version 3 as published by the
7
* Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
*
13
*
14
* @file main.cc
15
* @brief This file should contain only creation of Application object.
16
*/
17
18
19
#include "
coupling/application.hh
"
20
#include <
mpi.h
>
21
//#include "system/system.hh"
22
//#include "system/sys_profiler.hh"
23
//#include "system/python_loader.hh"
24
//#include "coupling/hc_explicit_sequential.hh"
25
//#include "coupling/balance.hh"
26
//#include "input/accessors.hh"
27
//#include "input/reader_to_storage.hh"
28
//#include "input/reader_internal_base.hh"
29
//#include "system/armadillo_tools.hh"
30
//
31
#include <iostream>
32
//#include <fstream>
33
//#include <regex>
34
//#include <boost/program_options/parsers.hpp>
35
//#include <boost/program_options/variables_map.hpp>
36
//#include <boost/program_options/options_description.hpp>
37
//#include <boost/filesystem.hpp>
38
#include <thread>
// std::this_thread::sleep_for
39
#include <chrono>
// std::chrono::seconds
40
41
42
43
44
45
void
mpi_terminate
() {
46
int
mpi_on;
47
MPI_Initialized
(&mpi_on);
48
if
(! mpi_on)
return
;
49
50
// Test if all processes are in the exception.
51
MPI_Request
request;
52
MPI_Ibarrier(
MPI_COMM_WORLD
, &request);
53
std::this_thread::sleep_for(std::chrono::microseconds(10));
54
int
done;
55
MPI_Status
status;
56
MPI_Test
(&request, &done, &status);
57
if
(! done) {
58
// Kill all if we can not synchronize.
59
MPI_Abort
(
MPI_COMM_WORLD
,
Application::exit_failure
);
60
}
61
// Peacefull end.
62
}
63
64
65
/**
66
* Wrap application variable into separate function in order to
67
* force correct call of destructors before main catch block which is necessary for
68
* aborting all MPI processes.
69
*/
70
void
application_run
(
int
argc,
char
**argv) {
71
Application
app;
72
app.
init
(argc, argv);
73
app.
run
();
74
}
75
76
//=============================================================================
77
78
/**
79
* FUNCTION "MAIN"
80
*/
81
int
main
(
int
argc,
char
**argv) {
82
try
{
83
application_run
(argc, argv);
84
}
catch
(Application::ExcNoRunOption) {
85
mpi_terminate
();
86
return
Application::exit_success
;
87
}
catch
(std::exception & e) {
88
_LOG
( Logger::MsgType::error ).every_proc() << e.what();
89
mpi_terminate
();
90
return
Application::exit_failure
;
91
}
catch
(...) {
92
_LOG
( Logger::MsgType::error ).every_proc() <<
"Unknown exception"
<< endl;
93
mpi_terminate
();
94
return
Application::exit_failure
;
95
}
96
97
// Say Goodbye
98
return
Application::exit_success
;
99
}
application.hh
Application
Definition:
application.hh:80
Application::exit_failure
static const int exit_failure
Definition:
application.hh:91
Application::exit_success
static const int exit_success
Return codes of application.
Definition:
application.hh:90
Application::init
void init(int argc, char **argv)
Definition:
application.cc:492
Application::run
void run()
Definition:
application.cc:521
_LOG
#define _LOG(type)
Internal macro defining universal record of log.
Definition:
logger.hh:272
mpi_terminate
void mpi_terminate()
Definition:
main.cc:45
main
int main(int argc, char **argv)
Definition:
main.cc:81
application_run
void application_run(int argc, char **argv)
Definition:
main.cc:70
mpi.h
MPI_Abort
#define MPI_Abort
Definition:
mpi.h:222
MPI_COMM_WORLD
#define MPI_COMM_WORLD
Definition:
mpi.h:123
MPI_Request
void * MPI_Request
Definition:
mpi.h:142
MPI_Initialized
#define MPI_Initialized
Definition:
mpi.h:233
MPI_Test
#define MPI_Test(request, flag, status)
Definition:
mpi.h:366
MPI_Status
Definition:
mpi.h:144
Generated by
1.9.1