BioDynaMo  v1.05.119-a4ff3934
partition.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_UTIL_PARTITION_H_
16 #define CORE_UTIL_PARTITION_H_
17 
18 #include <cmath>
19 
20 namespace bdm {
21 
22 inline void Partition(uint64_t elements, uint64_t batches, uint64_t batch_num,
23  uint64_t* start, uint64_t* end) {
24  auto correction = elements % batches == 0 ? 0 : 1;
25  auto chunk = elements / batches + correction;
26  *start = batch_num * chunk;
27  *end = std::min(elements, *start + chunk);
28 }
29 
30 } // namespace bdm
31 
32 #endif // CORE_UTIL_PARTITION_H_
bdm::Partition
void Partition(uint64_t elements, uint64_t batches, uint64_t batch_num, uint64_t *start, uint64_t *end)
Definition: partition.h:22
bdm
Definition: agent.cc:39