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

Added MPI operations for Bool variables #240

Merged
merged 4 commits into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/c4/C4_MPI_async_pt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace rtt_c4 {
//---------------------------------------------------------------------------//

//! Send char data asynchronously.
template C4_Req DLL_PUBLIC_c4 send_async<bool>(const bool *, int, int, int);
template C4_Req DLL_PUBLIC_c4 send_async<char>(const char *, int, int, int);
//! Send uchar data asynchronously.
template C4_Req DLL_PUBLIC_c4 send_async<unsigned char>(const unsigned char *,
Expand All @@ -48,6 +49,7 @@ template C4_Req DLL_PUBLIC_c4 send_async<long long>(const long long *, int, int,
template C4_Req DLL_PUBLIC_c4
send_async<unsigned long long>(const unsigned long long *, int, int, int);

template C4_Req DLL_PUBLIC_c4 receive_async<bool>(bool *, int, int, int);
template C4_Req DLL_PUBLIC_c4 receive_async<char>(char *, int, int, int);
template C4_Req DLL_PUBLIC_c4 receive_async<unsigned char>(unsigned char *, int,
int, int);
Expand All @@ -69,6 +71,8 @@ template C4_Req DLL_PUBLIC_c4 receive_async<long long>(long long *, int, int,
template C4_Req DLL_PUBLIC_c4
receive_async<unsigned long long>(unsigned long long *, int, int, int);

template void DLL_PUBLIC_c4 send_async<bool>(C4_Req &, const bool *, int, int,
int);
template void DLL_PUBLIC_c4 send_async<char>(C4_Req &, const char *, int, int,
int);
template void DLL_PUBLIC_c4 send_async<unsigned char>(C4_Req &,
Expand Down Expand Up @@ -101,6 +105,8 @@ template void DLL_PUBLIC_c4 send_async<long long>(C4_Req &, const long long *,
template void DLL_PUBLIC_c4 send_async<unsigned long long>(
C4_Req &, const unsigned long long *, int, int, int);

template void DLL_PUBLIC_c4 send_is<bool>(C4_Req &, const bool *, int, int,
int);
template void DLL_PUBLIC_c4 send_is<char>(C4_Req &, const char *, int, int,
int);
template void DLL_PUBLIC_c4 send_is<unsigned char>(C4_Req &,
Expand Down Expand Up @@ -131,6 +137,8 @@ template void DLL_PUBLIC_c4 send_is<long long>(C4_Req &, const long long *, int,
template void DLL_PUBLIC_c4 send_is<unsigned long long>(
C4_Req &, const unsigned long long *, int, int, int);

template void DLL_PUBLIC_c4 receive_async<bool>(C4_Req &, bool *, int, int,
int);
template void DLL_PUBLIC_c4 receive_async<char>(C4_Req &, char *, int, int,
int);
template void DLL_PUBLIC_c4 receive_async<unsigned char>(C4_Req &,
Expand Down
7 changes: 7 additions & 0 deletions src/c4/C4_MPI_blocking_pt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace rtt_c4 {
// EXPLICIT INSTANTIATIONS OF BLOCKING SEND/RECEIVE AND BROADCAST
//---------------------------------------------------------------------------//

template DLL_PUBLIC_c4 int send<bool>(const bool *, int, int, int);
template DLL_PUBLIC_c4 int send<char>(const char *, int, int, int);
template DLL_PUBLIC_c4 int send<unsigned char>(const unsigned char *, int, int,
int);
Expand All @@ -46,6 +47,7 @@ template DLL_PUBLIC_c4 int send<long double>(const long double *, int, int,
template DLL_PUBLIC_c4 int send_udt<double>(const double *, int, int,
C4_Datatype &, int);

template DLL_PUBLIC_c4 int receive<bool>(bool *, int, int, int);
template DLL_PUBLIC_c4 int receive<char>(char *, int, int, int);
template DLL_PUBLIC_c4 int receive<unsigned char>(unsigned char *, int, int,
int);
Expand All @@ -67,6 +69,7 @@ template DLL_PUBLIC_c4 int receive<long double>(long double *, int, int, int);
template DLL_PUBLIC_c4 int receive_udt<double>(double *, int, int,
C4_Datatype &, int);

template DLL_PUBLIC_c4 int broadcast<bool>(bool *, int, int);
template DLL_PUBLIC_c4 int broadcast<char>(char *, int, int);
template DLL_PUBLIC_c4 int broadcast<unsigned char>(unsigned char *, int, int);
template DLL_PUBLIC_c4 int broadcast<short>(short *, int, int);
Expand All @@ -83,6 +86,10 @@ template DLL_PUBLIC_c4 int broadcast<float>(float *, int, int);
template DLL_PUBLIC_c4 int broadcast<double>(double *, int, int);
template DLL_PUBLIC_c4 int broadcast<long double>(long double *, int, int);

template DLL_PUBLIC_c4 int send_receive(bool *sendbuf, int sendcount,
int destination, bool *recvbuf,
int recvcount, int source, int sendtag,
int recvtag);
template DLL_PUBLIC_c4 int send_receive(char *sendbuf, int sendcount,
int destination, char *recvbuf,
int recvcount, int source, int sendtag,
Expand Down
4 changes: 4 additions & 0 deletions src/c4/C4_Traits.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ template <class T> struct C4_Traits {};
// SPECIALIZATION OF INTRINSIC ELEMENTAL TYPES
//---------------------------------------------------------------------------//

template <> struct C4_Traits<bool> { static const int tag = 430; };

template <> struct C4_Traits<char> { static const int tag = 431; };

template <> struct C4_Traits<unsigned char> { static const int tag = 432; };
Expand Down Expand Up @@ -71,6 +73,8 @@ template <> struct C4_Traits<long long> { static const int tag = 443; };
// SPECIALIZATION OF INTRINSIC POINTER TYPES
//---------------------------------------------------------------------------//

template <> struct C4_Traits<bool *> { static const int tag = 450; };

template <> struct C4_Traits<char *> { static const int tag = 451; };

template <> struct C4_Traits<unsigned char *> { static const int tag = 452; };
Expand Down
4 changes: 4 additions & 0 deletions src/c4/MPI_Traits.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ template <class T> struct MPI_Traits {};
// SPECIALIZATIONS OF MPI_Traits FOR DIFFERENT TYPES
//---------------------------------------------------------------------------//

template <> struct MPI_Traits<bool> {
static MPI_Datatype element_type() { return MPI_C_BOOL; }
};

template <> struct MPI_Traits<char> {
static MPI_Datatype element_type() { return MPI_CHAR; }
};
Expand Down
55 changes: 51 additions & 4 deletions src/c4/test/tstPingPong.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ void blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
if (rtt_c4::nodes() != 2)
return;

bool b = false;
char c = 0;
int i = 0;
long l = 0;
Expand All @@ -44,6 +45,7 @@ void blocking_ping_pong(rtt_dsxx::UnitTest &ut) {

// assign on node 0
if (rtt_c4::node() == 0) {
b = true;
c = 'A';
i = 1;
l = 1000;
Expand All @@ -52,6 +54,7 @@ void blocking_ping_pong(rtt_dsxx::UnitTest &ut) {

// send out data
// Test both active and depricated forms of the send command.
send(&b, 1, 1);
send(&c, 1, 1);
send(&i, 1, 1);
send(&l, 1, 1);
Expand All @@ -60,13 +63,16 @@ void blocking_ping_pong(rtt_dsxx::UnitTest &ut) {

// receive back
// Test both active and depricated forms of the receive command.
receive(&b, 1, 1);
receive(&c, 1, 1);
receive(&i, 1, 1);
receive(&l, 1, 1);
receive(&f, 1, 1);
receive(&d, 1, 1);

// check values
if (b != false)
ITFAILS;
if (c != 'B')
ITFAILS;
if (i != 2)
Expand All @@ -82,13 +88,16 @@ void blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
// receive and send on node 1
if (rtt_c4::node() == 1) {
// receive from node 0
receive(&b, 1, 0);
receive(&c, 1, 0);
receive(&i, 1, 0);
receive(&l, 1, 0);
receive(&f, 1, 0);
receive(&d, 1, 0);

// check values
if (b != true)
ITFAILS;
if (c != 'A')
ITFAILS;
if (i != 1)
Expand All @@ -101,13 +110,15 @@ void blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
ITFAILS;

// assign new values
b = false;
c = 'B';
i = 2;
l = 2000;
f = 2.5;
d = 3.5;

// send them back
send(&b, 1, 0);
send(&c, 1, 0);
send(&i, 1, 0);
send(&l, 1, 0);
Expand All @@ -133,38 +144,41 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {

if (rtt_c4::nodes() != 2)
return;

bool b = false;
char c = 0;
int i = 0;
long l = 0;
float f = 0;
double d = 0;

bool br = false;
char cr = 0;
int ir = 0;
long lr = 0;
float fr = 0;
double dr = 0;

// send requests
C4_Req crs, irs, lrs, frs, drs;
C4_Req brs, crs, irs, lrs, frs, drs;

// receive requests
C4_Req crr, irr, lrr, frr, drr;
C4_Req brr, crr, irr, lrr, frr, drr;

// assign on node 0
if (rtt_c4::node() == 0) {
// post receives
// Test two forms of the receive_async command plus one deprecated
// form (namespace C4::)

brr = receive_async(&br, 1, 1);
receive_async(crr, &cr, 1, 1);
irr = receive_async(&ir, 1, 1);
receive_async(lrr, &lr, 1, 1);
frr = receive_async(&fr, 1, 1);
receive_async(drr, &dr, 1, 1);

// give values to the send data
b = true;
c = 'A';
i = 1;
l = 1000;
Expand All @@ -174,13 +188,15 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
// send out data
// Test two forms of the send_async command plus one deprecated
// form (namespace C4::)
brs = send_async(&b, 1, 1);
send_async(crs, &c, 1, 1);
irs = send_async(&i, 1, 1);
send_async(lrs, &l, 1, 1);
frs = send_async(&f, 1, 1);
send_async(drs, &d, 1, 1);

// wait for sends to be finished
brs.wait();
crs.wait();
irs.wait();
lrs.wait();
Expand All @@ -191,6 +207,12 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {

C4_Status status;

brr.wait(&status);
if (status.get_message_size() != sizeof(bool))
ITFAILS;
if (status.get_source() != 1)
ITFAILS;

crr.wait(&status);
if (status.get_message_size() != 1)
ITFAILS;
Expand Down Expand Up @@ -222,6 +244,8 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
ITFAILS;

// check values
if (br != false)
ITFAILS;
if (cr != 'B')
ITFAILS;
if (ir != 2)
Expand All @@ -238,13 +262,16 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
if (rtt_c4::node() == 1) {
// post receives
// Test both function that provide equivalent functionality.
brr = receive_async(&br, 1, 0);
receive_async(crr, &cr, 1, 0);
irr = receive_async(&ir, 1, 0);
receive_async(lrr, &lr, 1, 0);
receive_async(frr, &fr, 1, 0);
receive_async(drr, &dr, 1, 0);

// check that all are inuse
if (!brr.inuse())
ITFAILS;
if (!crr.inuse())
ITFAILS;
if (!irr.inuse())
Expand All @@ -258,7 +285,9 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {

// check on receives
int done = 0;
while (done < 5) {
while (done < 6) {
if (brr.complete())
done++;
if (crr.complete())
done++;
if (irr.complete())
Expand All @@ -271,6 +300,8 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
done++;
}

if (br != true)
ITFAILS;
if (cr != 'A')
ITFAILS;
if (ir != 1)
Expand All @@ -283,6 +314,7 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
ITFAILS;

// assign new values
b = false;
c = 'B';
i = 2;
l = 2000;
Expand All @@ -292,13 +324,15 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
// send them back
// Test both function that provide equivalent functionality.

brs = send_async(&b, 1, 0);
send_async(crs, &c, 1, 0);
irs = send_async(&i, 1, 0);
send_async(lrs, &l, 1, 0);
send_async(frs, &f, 1, 0);
send_async(drs, &d, 1, 0);

// wait for sends to be finished
brs.wait();
crs.wait();
irs.wait();
lrs.wait();
Expand All @@ -308,6 +342,8 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
rtt_c4::global_barrier();

// check that all requests are done
if (brs.inuse())
ITFAILS;
if (crs.inuse())
ITFAILS;
if (irs.inuse())
Expand All @@ -319,6 +355,8 @@ void non_blocking_ping_pong(rtt_dsxx::UnitTest &ut) {
if (drs.inuse())
ITFAILS;

if (brr.inuse())
ITFAILS;
if (crr.inuse())
ITFAILS;
if (irr.inuse())
Expand Down Expand Up @@ -435,6 +473,7 @@ void send_receive_ping_pong(rtt_dsxx::UnitTest &ut) {
if (rtt_c4::nodes() != 2)
return;

bool b = false, br;
char c = 0, cr;
int i = 0, ir;
long l = 0, lr;
Expand All @@ -443,19 +482,23 @@ void send_receive_ping_pong(rtt_dsxx::UnitTest &ut) {

// assign on node 0
if (rtt_c4::node() == 0) {
b = true;
c = 'A';
i = 1;
l = 1000;
f = 1.5;
d = 2.5;

send_receive(&b, 1, 1, &br, 1, 1);
send_receive(&c, 1, 1, &cr, 1, 1);
send_receive(&i, 1, 1, &ir, 1, 1);
send_receive(&l, 1, 1, &lr, 1, 1);
send_receive(&f, 1, 1, &fr, 1, 1);
send_receive(&d, 1, 1, &dr, 1, 1);

// check values
if (br != false)
ITFAILS;
if (cr != 'B')
ITFAILS;
if (ir != 2)
Expand All @@ -471,19 +514,23 @@ void send_receive_ping_pong(rtt_dsxx::UnitTest &ut) {
// receive and send on node 1
if (rtt_c4::node() == 1) {
// assign new values
b = false;
c = 'B';
i = 2;
l = 2000;
f = 2.5;
d = 3.5;

send_receive(&b, 1, 0, &br, 1, 0);
send_receive(&c, 1, 0, &cr, 1, 0);
send_receive(&i, 1, 0, &ir, 1, 0);
send_receive(&l, 1, 0, &lr, 1, 0);
send_receive(&f, 1, 0, &fr, 1, 0);
send_receive(&d, 1, 0, &dr, 1, 0);

// check values
if (br != true)
ITFAILS;
if (cr != 'A')
ITFAILS;
if (ir != 1)
Expand Down