Mantid
Loading...
Searching...
No Matches
ParallelRunner.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include "MantidParallel/ThreadingBackend.h"
9
10#include <algorithm>
11
12using namespace Mantid::Parallel;
13
14namespace ParallelTestHelpers {
15
17 Communicator comm;
18 // Fake parallelism via threads if there is only 1 MPI rank
19 if (comm.size() == 1) {
20 // 3 is an arbitrary choice. We need more than 1 since that would be a
21 // trivial case, 2 seems like a special case that might make some bugs
22 // invisible.
23 int threads = std::max(3, static_cast<int>(std::thread::hardware_concurrency()));
24 m_backend = std::make_shared<detail::ThreadingBackend>(threads);
25 }
26 m_serialBackend = std::make_shared<detail::ThreadingBackend>(1);
27}
28
30 Communicator comm;
31 // Fake parallelism via threads if there is only 1 MPI rank, but fail if there
32 // are MPI ranks that do not match the number of requested threads.
33 if (comm.size() != 1 && comm.size() != threads)
34 throw("ParallelRunner: number of requested threads does not match number "
35 "of MPI ranks");
36 if (comm.size() == 1)
37 m_backend = std::make_shared<detail::ThreadingBackend>(threads);
38 m_serialBackend = std::make_shared<detail::ThreadingBackend>(1);
39}
40
42 if (m_backend)
43 return m_backend->size();
44 Communicator comm;
45 return comm.size();
46}
47
48} // namespace ParallelTestHelpers
std::shared_ptr< Mantid::Parallel::detail::ThreadingBackend > m_backend
std::shared_ptr< Mantid::Parallel::detail::ThreadingBackend > m_serialBackend