Skip to content

Commit 6f49ccb

Browse files
authored
refactor: rpc engine requestRPC() accepts instance ids as parameter. getReturnValue() does not take an instance argument anymore (#40)
1 parent 38d39f8 commit 6f49ccb

File tree

7 files changed

+12
-15
lines changed

7 files changed

+12
-15
lines changed

examples/RPCEngine/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ The RPC is invoked by the root instance, the other instances listen to incoming
6363
if (currentInstance->isRootInstance())
6464
{
6565
for (auto &instance : im.getInstances())
66-
if (instance != currentInstance) rpcEngine.requestRPC(*instance, "Test RPC");
66+
if (instance != currentInstance) rpcEngine.requestRPC(instance->getId(), "Test RPC");
6767
}
6868
else
6969
rpcEngine.listen();

examples/RPCEngine/source/include/RPCTest.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void RPCTestFc(HiCR::CommunicationManager &cm,
4646
if (currentInstance->isRootInstance())
4747
{
4848
for (auto &instance : im.getInstances())
49-
if (instance != currentInstance) rpcEngine.requestRPC(*instance, "Test RPC");
49+
if (instance != currentInstance) rpcEngine.requestRPC(instance->getId(), "Test RPC");
5050
}
5151
else
5252
rpcEngine.listen();

examples/topology/distributed/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ The Root instance requests the topology from all the other instances, merge them
7878

7979
// Invoke RPC
8080
for (const auto &instance : instances)
81-
if (instance->getId() != coordinator->getId()) rpcEngine.requestRPC(*instance, TOPOLOGY_RPC_NAME);
81+
if (instance->getId() != coordinator->getId()) rpcEngine.requestRPC(instance->getId(), TOPOLOGY_RPC_NAME);
8282

8383
// Getting return values from the RPCs containing each of the worker's topology
8484
for (const auto &instance : instances)
8585
if (instance == coordinator)
8686
{
8787
// Getting return value as a memory slot
88-
auto returnValue = rpcEngine.getReturnValue(*instance);
88+
auto returnValue = rpcEngine.getReturnValue();
8989

9090
// Receiving raw serialized topology information from the worker
9191
std::string serializedTopology = (char *)returnValue->getPointer();

examples/topology/distributed/source/include/coordinator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ void coordinatorFc(HiCR::frontend::RPCEngine &rpcEngine)
3434

3535
// Printing instance information and invoking a simple RPC if its not ourselves
3636
for (const auto &instance : instances)
37-
if (instance->getId() != coordinator->getId()) rpcEngine.requestRPC(*instance, TOPOLOGY_RPC_NAME);
37+
if (instance->getId() != coordinator->getId()) rpcEngine.requestRPC(instance->getId(), TOPOLOGY_RPC_NAME);
3838

3939
// Getting return values from the RPCs containing each of the worker's topology
4040
for (const auto &instance : instances)
4141
if (instance != coordinator)
4242
{
4343
// Getting return value as a memory slot
44-
auto returnValue = rpcEngine.getReturnValue(*instance);
44+
auto returnValue = rpcEngine.getReturnValue();
4545

4646
// Receiving raw serialized topology information from the worker
4747
std::string serializedTopology = (char *)returnValue->getPointer();

include/hicr/core/memorySpace.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class MemorySpace
155155
_size = input[key].get<size_t>();
156156

157157
// Deserializing usage -- do not fail if unspecified
158-
key = "Usage";
158+
key = "Usage";
159159
_usage = 0;
160160
if (input.contains(key) && input[key].is_number_unsigned()) _usage = input[key].get<size_t>();
161161
}

include/hicr/frontends/RPCEngine/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The RPC caller can then wait for the reception of the return value by specifying
9393
instanceManager.launchRPC(*someInstance, RPC1_TARGET_ID);
9494
9595
// Getting return value
96-
auto returnValue = *(int *)instanceManager.getReturnValue(*someInstance);
96+
auto returnValue = *(int *)instanceManager.getReturnValue();
9797
9898
// Printing return value
9999
printf("Obtained return value: %d\n", returnValue);

include/hicr/frontends/RPCEngine/RPCEngine.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,12 @@ class RPCEngine
208208

209209
/**
210210
* Function to request the execution of a remote function in a remote HiCR instance
211-
* \param[in] RPCName The name of the RPC to run
212-
* \param[in] instance Instance on which to run the RPC
211+
* \param[in] targetInstanceId Instance ID of where the rpc is to be executed
212+
* \param[in] RPCName RPC Name
213213
* \param[in] argument An optional numerical argument to provide to the RPC
214214
*/
215-
virtual void requestRPC(HiCR::Instance &instance, const std::string &RPCName, const HiCR::frontend::RPCEngine::RPCArgument_t argument = 0)
215+
virtual void requestRPC(HiCR::Instance::instanceId_t targetInstanceId, const std::string &RPCName, const HiCR::frontend::RPCEngine::RPCArgument_t argument = 0)
216216
{
217-
const auto targetInstanceId = instance.getId();
218-
219217
// Creating message payload
220218
RPCPayload_t RPCPayload;
221219
RPCPayload.index = getRPCTargetIndexFromString(RPCName);
@@ -254,10 +252,9 @@ class RPCEngine
254252

255253
/**
256254
* Function to get a return value from a remote instance that ran an RPC
257-
* \param[in] instance Instance from which to read the return value. An RPC request should be sent to that instance before calling this function.
258255
* \return A pointer to a newly allocated local memory slot containing the return value
259256
*/
260-
__INLINE__ std::shared_ptr<HiCR::LocalMemorySlot> getReturnValue(HiCR::Instance &instance) const
257+
__INLINE__ std::shared_ptr<HiCR::LocalMemorySlot> getReturnValue() const
261258
{
262259
// Calling the backend-specific implementation of the listen function
263260
while (_returnValueConsumerChannel->isEmpty());

0 commit comments

Comments
 (0)