charm AT lists.siebelschool.illinois.edu
Subject: Charm++ parallel programming system
List archive
- From: "White, Samuel T" <white67 AT illinois.edu>
- To: Jozsef Bakosi <jbakosi AT lanl.gov>, charm <charm AT lists.cs.illinois.edu>
- Subject: RE: [charm] Send a variable-size message with std::vector inside
- Date: Fri, 20 Oct 2017 23:46:43 +0000
- Accept-language: en-US
- Authentication-results: illinois.edu; spf=pass smtp.mailfrom=white67 AT illinois.edu
Hi Jozsef,
Sorry for the delayed response! The issue looks to be that your message
object's constructor is not copying all the elements of the input vectors
into its array members.
So if you replace:
solMsg( std::vector< int >& g, std::vector< double >& s ) :
gid( g.data() ),
sol( s.data() ),
gid_size( static_cast<int>(g.size()) ),
sol_size( static_cast<int>(s.size()) ) {}
... with the following, it should work:
solMsg( std::vector< int >& g, std::vector< double >& s ) :
gid_size( static_cast<int>(g.size()) ),
sol_size( static_cast<int>(s.size()) )
{
memcpy(gid, g.data(), sizeof(int)*gid_size);
memcpy(sol, s.data(), sizeof(double)*sol_size);
}
-Sam
________________________________________
From: Jozsef Bakosi
[jbakosi AT lanl.gov]
Sent: Tuesday, October 10, 2017 3:35 PM
To: charm
Subject: [charm] Send a variable-size message with std::vector inside
Hi folks,
I need to send two std::vectors (whose sizes are only known at runtime) via
callbacks. If I understand the manual, standard pup methods don't work for
this
scenario and so I have to send the data via a custom message. Here is my
attempt:
.ci:
message solMsg {
int* gid;
double* sol;
};
.h:
class solMsg : public CMessage_solMsg {
public:
int* gid;
double* sol;
int gid_size;
int sol_size;
solMsg( std::vector< int >& g, std::vector< double >& s ) :
gid( g.data() ),
sol( s.data() ),
gid_size( static_cast<int>(g.size()) ),
sol_size( static_cast<int>(s.size()) ) {}
};
In the target class (T), I pre-create the callback, pointing back to T::fn:
auto cb = CkCallback( CkIndex_T::fn(nullptr), CkArrayIndex1D(thisIndex),
thisProxy );
Then after passing the above cb into a caller chare, I create the message and
issue the callback:
// the two vector I want to send
std::vector< int > gid;
std::vector< double > sol;
// fill gid and sol ...
// create message & send
int sizes[2] = { static_cast<int>(gid.size()), static_cast<int>(sol.size()) };
solMsg* m = new ( sizes ) solMsg( gid, sol );
cb.send( m );
// on the receiving side, I unpack and attempt to use
void T::fn( solMsg* m ) {
std::vector< int > gid( m->gid, m->gid + m->gid_size );
std::vector< double > sol( m->sol, m->sol + m->sol_size );
// use gid and sol ...
}
The problem is, in T::fn, I get complete garbage.
Interestingly, when I have first attempted to do this via the fixed-size
message
.ci:
message solMsg;
.h:
class solMsg : public CMessage_solMsg {
public:
std::vector<int gid;
std::vector<double> sol;
solMsg( const std::vector< int >& g, const std::vector< double >& s ) :
gid( g ), sol( s ) {}
};
then send simply as:
cb.send( new solMsg( gid, solution ) );
at least the vector sizes inside the message on the receiving side were
correct:
void T::fn( solMsg* m ) {
// m->gid.size() correct
// m->sol.size() correct
// use m->gid and m->sol ... but still garbage
}
What is a good way to pack/unpack a std::vector to a custom message type and
use
the message via a callback?
Thanks,
Jozsef
- [charm] Send a variable-size message with std::vector inside, Jozsef Bakosi, 10/10/2017
- RE: [charm] Send a variable-size message with std::vector inside, White, Samuel T, 10/20/2017
Archive powered by MHonArc 2.6.19.