-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (80 loc) · 2.36 KB
/
Copy pathmain.cpp
File metadata and controls
96 lines (80 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// File : main.cpp
// Created : Thu Mar 26 2026 10:17:26 (+0100)
// Author : Fabian Wermelinger
// Description: Main application entry
// Copyright 2026 CCFNUM HSLU T&A. All Rights Reserved.
#include <Kokkos_Core.hpp>
#include <csignal>
#include <mpi.h>
#ifdef HAS_PETSC
#include <petscsys.h>
#if PETSC_VERSION_LT(3, 18, 1)
#define ErrorWrapPetscCall(c) CHKERRQ(c)
#else
#define ErrorWrapPetscCall(c) PetscCall(c)
#endif
#endif /* HAS_PETSC */
#ifdef HAS_HYPRE
#include <HYPRE_utilities.h>
#endif /* HAS_HYPRE */
// code libraries
#include "macros.h"
#include "simulation.h"
namespace
{
// Global pointer used by the signal handler to trigger a clean shutdown.
::accel::simulation* g_realm = nullptr;
void handleSignal(int sig)
{
delete g_realm;
g_realm = nullptr;
// Restore the default handler and re-raise so the process exits with the
// correct status (e.g. SIGINT still shows as interrupted to the shell).
std::signal(sig, SIG_DFL);
std::raise(sig);
}
} // namespace
int main(int argc, char* argv[])
{
// The package tackles real world physics in 2D or 3D
assert(SPATIAL_DIM >= 2);
using Sim = ::accel::simulation;
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided);
if (provided < MPI_THREAD_FUNNELED)
{
accel::errorMsg("Provided MPI thread-level support is not sufficient");
}
#ifdef HAS_PETSC
// Initialize the Petsc environment
ErrorWrapPetscCall(PetscInitialize(&argc, &argv, NULL, NULL));
#endif /* HAS_PETSC */
#ifdef HAS_HYPRE
HYPRE_Initialize();
#endif /* HAS_HYPRE */
Kokkos::initialize(argc, argv);
{
// create and run simulation
Sim* realm = new Sim(argc, const_cast<const char**>(argv));
// Register signal handlers so that SIGINT/SIGTERM trigger the
// simulation destructor (which closes any open gnuplot windows).
g_realm = realm;
std::signal(SIGINT, handleSignal);
std::signal(SIGTERM, handleSignal);
realm->run();
g_realm = nullptr;
std::signal(SIGINT, SIG_DFL);
std::signal(SIGTERM, SIG_DFL);
delete realm;
}
Kokkos::finalize();
#ifdef HAS_HYPRE
HYPRE_Finalize();
#endif /* HAS_HYPRE */
#ifdef HAS_PETSC
// Finalize the Petsc environment.
ErrorWrapPetscCall(PetscFinalize());
#endif /* HAS_PETSC */
MPI_Finalize();
return 0;
}