Flow123d
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
system
application_base.cc
Go to the documentation of this file.
1
/*
2
* aplication_base.cc
3
*
4
*/
5
6
#include <petsc.h>
7
8
#include "
system/application_base.hh
"
9
#include "
system/sys_profiler.hh
"
10
11
12
ApplicationBase::ApplicationBase
(
int
argc,
char
** argv)
13
: log_filename_(
""
)
14
{ }
15
16
17
void
ApplicationBase::system_init
(
MPI_Comm
comm,
const
string
&log_filename ) {
18
int
ierr;
19
20
//for(int i=0;i<argc;i++) xprintf(Msg,"%s,",argv[i]);
21
petsc_initialized
=
true
;
22
sys_info
.
comm
=comm;
23
24
25
Xio::init
();
//Initialize XIO library
26
27
// TODO : otevrit docasne log file jeste pred ctenim vstupu (kvuli zachyceni chyb), po nacteni dokoncit
28
// inicializaci systemu
29
30
ierr=
MPI_Comm_rank
(comm, &(
sys_info
.
my_proc
));
31
ierr+=
MPI_Comm_size
(comm, &(
sys_info
.
n_proc
));
32
ASSERT
( ierr ==
MPI_SUCCESS
,
"MPI not initialized.\n"
);
33
34
// determine logfile name or switch it off
35
stringstream log_name;
36
37
if
( log_filename ==
"//"
) {
38
// -l option without given name -> turn logging off
39
sys_info
.
log
=NULL;
40
}
else
{
41
// construct full log name
42
log_name << log_filename <<
"."
<<
sys_info
.
my_proc
<<
".log"
;
43
sys_info
.
log_fname
=
FilePath
(log_name.str(),
FilePath::output_file
);
44
sys_info
.
log
=
xfopen
(
sys_info
.
log_fname
.c_str(),
"wt"
);
45
}
46
47
sys_info
.
verbosity
=0;
48
sys_info
.
pause_after_run
=0;
49
}
50
51
52
53
void
ApplicationBase::petsc_initialize
(
int
argc,
char
** argv) {
54
#ifdef HAVE_PETSC
55
PetscErrorCode ierr;
56
ierr = PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
57
58
int
mpi_size;
59
MPI_Comm_size
(PETSC_COMM_WORLD, &mpi_size);
60
xprintf
(
Msg
,
"MPI size: %d\n"
, mpi_size);
61
#endif
62
}
63
64
65
66
int
ApplicationBase::petcs_finalize
() {
67
#ifdef HAVE_PETSC
68
if
(
petsc_initialized
)
69
{
70
PetscErrorCode ierr=0;
71
72
ierr = PetscFinalize(); CHKERRQ(ierr);
73
74
petsc_initialized
=
false
;
75
76
return
ierr;
77
}
78
#endif
79
80
return
0;
81
}
82
83
84
void
ApplicationBase::init
(
int
argc,
char
** argv) {
85
Profiler::initialize
();
86
// parse our own command line arguments, leave others for PETSc
87
this->
parse_cmd_line
(argc, argv);
88
89
this->
petsc_initialize
(argc, argv);
90
91
this->
system_init
(PETSC_COMM_WORLD,
log_filename_
);
// Petsc, open log, read ini file
92
93
//try {
94
this->
run
();
95
//} catch (std::exception & e) {
96
// std::cerr << e.what();
97
// exit( exit_failure );
98
//}
99
100
this->
after_run
();
101
}
102
103
104
ApplicationBase::~ApplicationBase
() {
105
if
(
sys_info
.
log
)
xfclose
(
sys_info
.
log
);
106
petcs_finalize
();
107
}
108
Generated on Thu Apr 17 2014 01:28:45 for Flow123d by
1.8.4