- changed status to resolved
Transfer text data using std::string or char* with RMA calls
With the current release of UPC++, what is the recommended away to transfer text data using RMA calls, upcxx::rget
, upcxx::rput
?
There could be the following possibilities, and I think only the last one will work as the rest are not trivially serializable.
upcxx::global_ptr<std::string> s;
upcxx::global_ptr<std::vector<std::string>> s;
upcxx::global_ptr<char*> c;
upcxx::global_ptr<char[50]> c = upcxx::new_array<char[50]>(100);
upcxx::global_ptr<char> c = upcxx::new_array<char>(5000)
In theory, global_ptr<std::vector<std::string>>
would be the most flexible.
In practice, global_ptr<char>
will work, but involves more programming logic in the user application to track different text snippets, in particular when text has to be removed and inserted.
For some context, upcxx-spec issue #136 covers the details on full featured serialization. See also some relevant discussion related to serialization in earlier issues:
Comments (2)
-
-
reporter Thank you @Dan Bonachea for the useful pointers.
Just one addition that the solution would also have to extend to user-defined data types containing string, for example:
class Doc { std::string name; std::string type; std::string contents; }; upcxx::global_ptr<Doc> docs = upcxx::new_array<upcxx::global_ptr<Doc>>(1000);
- Log in to comment
RMA will likely always require trivially serializable types. The reason is that transferring non-trivial types requires active serialization work on the remote side - that entails remote CPU involvement, eliminates the possibility of offload to network hardware and makes the transfer no longer semantically a "memory access" (the MA in RMA).
If you need to transfer strings you have several choices:
std::string
and other STL containers (and in an upcoming release will also handle user-defined serialization). If the data has non-trivial size, you should consider additionally usingview
to reduce copy overheads.char
arrays in the shared heap (as in your ex 4 and 5 above), and perform RMA onupcxx::global_ptr<char>
or other trivially serializable types.std::string
data in the shared heap, callstd::string::data
to retrieve thechar *
, then usetry_global_ptr
to create aupcxx::global_ptr<char>
that other ranks can use in RMA.Which option is best depends on your situation.
Hope this helps..