diff --git a/Framework/API/CMakeLists.txt b/Framework/API/CMakeLists.txt index 458d5c37819dc17131cd49e2aec2faff18e29081..94ed3d4ef037105f540199cd69cac2063d0a9572 100644 --- a/Framework/API/CMakeLists.txt +++ b/Framework/API/CMakeLists.txt @@ -110,6 +110,7 @@ set ( SRC_FILES src/NullCoordTransform.cpp src/NumericAxis.cpp src/NumericAxisValidator.cpp + src/ParallelAlgorithm.cpp src/ParamFunction.cpp src/ParameterReference.cpp src/ParameterTie.cpp @@ -307,6 +308,7 @@ set ( INC_FILES inc/MantidAPI/NullCoordTransform.h inc/MantidAPI/NumericAxis.h inc/MantidAPI/NumericAxisValidator.h + inc/MantidAPI/ParallelAlgorithm.h inc/MantidAPI/ParamFunction.h inc/MantidAPI/ParameterReference.h inc/MantidAPI/ParameterTie.h diff --git a/Framework/API/inc/MantidAPI/ParallelAlgorithm.h b/Framework/API/inc/MantidAPI/ParallelAlgorithm.h new file mode 100644 index 0000000000000000000000000000000000000000..d3f5169666d320c15ed37d4e4e75e6a29f3ca037 --- /dev/null +++ b/Framework/API/inc/MantidAPI/ParallelAlgorithm.h @@ -0,0 +1,59 @@ +#ifndef MANTID_API_PARALLELALGORITHM_H_ +#define MANTID_API_PARALLELALGORITHM_H_ + +#include "MantidAPI/Algorithm.h" +#include "MantidAPI/DllConfig.h" + +namespace Mantid { +namespace API { + +/** Base class for algorithms that can run in parallel on all MPI ranks but not + in a distributed fashion. A prime example are most `Load` algorithms, which, + since they read input data from a file have no automatic way of doing so in a + distributed manner. Creating an actual distributed workspace + (Parallel::StorageMode::Distributed) would require a manual implementation + taking care of setting up a workspace and partitioning it correctly. + + When a specific algorithm is determined to be parallel (this is a manual + process), the only required change to add MPI support is to inherit from this + class instead of Algorithm. The algorithm will then support + Parallel::ExecutionMode::MasterOnly and Parallel::ExecutionMode::Identical, + provided that the mode can uniquely be determined from its input workspaces. + If there are no inputs it defaults to Parallel::ExecutionMode::Identical. + + @author Simon Heybrock + @date 2017 + + + Copyright © 2017 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge + National Laboratory & European Spallation Source + + This file is part of Mantid. + + Mantid 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. + + Mantid 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 this program. If not, see <http://www.gnu.org/licenses/>. + + File change history is stored at: <https://github.com/mantidproject/mantid> + Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class MANTID_API_DLL ParallelAlgorithm : public API::Algorithm { +protected: + Parallel::ExecutionMode getParallelExecutionMode( + const std::map<std::string, Parallel::StorageMode> &storageModes) + const override; +}; + +} // namespace API +} // namespace Mantid + +#endif /* MANTID_API_PARALLELALGORITHM_H_ */ diff --git a/Framework/API/src/ParallelAlgorithm.cpp b/Framework/API/src/ParallelAlgorithm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..19065dab2343189c067010eb9b09a5ef5c6a95c7 --- /dev/null +++ b/Framework/API/src/ParallelAlgorithm.cpp @@ -0,0 +1,29 @@ +#include "MantidAPI/ParallelAlgorithm.h" + +#include <algorithm> + +namespace Mantid { +namespace API { + +Parallel::ExecutionMode ParallelAlgorithm::getParallelExecutionMode( + const std::map<std::string, Parallel::StorageMode> &storageModes) const { + using namespace Parallel; + // Match all cloned or empty. + if (std::all_of( + storageModes.begin(), storageModes.end(), + [](const std::pair<std::string, Parallel::StorageMode> &item) { + return item.second == StorageMode::Cloned; + })) + return getCorrespondingExecutionMode(StorageMode::Cloned); + // Match all master-only (empty handled earlier). + if (std::all_of( + storageModes.begin(), storageModes.end(), + [](const std::pair<std::string, Parallel::StorageMode> &item) { + return item.second == StorageMode::MasterOnly; + })) + return getCorrespondingExecutionMode(StorageMode::MasterOnly); + return ExecutionMode::Invalid; +} + +} // namespace API +} // namespace Mantid