Project
Loading...
Searching...
No Matches
SimpleResourceManager.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.
13#include <fmt/format.h>
14#include <exception>
15#include <stdexcept>
16
17namespace o2::framework
18{
19
23std::vector<ComputingOffer> SimpleResourceManager::getAvailableOffers()
24{
25 std::vector<ComputingOffer> result;
26
27 for (auto& resource : mResources) {
28 if (resource.cpu < 0.01) {
29 continue;
30 }
31 if (resource.memory < 0.01) {
32 continue;
33 }
34 if (resource.usedPorts == (resource.lastPort - resource.startPort + 1)) {
35 continue;
36 }
37 ComputingOffer offer;
38 offer.cpu = resource.cpu;
39 offer.memory = resource.memory;
40 offer.hostname = resource.hostname;
41 offer.startPort = resource.startPort + resource.usedPorts;
42 offer.rangeSize = (resource.lastPort - resource.startPort) - resource.usedPorts;
43 result.push_back(offer);
44 }
45 return result;
46}
47
49{
50 bool resourceFound = false;
51 for (auto& resource : mResources) {
52 if (resource.hostname != offer.hostname) {
53 continue;
54 }
55 if (resource.startPort > offer.startPort) {
56 continue;
57 }
58 if (resource.lastPort < offer.startPort + offer.rangeSize) {
59 continue;
60 }
61 resourceFound = true;
62 resource.cpu -= offer.cpu;
63 resource.memory -= offer.memory;
64 resource.usedPorts += offer.rangeSize;
65 break;
66 }
67
68 if (resourceFound == false) {
69 std::string resources = "Available resources:\n";
70 for (auto& resource : mResources) {
71 resources += fmt::format("- (host:{}, cpu:{}, memory:{}, ports:{}-{})\n", resource.hostname.c_str(), resource.cpu, resource.memory, resource.startPort, resource.lastPort);
72 }
73 throw std::runtime_error(fmt::format("Could not match offer (host:{}, cpu:{}, mem:{}, ports:{}) to original resource.\n"
74 "Most likely you need to declare more resources via --resources or reduce the number of devices.",
75 offer.hostname, offer.cpu, offer.memory, offer.rangeSize) +
76 resources);
77 }
78}
79
80} // namespace o2::framework
std::vector< ComputingOffer > getAvailableOffers() override
Get the available resources for a device to run on.
void notifyAcceptedOffer(ComputingOffer const &accepted) override
GLuint64EXT * result
Definition glcorearb.h:5662
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20