LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
MPITestHelpers.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2019, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 
27 #ifndef LBANN_UNIT_TEST_MPI_TEST_HELPERS_HPP_
28 #define LBANN_UNIT_TEST_MPI_TEST_HELPERS_HPP_
29 
30 #include <lbann/comm.hpp>
32 
33 #include <stdexcept>
34 #include <string>
35 
36 #define LBANN_ASSERT_POINTER(ptr) \
37  do { \
38  if (!ptr) \
39  throw ::unit_test::utilities::BadPointer( \
40  __FILE__, __LINE__, #ptr); \
41  } while (false)
42 
43 namespace unit_test {
44 namespace utilities {
45 
46 struct BadPointer : std::runtime_error
47 {
48  BadPointer(std::string const& file, unsigned int line,
49  std::string const& var_name)
50  : std::runtime_error{
52  file, ":", line, ": \"", var_name, "\" is null.")}
53  {}
54 };
55 
58 
59 // Sizes are not signed.
60 template <typename T>
61 size_t as_size(T const& size) noexcept { return static_cast<size_t>(size); }
62 
64 namespace expert {
65 
70 void register_world_comm(lbann::lbann_comm& comm) noexcept;
71 
76 void reset_world_comm() noexcept;
77 } // namespace expert
78 } // namespace utilities
79 } // namespace unit_test
80 #endif // LBANN_UNIT_TEST_MPI_TEST_HELPERS_HPP_
BadPointer(std::string const &file, unsigned int line, std::string const &var_name)
std::string build_string(Args &&... args)
Build a string from the arguments.
Definition: exception.hpp:157
void register_world_comm(lbann::lbann_comm &comm) noexcept
Set the world communicator for this session.
size_t as_size(T const &size) noexcept
lbann::lbann_comm & current_world_comm()
Get the world communicator for this MPI session.
void reset_world_comm() noexcept
Clear the world communicator for this session.