Project
Loading...
Searching...
No Matches
ResourcePolicyHelpers.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include <regex>
16
17namespace o2::framework
18{
19
23{
24 return ResourcePolicy{
25 "trivial",
26 [matcher = std::regex(s)](DeviceSpec const& spec) -> bool {
27 return std::regex_match(spec.name, matcher);
28 },
30}
31
32ResourcePolicy ResourcePolicyHelpers::cpuBoundTask(char const* s, int requestedCPUs)
33{
34 return ResourcePolicy{
35 "cpu-bound",
36 [matcher = std::regex(s)](DeviceSpec const& spec) -> bool {
37 return std::regex_match(spec.name, matcher);
38 },
39 [requestedCPUs](ComputingQuotaOffer const& offer, ComputingQuotaOffer const& accumulated) -> OfferScore { return accumulated.cpu >= requestedCPUs ? OfferScore::Enough : OfferScore::More; }};
40}
41
42ResourcePolicy ResourcePolicyHelpers::rateLimitedSharedMemoryBoundTask(char const* s, int requestedSharedMemory, int requestedTimeslices)
43{
44 return ResourcePolicy{
45 "ratelimited-shm-bound",
46 [matcher = std::regex(s)](DeviceSpec const& spec) -> bool {
47 return std::regex_match(spec.name, matcher);
48 },
49 [requestedSharedMemory, requestedTimeslices](ComputingQuotaOffer const& offer, ComputingQuotaOffer const& accumulated) -> OfferScore {
50 // If we have enough memory and not enough timeslices,
51 // ignore further shared memory.
52 if (accumulated.sharedMemory >= requestedSharedMemory && offer.timeslices == 0) {
54 }
55 // If we have enough timeslices and not enough shared memory
56 // ignore further timeslices.
57 if (accumulated.timeslices >= requestedTimeslices && offer.sharedMemory == 0) {
59 }
60 // If it does not offer neither shared memory nor timeslices, mark it as unneeded.
61 if (offer.sharedMemory == 0 && offer.timeslices == 0) {
63 }
64 // We have enough to process.
65 if ((accumulated.sharedMemory + offer.sharedMemory) >= requestedSharedMemory && (accumulated.timeslices + offer.timeslices) >= requestedTimeslices) {
66 return OfferScore::Enough;
67 }
68 // We need more resources
69 return OfferScore::More; }};
70}
71
72ResourcePolicy ResourcePolicyHelpers::sharedMemoryBoundTask(char const* s, int requestedSharedMemory)
73{
74 return ResourcePolicy{
75 "shm-bound",
76 [matcher = std::regex(s)](DeviceSpec const& spec) -> bool {
77 return std::regex_match(spec.name, matcher);
78 },
79 [requestedSharedMemory](ComputingQuotaOffer const& offer, ComputingQuotaOffer const& accumulated) -> OfferScore {
80 if (offer.sharedMemory == 0) {
82 }
83 return (accumulated.sharedMemory + offer.sharedMemory)>= requestedSharedMemory ? OfferScore::Enough : OfferScore::More; }};
84}
85
86} // namespace o2::framework
Defining PrimaryVertex explicitly as messageable.
int64_t sharedMemory
How much shared memory it can allocate.
static ResourcePolicy rateLimitedSharedMemoryBoundTask(char const *taskMatcher, int maxMemory, int maxTimeslices)
static ResourcePolicy trivialTask(char const *taskMatcher)
static ResourcePolicy sharedMemoryBoundTask(char const *taskMatcher, int maxMemory)
static ResourcePolicy cpuBoundTask(char const *taskMatcher, int maxCPUs=1)