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

Utilities::pack and unpack #5500

Merged
merged 2 commits into from Nov 19, 2017
Merged

Conversation

luca-heltai
Copy link
Member

@luca-heltai luca-heltai commented Nov 18, 2017

Since this is used in many places over the library now, I moved these two to the utilities namespace.

In a followup PR, I'll make sure that whenever this functionality is used in the library, then this is called instead of rewriting the same thing over and over. I already started, by converting some calls inside grid_tools.h (see last commit).

@@ -0,0 +1 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change the test so that it outputs ok

Copy link
Member

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

Looks good otherwise!

* to pack the object into a vector of characters. The object can be unpacked
* using the Utilities::unpack function below.
*
* If the library has been compiled with BZIP enabled, then the output buffer
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be ZLIB.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes of course. :)

@masterleinad
Copy link
Member

/run-tests

* If the library has been compiled with ZLIB enabled, then the output buffer
* is compressed.
*
* @author Luca Heltai, 2017.
Copy link
Contributor

Choose a reason for hiding this comment

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

since you moved the fucntion, maybe add @tjhei as an author as IIRC he wrote those originally.

Copy link
Member

Choose a reason for hiding this comment

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

@tjhei wrote the initial function, I added the compression. Either way, though, great idea to externalize this into a separate set of functions!

Copy link
Contributor

Choose a reason for hiding this comment

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

great idea to externalize this into a separate set of functions!

👍

Copy link
Member

@bangerth bangerth left a comment

Choose a reason for hiding this comment

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

Great idea!

Since it's completely generic now and not replicated in many places, we may later on think about whether the function can be optimized in various ways. For example, if T is either a POD type, or an array of PODs, or a std::vector of POD types, then we can just copy the data into the buffer bitwise. Or not compress if the data size is less than 1000 bytes, or any other considerations. But all of this can wait for later patches and/or evidence that it makes a difference.

In any case, I like this a lot!

* If the library has been compiled with ZLIB enabled, then the output buffer
* is compressed.
*
* @author Luca Heltai, 2017.
Copy link
Member

Choose a reason for hiding this comment

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

@tjhei wrote the initial function, I added the compression. Either way, though, great idea to externalize this into a separate set of functions!

}

return buffer;
return Utilities::pack(*this);
Copy link
Member

Choose a reason for hiding this comment

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

since the function now has only one line, could you just get rid of it altogether by calling Utilities::pack(obj) instead of obj.pack_data()?

Copy link
Contributor

Choose a reason for hiding this comment

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

don't we also pack and unpack cell_id within the CellDataTransferBuffer? eventually we should be always sending/receiving those in pairs.

@luca-heltai luca-heltai force-pushed the pack_unpack branch 2 times, most recently from a1347ff to e4c6905 Compare November 18, 2017 16:56
@@ -3290,8 +3216,7 @@ namespace GridTools
tria->get_communicator(), &status);
AssertThrowMPI(ierr);

CellDataTransferBuffer<dim, DataType> cellinfo;
cellinfo.unpack_data(receive);
auto cellinfo = Utilities::unpack<CellDataTransferBuffer<dim, DataType> >(receive);
Copy link
Contributor

Choose a reason for hiding this comment

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

out of curiosity, how are std::vector<CellId> cell_ids; (member of CellDataTransferBuffer) being set here?

Copy link
Contributor

Choose a reason for hiding this comment

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

p.s. I am just a bit lost how do we unpack this part of the object here... @bangerth ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea...

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, i guess it's hidden in archive << object; and archive >> object; which calls load and save methods of this class and consequently do the right thing.

namespace serialization
{

// Provides boost and c++11 with a way to serialize tuples and pairs automatically
Copy link
Contributor

@davydden davydden Nov 18, 2017

Choose a reason for hiding this comment

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

do you mind adding tests for those?

Copy link
Contributor

@davydden davydden Nov 18, 2017

Choose a reason for hiding this comment

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

maybe put it into a separate PR so that this one can be merged quickly

Copy link
Contributor

Choose a reason for hiding this comment

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

nevermind, i see that you already pushed the tests.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's already there. test number two packs and unpack a tuple of pairs and points.

@davydden
Copy link
Contributor

@luca-heltai can you please squash into fewer commits, ideally two: first for everything but "Added boost::serialization::serialize for tuples and pairs in utilities" and the second for it.

Copy link
Member

@tjhei tjhei left a comment

Choose a reason for hiding this comment

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

neat!

@luca-heltai
Copy link
Member Author

merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants