1/**
2 * Copyright (c) 2017-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9#pragma once
10
11#include <chrono>
12#include <memory>
13#include <vector>
14
15#include <gloo/transport/pair.h>
16
17namespace gloo {
18
19// There is no need to materialize all transport types here.
20namespace transport {
21class Context;
22class Device;
23class UnboundBuffer;
24}
25
26class Context {
27 public:
28 Context(int rank, int size, int base = 2);
29 virtual ~Context();
30
31 const int rank;
32 const int size;
33 int base;
34
35 std::shared_ptr<transport::Device>& getDevice();
36
37 std::unique_ptr<transport::Pair>& getPair(int i);
38
39 // Factory function to create an unbound buffer for use with the
40 // transport used for this context. Use this function to avoid tying
41 // downstream code to a specific transport.
42 std::unique_ptr<transport::UnboundBuffer> createUnboundBuffer(
43 void* ptr, size_t size);
44
45 int nextSlot(int numToSkip = 1);
46
47 void closeConnections();
48
49 void setTimeout(std::chrono::milliseconds timeout);
50
51 std::chrono::milliseconds getTimeout() const;
52
53 protected:
54 std::shared_ptr<transport::Device> device_;
55 std::shared_ptr<transport::Context> transportContext_;
56 int slot_;
57 std::chrono::milliseconds timeout_;
58};
59
60} // namespace gloo
61