forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScatter.cpp
38 lines (34 loc) · 1.77 KB
/
Scatter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidIndexing/Scatter.h"
#include "MantidIndexing/GlobalSpectrumIndex.h"
#include "MantidIndexing/IndexInfo.h"
#include "MantidIndexing/SpectrumNumber.h"
#include "MantidParallel/Communicator.h"
#include "MantidTypes/SpectrumDefinition.h"
namespace Mantid::Indexing {
/// Returns a scattered copy of `indexInfo` with storage mode `Distributed`.
IndexInfo scatter(const Indexing::IndexInfo &indexInfo) {
using namespace Parallel;
if (indexInfo.communicator().size() == 1 || indexInfo.storageMode() == Parallel::StorageMode::Distributed)
return indexInfo;
if (indexInfo.storageMode() == Parallel::StorageMode::MasterOnly)
throw std::runtime_error("Cannot scatter IndexInfo with unsupported storage mode " +
toString(StorageMode::MasterOnly));
std::vector<SpectrumNumber> spectrumNumbers;
for (size_t i = 0; i < indexInfo.size(); ++i)
spectrumNumbers.emplace_back(indexInfo.spectrumNumber(i));
IndexInfo scattered(spectrumNumbers, Parallel::StorageMode::Distributed, indexInfo.communicator());
const auto &globalSpectrumDefinitions = indexInfo.spectrumDefinitions();
std::vector<SpectrumDefinition> spectrumDefinitions;
for (size_t i = 0; i < indexInfo.size(); ++i)
if (scattered.isOnThisPartition(static_cast<GlobalSpectrumIndex>(i)))
spectrumDefinitions.emplace_back((*globalSpectrumDefinitions)[i]);
scattered.setSpectrumDefinitions(spectrumDefinitions);
return scattered;
}
} // namespace Mantid::Indexing