Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
MPIHelpers.h
Go to the documentation of this file.
1//===-- MPIHelpers.h -- MPI helper classes for cache implementations --===//
2//
3// Part of the Proteus Project, under the Apache License v2.0 with LLVM
4// Exceptions. See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Shared MPI helper classes used by MPI-based cache implementations.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef PROTEUS_MPIHELPERS_H
14#define PROTEUS_MPIHELPERS_H
15
18
19#include <mpi.h>
20
21#include <memory>
22#include <thread>
23#include <vector>
24
25namespace proteus {
26
27enum class MPITag : int {
28 Store = 1,
29 LookupRequest = 2,
31};
32
34
37public:
38 CommThreadHandle() = default;
40
43
44 template <typename Callable> void start(Callable &&ThreadFunc) {
45 if (isRunning())
46 return;
47
48 Thread = std::make_unique<std::thread>(std::forward<Callable>(ThreadFunc));
49 Running = true;
50 }
51
52 void join();
53
54 bool isRunning() const;
55
56private:
57 std::unique_ptr<std::thread> Thread;
58 bool Running = false;
59};
60
63public:
66
67 MPICommHandle(const MPICommHandle &) = delete;
69
70 MPI_Comm get() const;
71 int getRank() const;
72 int getSize() const;
73
74 void finalize();
75
76private:
77 MPI_Comm Comm = MPI_COMM_NULL;
78 int Rank = -1;
79 int Size = -1;
80};
81
86 std::vector<char> Data;
88};
89
90std::vector<char> packStoreMessage(MPI_Comm Comm, const HashT &HashValue,
91 const CacheEntry &Entry);
92StoreMessage unpackStoreMessage(MPI_Comm Comm, const std::vector<char> &Buffer);
93
94} // namespace proteus
95
96#endif
Manages the lifecycle of a background communication thread.
Definition MPIHelpers.h:36
void join()
Definition MPIHelpers.cpp:77
CommThreadHandle & operator=(const CommThreadHandle &)=delete
CommThreadHandle(const CommThreadHandle &)=delete
void start(Callable &&ThreadFunc)
Definition MPIHelpers.h:44
bool isRunning() const
Definition MPIHelpers.cpp:87
~CommThreadHandle()
Definition MPIHelpers.cpp:75
Definition Hashing.h:21
RAII wrapper for MPI communicator with thread safety checks.
Definition MPIHelpers.h:62
MPICommHandle(const MPICommHandle &)=delete
~MPICommHandle()
Definition MPIHelpers.cpp:65
int getRank() const
Definition MPIHelpers.cpp:69
int getSize() const
Definition MPIHelpers.cpp:71
MPICommHandle & operator=(const MPICommHandle &)=delete
void finalize()
Definition MPIHelpers.cpp:73
MPI_Comm get() const
Definition MPIHelpers.cpp:67
MPICommHandle()
Definition MPIHelpers.cpp:52
Definition MemoryCache.h:26
std::vector< char > packStoreMessage(MPI_Comm Comm, const HashT &HashValue, const CacheEntry &Entry)
Definition MPIHelpers.cpp:89
void validateMPIConfig()
Definition MPIHelpers.cpp:30
StoreMessage unpackStoreMessage(MPI_Comm Comm, const std::vector< char > &Buffer)
Definition MPIHelpers.cpp:130
MPITag
Definition MPIHelpers.h:27
Definition ObjectCache.h:27
Definition MPIRemoteLookupCache.h:24
Definition MPIRemoteLookupCache.h:28
Definition MPIHelpers.h:84
std::vector< char > Data
Definition MPIHelpers.h:86
bool IsDynLib
Definition MPIHelpers.h:87
HashT Hash
Definition MPIHelpers.h:85