Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
initialize.cpp
1 // Copyright (c) 2019-2024, Lawrence Livermore National Security, LLC and
2 // other Serac Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
8 
9 #ifdef WIN32
10 #include <windows.h>
11 #include <tchar.h>
12 #else
13 #include <unistd.h>
14 #include <limits.h>
15 #endif
16 
21 
22 #include "mfem.hpp"
23 
24 namespace serac {
25 
26 std::pair<int, int> getMPIInfo(MPI_Comm comm)
27 {
28  int num_procs = 0;
29  int rank = 0;
30  if (MPI_Comm_size(comm, &num_procs) != MPI_SUCCESS) {
31  SLIC_ERROR("Failed to determine number of MPI processes");
32  }
33 
34  if (MPI_Comm_rank(comm, &rank) != MPI_SUCCESS) {
35  SLIC_ERROR("Failed to determine MPI rank");
36  }
37  return {num_procs, rank};
38 }
39 
40 std::pair<int, int> initialize(int argc, char* argv[], MPI_Comm comm)
41 {
42  // Initialize MPI.
43  if (MPI_Init(&argc, &argv) != MPI_SUCCESS) {
44  std::cerr << "Failed to initialize MPI" << std::endl;
46  }
47 
48  // Initialize the signal handler
50 
51  // Initialize SLIC logger
52  if (!logger::initialize(comm)) {
54  }
55 
56  // Start the profiler (no-op if not enabled)
58 
59  mfem::Hypre::Init();
60 
61 #ifdef SERAC_USE_SUNDIALS
62  mfem::Sundials::Init();
63 #endif
64 
65  // Initialize GPU (no-op if not enabled/available)
66  // TODO for some reason this causes errors on Lassen. We need to look into this ASAP.
67  // accelerator::initializeDevice();
68 
69  return getMPIInfo(comm);
70 }
71 
72 } // namespace serac
This file contains the interface used for initializing/terminating any hardware accelerator-related f...
A function intended to be used as part of a driver to initialize common libraries.
This file contains the all the necessary functions and macros required for logging as well as a helpe...
void initialize([[maybe_unused]] MPI_Comm comm, [[maybe_unused]] std::string options)
Initializes performance monitoring using the Caliper and Adiak libraries.
Definition: profiling.cpp:23
void registerSignals()
Registers the signalHandler function to handle various fatal signals.
Definition: terminator.cpp:34
Accelerator functionality.
Definition: serac.cpp:38
void exitGracefully(bool error)
Exits the program gracefully after cleaning up necessary tasks.
Definition: terminator.cpp:44
std::pair< int, int > initialize(int argc, char *argv[], MPI_Comm comm)
Initializes MPI, signal handling, and logging.
Definition: initialize.cpp:40
std::pair< int, int > getMPIInfo(MPI_Comm comm)
Returns the number of processes and rank for an MPI communicator.
Definition: initialize.cpp:26
Various helper functions and macros for profiling using Caliper.
Helper functions for exiting Serac cleanly.