Skip to Content.
Sympa Menu

charm - [charm] Send a variable-size message with std::vector inside

charm AT lists.cs.illinois.edu

Subject: Charm++ parallel programming system

List archive

[charm] Send a variable-size message with std::vector inside


Chronological Thread 
  • From: Jozsef Bakosi <jbakosi AT lanl.gov>
  • To: charm <charm AT lists.cs.illinois.edu>
  • Subject: [charm] Send a variable-size message with std::vector inside
  • Date: Tue, 10 Oct 2017 14:35:16 -0600
  • Authentication-results: illinois.edu; spf=pass smtp.mailfrom=jbakosi AT lanl.gov

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



Archive powered by MHonArc 2.6.19.

Top of Page