Skip to content

Commit

Permalink
Pending count (#2111)
Browse files Browse the repository at this point in the history
* add a few HELICS 3 methods and deprecate a few others in prep for release

* update changelog

* Automated formatting of repo files (#2112)

Co-authored-by: Philip Top <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Ryan Mast <[email protected]>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Ryan Mast <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2021
1 parent 3715e65 commit 27ee5b6
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 25 deletions.
16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
A note on future revisions.
Everything within a major version number should be code compatible (with the exception of experimental interfaces). Everything within a single minor release should be network compatible with other federates on the same minor release number. Compatibility across minor release numbers may be possible in some situations but we are not going to guarantee this as those components are subject to performance improvements and may need to be modified at some point. Patch releases will be limited to bug fixes and other improvements not impacting the public API or network compatibility. Check the [Public API](./docs/Public_API.md) for details on what is included and excluded from the public API and version stability.

## [2.8.0][] - 2021-09-10
## [2.8.0][] - 2021-09-17

Final Minor release in the 2.X series of HELICS. This includes a compatibility layer for future compatibility through the "--json" flag. There may be more bug fix releases
Final Minor release in the 2.X series of HELICS. This includes profiling capabilities and a compatibility layer for future compatibility through the "--json" flag. There may be more bug fix releases but no major new features will be added to HELICS 2.

### Changed

- Upgraded Units library to 0.5.0
- CMAKE 3.20 was tested and verified and used as the baseline version when available.
- Updated to a newer custom version of JSONCPP to support the json compatibility layer

### Fixed

- The uninterruptible flag now works with iterations
- A compile issue with C++20 requiring `#include <thread>` in a number of files

### Added

- Added json data type and flag to support interoperability between HELICS 2 and 3
- Added `helicsEndpointPendingMessageCount`, `helicsFederatePendingMessageCount`, and `helicsFederateDisconnect[Async|Complete]`
- Added a [profiling capability](https://docs.helics.org/en/latest/user-guide/advanced_topics/profiling.html)

### Deprecated

- `helicsEndpointPendingMessages` and `helicsFederatePendingMessages` are replaced by `helicsEndpointPendingMessageCount` and`helicsFederatePendingMessageCount` to match HELICS 3 functions

## [2.7.1][] - 2021-06-03

There were several bug fixes in this patch release. Some of them related to changes in [2.7.0][] and some new ones that came up from bug reports. Some new enhancements are experimental signal handlers in the C-api, which will be used in the python interface to provide a little better user experience when trying to kill a co-simulation.
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ project(HELICS VERSION 2.8.0)
# -----------------------------------------------------------------------------
set(HELICS_VERSION_BUILD)
# use ISO date YYYY-MM-DD
set(HELICS_DATE "2021-09-10")
set(HELICS_DATE "2021-09-17")

set(HELICS_VERSION_UNDERSCORE
"${HELICS_VERSION_MAJOR}_${HELICS_VERSION_MINOR}_${HELICS_VERSION_PATCH}"
Expand Down
2 changes: 1 addition & 1 deletion src/helics/cpp98/Endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class Endpoint {
/** get the default destination for an endpoint*/
const char* getDefaultDestination() const { return helicsEndpointGetDefaultDestination(ep); }
/** Returns the number of pending receives for endpoint **/
uint64_t pendingMessages() const { return helicsEndpointPendingMessages(ep); }
uint64_t pendingMessages() const { return helicsEndpointPendingMessageCount(ep); }

/** Get a packet from an endpoint **/
Message getMessage() { return Message(helicsEndpointGetMessageObject(ep)); }
Expand Down
2 changes: 1 addition & 1 deletion src/helics/cpp98/MessageFederate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MessageFederate: public virtual Federate {
}

/** Returns the number of pending receives for all endpoints. **/
int pendingMessages() const { return helicsFederatePendingMessages(fed); }
int pendingMessages() const { return helicsFederatePendingMessageCount(fed); }

/** Get a packet for any endpoints in the federate **/
Message getMessage() { return Message(helicsFederateGetMessageObject(fed)); }
Expand Down
15 changes: 15 additions & 0 deletions src/helics/shared_api_library/FederateExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,21 @@ void helicsFederateFinalizeComplete(helics_federate fed, helics_error* err)
// LCOV_EXCL_STOP
}

void helicsFederateDisconnect(helics_federate fed, helics_error* err)
{
helicsFederateFinalize(fed, err);
}

void helicsFederateDisconnectAsync(helics_federate fed, helics_error* err)
{
helicsFederateFinalizeAsync(fed, err);
}

void helicsFederateDisconnectComplete(helics_federate fed, helics_error* err)
{
helicsFederateFinalizeComplete(fed, err);
}

/* initialization, execution, and time requests */
void helicsFederateEnterInitializingMode(helics_federate fed, helics_error* err)
{
Expand Down
20 changes: 18 additions & 2 deletions src/helics/shared_api_library/MessageFederate.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,34 @@ HELICS_EXPORT helics_bool helicsFederateHasMessage(helics_federate fed);
HELICS_EXPORT helics_bool helicsEndpointHasMessage(helics_endpoint endpoint);

/**
* Deprecated, please use helicsFederatePendingMessageCount instead.
* Returns the number of pending receives for the specified destination endpoint.
*
* @param fed The federate to get the number of waiting messages from.
*/
HELICS_EXPORT int helicsFederatePendingMessages(helics_federate fed);
HELICS_DEPRECATED_EXPORT int helicsFederatePendingMessages(helics_federate fed);

/**
* Returns the number of pending receives for the specified destination endpoint.
*
* @param fed The federate to get the number of waiting messages from.
*/
HELICS_EXPORT int helicsFederatePendingMessageCount(helics_federate fed);

/**
* Deprecated, please use helicsEndpointPendingMessageCount instead.
* Returns the number of pending receives for all endpoints of a particular federate.
*
* @param endpoint The endpoint to query.
*/
HELICS_DEPRECATED_EXPORT int helicsEndpointPendingMessages(helics_endpoint endpoint);

/**
* Returns the number of pending receives for all endpoints of a particular federate.
*
* @param endpoint The endpoint to query.
*/
HELICS_EXPORT int helicsEndpointPendingMessages(helics_endpoint endpoint);
HELICS_EXPORT int helicsEndpointPendingMessageCount(helics_endpoint endpoint);

/**
* Receive a packet from a particular endpoint.
Expand Down
15 changes: 13 additions & 2 deletions src/helics/shared_api_library/MessageFederateExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ helics_bool helicsEndpointHasMessage(helics_endpoint endpoint)
return (endObj->endPtr->hasMessage()) ? helics_true : helics_false;
}

int helicsFederatePendingMessages(helics_federate fed)
int helicsFederatePendingMessageCount(helics_federate fed)
{
auto* mFed = getMessageFed(fed, nullptr);
if (mFed == nullptr) {
Expand All @@ -362,14 +362,25 @@ int helicsFederatePendingMessages(helics_federate fed)
return static_cast<int>(mFed->pendingMessages());
}

int helicsEndpointPendingMessages(helics_endpoint endpoint)
int helicsFederatePendingMessages(helics_federate fed)
{
return helicsFederatePendingMessageCount(fed);
}

int helicsEndpointPendingMessageCount(helics_endpoint endpoint)
{
auto* endObj = verifyEndpoint(endpoint, nullptr);
if (endObj == nullptr) {
return 0;
}
return static_cast<int>(endObj->endPtr->pendingMessages());
}

int helicsEndpointPendingMessages(helics_endpoint endpoint)
{
return helicsEndpointPendingMessageCount(endpoint);
}

static constexpr uint16_t messageKeyCode = 0xB3;

namespace helics {
Expand Down
16 changes: 16 additions & 0 deletions src/helics/shared_api_library/helics.h
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,22 @@ HELICS_EXPORT void helicsFederateFinalizeAsync(helics_federate fed, helics_error
*/
HELICS_EXPORT void helicsFederateFinalizeComplete(helics_federate fed, helics_error* err);

/**
* Disconnect/finalize the federate. This function halts all communication in the federate and disconnects it
* from the core. This call is identical to helicsFederateFinalize.
*/
HELICS_EXPORT void helicsFederateDisconnect(helics_federate fed, helics_error* err);

/**
* Disconnect/finalize the federate in an async call. This call is identical to helicsFederateFinalizeAsync.
*/
HELICS_EXPORT void helicsFederateDisconnectAsync(helics_federate fed, helics_error* err);

/**
* Complete the asynchronous disconnect/finalize call. This call is identical to helicsFederateFinalizeComplete.
*/
HELICS_EXPORT void helicsFederateDisconnectComplete(helics_federate fed, helics_error* err);

/**
* Release the memory associated with a federate.
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/helics/shared_library/FilterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ TEST_F(filter_tests, multi_clone_test)
CE(helicsFederateRequestTimeComplete(sFed2, &err));
CE(helicsFederateRequestTimeComplete(dcFed, &err));

auto mcnt = helicsEndpointPendingMessages(p3);
auto mcnt = helicsEndpointPendingMessageCount(p3);
EXPECT_EQ(mcnt, 2);
auto res = helicsFederateHasMessage(dFed);
EXPECT_EQ(res, helics_true);
Expand All @@ -1000,7 +1000,7 @@ TEST_F(filter_tests, multi_clone_test)
}

// now check the message clone
mcnt = helicsEndpointPendingMessages(p4);
mcnt = helicsEndpointPendingMessageCount(p4);
EXPECT_EQ(mcnt, 2);
res = helicsFederateHasMessage(dcFed);
EXPECT_EQ(res, helics_true);
Expand Down
10 changes: 5 additions & 5 deletions tests/helics/shared_library/badInputTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ TEST_F(function_tests, typePub)
EXPECT_EQ(str[0], '2');
EXPECT_EQ(str[1], '7');

auto messages = helicsFederatePendingMessages(vFed1);
auto messages = helicsFederatePendingMessageCount(vFed1);
EXPECT_EQ(messages, 0);

helicsFederateFinalize(vFed1, nullptr);
Expand Down Expand Up @@ -885,7 +885,7 @@ TEST_F(function_tests, messageFed)

helicsFederateRequestNextStep(mFed1, nullptr);
// make sure the message got through
auto cnt = helicsEndpointPendingMessages(ept1);
auto cnt = helicsEndpointPendingMessageCount(ept1);
EXPECT_EQ(cnt, 2);

// message Federates do not have publications so should be 0
Expand Down Expand Up @@ -921,7 +921,7 @@ TEST_F(function_tests, messageFed_event)
char data[5] = "test";
helicsEndpointSendEventRaw(ept1, nullptr, data, 4, 0.0, &err);
helicsFederateRequestNextStep(mFed1, nullptr);
auto cnt = helicsEndpointPendingMessages(ept1);
auto cnt = helicsEndpointPendingMessageCount(ept1);
EXPECT_EQ(cnt, 3);

helicsFederateFinalize(mFed1, nullptr);
Expand Down Expand Up @@ -975,7 +975,7 @@ TEST_F(function_tests, messageFed_messageObject)
helicsEndpointSendMessageObjectZeroCopy(ept1, mess1, &err);

helicsFederateRequestNextStep(mFed1, nullptr);
auto cnt = helicsEndpointPendingMessages(ept1);
auto cnt = helicsEndpointPendingMessageCount(ept1);
EXPECT_EQ(cnt, 4);

helicsFederateFinalize(mFed1, nullptr);
Expand Down Expand Up @@ -1015,7 +1015,7 @@ TEST_F(function_tests, messageFed_message_object)
helicsEndpointSendMessageObject(ept1, mess1, &err);

helicsFederateRequestNextStep(mFed1, nullptr);
auto cnt = helicsEndpointPendingMessages(ept1);
auto cnt = helicsEndpointPendingMessageCount(ept1);
EXPECT_EQ(cnt, 1);

auto m3 = helicsFederateGetMessageObject(mFed1);
Expand Down
14 changes: 7 additions & 7 deletions tests/helics/shared_library/evilInputTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3206,14 +3206,14 @@ TEST(evil_message_fed_test, helicsFederateHasMessage)
EXPECT_EQ(res2, helics_false);
}

TEST(evil_message_fed_test, helicsFederatePendingMessages)
TEST(evil_message_fed_test, helicsFederatePendingMessageCount)
{
// int helicsFederatePendingMessages(helics_federate fed);
char rdata[256];
auto evil_federate = reinterpret_cast<helics_federate>(rdata);
auto res1 = helicsFederatePendingMessages(nullptr);
auto res1 = helicsFederatePendingMessageCount(nullptr);
EXPECT_EQ(res1, 0);
auto res2 = helicsFederatePendingMessages(evil_federate);
auto res2 = helicsFederatePendingMessageCount(evil_federate);
EXPECT_EQ(res2, 0);
}

Expand Down Expand Up @@ -3735,14 +3735,14 @@ TEST(evil_endpoint_test, helicsEndpointHasMessage)
EXPECT_EQ(res2, helics_false);
}

TEST(evil_endpoint_test, helicsEndpointPendingMessages)
TEST(evil_endpoint_test, helicsEndpointPendingMessageCount)
{
// int helicsEndpointPendingMessages(helics_endpoint endpoint);
// int helicsEndpointPendingMessageCount(helics_endpoint endpoint);
char rdata[256];
auto evil_ept = reinterpret_cast<helics_endpoint>(rdata);
auto res1 = helicsEndpointPendingMessages(nullptr);
auto res1 = helicsEndpointPendingMessageCount(nullptr);
EXPECT_EQ(res1, 0);
auto res2 = helicsEndpointPendingMessages(evil_ept);
auto res2 = helicsEndpointPendingMessageCount(evil_ept);
EXPECT_EQ(res2, 0);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/helics/shared_library/test-message-federate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ TEST_P(mfed_type_tests, send_receive_2fed_multisend)
EXPECT_EQ(gtime, 1.0);
EXPECT_EQ(time, 1.0);

auto res = helicsEndpointPendingMessages(epid2);
auto res = helicsEndpointPendingMessageCount(epid2);
EXPECT_EQ(res, 3);

res = helicsFederatePendingMessages(mFed2);
res = helicsFederatePendingMessageCount(mFed2);
EXPECT_EQ(res, 3);

EXPECT_STREQ(helicsEndpointGetDefaultDestination(epid), "ep2");
Expand Down

0 comments on commit 27ee5b6

Please sign in to comment.