Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PetscInitializer.cc
Go to the documentation of this file.
1/* Copyright (C) 2014, 2015, 2017, 2023, 2024 PISM Authors
2 *
3 * This file is part of PISM.
4 *
5 * PISM is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with PISM; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include "pism/util/petscwrappers/PetscInitializer.hh"
21
22#include <petscsys.h>
23#include <mpi.h>
24#include <cstdio>
25
26#include "pism/util/error_handling.hh"
27
28#if (Pism_USE_YAC_INTERPOLATION == 1)
29#include "pism/util/yaxt_wrapper.h"
30#endif
31
32namespace pism {
33namespace petsc {
34
35Initializer::Initializer(int argc, char **argv, const char *help) {
36
37 PetscErrorCode ierr = 0;
38 PetscBool initialized = PETSC_FALSE;
39
40 ierr = PetscInitialized(&initialized);
41 PISM_CHK(ierr, "PetscInitialized");
42
43 if (initialized == PETSC_FALSE) {
44 ierr = PetscInitialize(&argc, &argv, NULL, help);
45 PISM_CHK(ierr, "PetscInitialize");
46
47 if (ierr != 0) {
48 printf("PETSc initialization failed. Aborting...\n");
49 MPI_Abort(MPI_COMM_WORLD, -1);
50 }
51 }
52
53#if (Pism_USE_YAC_INTERPOLATION == 1)
54 int yaxt_initialized = pism_yaxt_initialized();
55 if (yaxt_initialized != 1) {
56 pism_yaxt_initialize(PETSC_COMM_WORLD);
57 }
58#endif
59}
60
62
63#if (Pism_USE_YAC_INTERPOLATION == 1)
64 int yaxt_initialized = pism_yaxt_initialized();
65 int yaxt_finalized = pism_yaxt_finalized();
66 if (yaxt_initialized == 1 and yaxt_finalized != 1) {
68 }
69#endif
70
71 PetscBool petsc_initialized = PETSC_FALSE;
72 PetscErrorCode ierr = PetscInitialized(&petsc_initialized); CHKERRCONTINUE(ierr);
73
74 if (petsc_initialized == PETSC_TRUE) {
75 // there is nothing we can do if this fails
76 ierr = PetscFinalize(); CHKERRCONTINUE(ierr);
77 }
78}
79
80} // end of namespace petsc
81} // end of namespace pism
static char help[]
Definition btutest.cc:21
Initializer(int argc, char **argv, const char *help)
#define PISM_CHK(errcode, name)
std::string printf(const char *format,...)
void pism_yaxt_initialize(MPI_Comm default_comm)
int pism_yaxt_initialized(void)
int pism_yaxt_finalized(void)
void pism_yaxt_finalize(void)