diff --git a/triqs/mpi/base.hpp b/triqs/mpi/base.hpp index 60b54b6e..f0736742 100644 --- a/triqs/mpi/base.hpp +++ b/triqs/mpi/base.hpp @@ -19,55 +19,11 @@ * ******************************************************************************/ #pragma once -#include -#include - -namespace boost { // forward declare in case we do not include boost. -namespace mpi { - class communicator; -} -} +#include "./communicator.hpp" namespace triqs { namespace mpi { - /// Environment - struct environment { - // MPICH does not allow Init without argc, argv, so we do not allow default constructors - // for portability, cf #133 - environment(int argc, char *argv[]) { MPI_Init(&argc, &argv); } - ~environment() { MPI_Finalize(); } - }; - - /// The communicator. Todo : add more constructors. - class communicator { - MPI_Comm _com = MPI_COMM_WORLD; - - public: - communicator() = default; - - MPI_Comm get() const { return _com; } - - inline communicator(boost::mpi::communicator); - - /// Cast to the boost mpi communicator - inline operator boost::mpi::communicator () const; - - int rank() const { - int num; - MPI_Comm_rank(_com, &num); - return num; - } - - int size() const { - int num; - MPI_Comm_size(_com, &num); - return num; - } - - void barrier() const { MPI_Barrier(_com); } - }; - /// a tag for each operation namespace tag { struct broadcast {}; diff --git a/triqs/mpi/communicator.hpp b/triqs/mpi/communicator.hpp new file mode 100644 index 00000000..6afad903 --- /dev/null +++ b/triqs/mpi/communicator.hpp @@ -0,0 +1,78 @@ +/******************************************************************************* + * + * TRIQS: a Toolbox for Research in Interacting Quantum Systems + * + * Copyright (C) 2014 by O. Parcollet + * + * TRIQS is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * TRIQS. If not, see . + * + ******************************************************************************/ +#pragma once +#include +#include + +namespace boost { // forward declare in case we do not include boost. +namespace mpi { + class communicator; +} +} + +namespace triqs { +namespace mpi { + + /// Environment + struct environment { + // MPICH does not allow Init without argc, argv, so we do not allow default constructors + // for portability, cf #133 + environment(int argc, char *argv[]) { MPI_Init(&argc, &argv); } + ~environment() { MPI_Finalize(); } + }; + + // + inline bool is_initialized() noexcept { + int flag; + MPI_Initialized(&flag); + return flag; + } + + /// The communicator. Todo : add more constructors. + class communicator { + MPI_Comm _com = MPI_COMM_WORLD; + + public: + communicator() = default; + + MPI_Comm get() const { return _com; } + + inline communicator(boost::mpi::communicator); + + /// Cast to the boost mpi communicator + inline operator boost::mpi::communicator() const; + + int rank() const { + int num; + MPI_Comm_rank(_com, &num); + return num; + } + + int size() const { + int num; + MPI_Comm_size(_com, &num); + return num; + } + + void barrier() const { MPI_Barrier(_com); } + }; +} +} diff --git a/triqs/utility/exceptions.hpp b/triqs/utility/exceptions.hpp index 4c5f979a..2e0014b0 100644 --- a/triqs/utility/exceptions.hpp +++ b/triqs/utility/exceptions.hpp @@ -19,10 +19,9 @@ * TRIQS. If not, see . * ******************************************************************************/ +#pragma once -#ifndef TRIQS_EXCEPTIONS_H -#define TRIQS_EXCEPTIONS_H - +#include "../mpi/communicator.hpp" #include "./stack_trace.hpp" #include #include @@ -37,7 +36,13 @@ namespace triqs { virtual ~exception() throw() {} template exception & operator <<( T const & x) { std::stringstream f; f<