Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/506 set data buffer method in storage unit #507

Merged
merged 4 commits into from
Nov 23, 2023

Conversation

LorenzzoQM
Copy link
Contributor

  • Tickets addressed: bsk-506
  • Review: By commit
  • Merge strategy: Merge (no squash)

Description

A method setDataBuffer was added to the dataStorageUnitBase, simpleStorageUnit, and partitionedStorageUnit modules. setDataBuffer allows the user to add or remove a specific amount of data from a given storage partition. simpleStorageUnit and partitionedStorageUnit inherit the method from dataStorageUnitBase. simpleStorageUnit only allows the user to modify the existing partition; partitionedStorageUnit allows the user to pass a vector of partition names and a vector of data to be added/removed from those partitions.

The data type for the storage capacity and storage level was changed from double to long int to avoid floating-point errors during comparisons. Also, the code now checks if there is enough space for the new data before adding it to the storage unit, avoiding going over the storage capacity.

Verification

Unit tests for simpleStorageUnit and partitionedStorageUnit were updated to test the new method.

Documentation

Documentation was updated to explain how the method works in each module.

Future work

N/A

@LorenzzoQM LorenzzoQM self-assigned this Nov 22, 2023
@LorenzzoQM LorenzzoQM requested a review from schaubh November 22, 2023 23:30
@LorenzzoQM LorenzzoQM force-pushed the feature/506_setDataBuffer_method_in_storageUnit branch from b57d356 to 9b5dc30 Compare November 23, 2023 01:52
@schaubh schaubh added the enhancement New feature or request label Nov 23, 2023
Copy link
Contributor

@schaubh schaubh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice branch. thanks for making these changes. This change ended up being much more involved than I expected.

@LorenzzoQM LorenzzoQM merged commit 3d7fb0e into develop Nov 23, 2023
2 checks passed
@LorenzzoQM LorenzzoQM deleted the feature/506_setDataBuffer_method_in_storageUnit branch November 23, 2023 02:28
@@ -34,7 +34,7 @@

struct dataInstance {
char dataInstanceName[128]; //!< data instance name
double dataInstanceSum; //!< data instance sum value, bits
long long int dataInstanceSum; //!< data instance sum value, bits
Copy link
Contributor

@patkenneally patkenneally Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that this has already been merged, but maybe after the break, this can be changed to use the precise width type int64_t or even uint64_t if your semantics demand it. We should prefer precise width types for any integer types larger than int. The bit size of integral types is not guaranteed across platforms/compilers. It benefits us to er on the side of guarantee. You can see (for the large majority) this attempt throughout the code base to use int32_t, int64_t, and the unsigned versions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Howdy @LorenzzoQM , @patkenneally makes some good points here about the use of int64_t, etc. Could you please create a small branch next week to address his feedback? I'll respond to review request quickly so it doesn't slow down your research tasks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I will address the comments as soon as possible. Thank you for the feedback, @patkenneally.

//! - Only perform the operation if it will not result in less than 0 data
if ((this->storedData[0].dataInstanceSum + it->baudRate * (this->currentTimestep)) >= 0){
this->storedData[0].dataInstanceSum += it->baudRate * (this->currentTimestep);
this->storedData[0].dataInstanceSum += round(it->baudRate * (this->currentTimestep));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The braces around this->currentTimestep are redundant and can be removed.

void SimpleStorageUnit::setDataBuffer(long long int data){
std::string partitionName = "STORED DATA";
SimpleStorageUnit::DataStorageUnitBase::setDataBuffer(partitionName, data);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is missing a new line at its end. You can see that github is alerting you of this fact with the little red circle containing a dash, just to the left above this comment.

for (int i = 0; i < partitionNames.size(); i++)
{
PartitionedStorageUnit::DataStorageUnitBase::setDataBuffer(partitionNames[i], data[i]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line here as well

@param data //Vector of data to be added to each partition in partitionNames
@return void
*/
void PartitionedStorageUnit::setDataBuffer(std::vector<std::string> partitionNames, std::vector<long long int> data){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be int64_t also, (assuming I'm not missing something here...I could be :) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Set initial data storage level in simpleStorageUnit and partitionedStorageUnit
3 participants