Skip to content

Commit

Permalink
update io signature
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxiao1254 committed Apr 14, 2022
1 parent 203bc53 commit 81f5ed2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
32 changes: 16 additions & 16 deletions emp-tool/io/io_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ namespace emp {
template<typename T>
class IOChannel { public:
uint64_t counter = 0;
void send_data(const void * data, int nbyte) {
void send_data(const void * data, size_t nbyte) {
counter +=nbyte;
derived().send_data_internal(data, nbyte);
}

void recv_data(void * data, int nbyte) {
void recv_data(void * data, size_t nbyte) {
derived().recv_data_internal(data, nbyte);
}

void send_block(const block* data, int nblock) {
void send_block(const block* data, size_t nblock) {
send_data(data, nblock*sizeof(block));
}

void recv_block(block* data, int nblock) {
void recv_block(block* data, size_t nblock) {
recv_data(data, nblock*sizeof(block));
}

void send_pt(Point *A, int num_pts = 1) {
for(int i = 0; i < num_pts; ++i) {
void send_pt(Point *A, size_t num_pts = 1) {
for(size_t i = 0; i < num_pts; ++i) {
size_t len = A[i].size();
A[i].group->resize_scratch(len);
unsigned char * tmp = A[i].group->scratch;
Expand All @@ -38,9 +38,9 @@ class IOChannel { public:
}
}

void recv_pt(Group * g, Point *A, int num_pts = 1) {
void recv_pt(Group * g, Point *A, size_t num_pts = 1) {
size_t len = 0;
for(int i = 0; i < num_pts; ++i) {
for(size_t i = 0; i < num_pts; ++i) {
recv_data(&len, 4);
assert(len <= 2048);
g->resize_scratch(len);
Expand All @@ -50,36 +50,36 @@ class IOChannel { public:
}
}

void send_bool(bool * data, int length) {
void send_bool(bool * data, size_t length) {
void * ptr = (void *)data;
size_t space = length;
const void * aligned = std::align(alignof(uint64_t), sizeof(uint64_t), ptr, space);
if(aligned == nullptr)
send_data(data, length);
else{
int diff = length - space;
size_t diff = length - space;
send_data(data, diff);
send_bool_aligned((const bool*)aligned, length - diff);
}
}

void recv_bool(bool * data, int length) {
void recv_bool(bool * data, size_t length) {
void * ptr = (void *)data;
size_t space = length;
void * aligned = std::align(alignof(uint64_t), sizeof(uint64_t), ptr, space);
if(aligned == nullptr)
recv_data(data, length);
else{
int diff = length - space;
size_t diff = length - space;
recv_data(data, diff);
recv_bool_aligned((bool*)aligned, length - diff);
}
}


void send_bool_aligned(const bool * data, int length) {
void send_bool_aligned(const bool * data, size_t length) {
unsigned long long * data64 = (unsigned long long * )data;
int i = 0;
size_t i = 0;
for(; i < length/8; ++i) {
unsigned long long mask = 0x0101010101010101ULL;
unsigned long long tmp = 0;
Expand All @@ -97,9 +97,9 @@ class IOChannel { public:
if (8*i != length)
send_data(data + 8*i, length - 8*i);
}
void recv_bool_aligned(bool * data, int length) {
void recv_bool_aligned(bool * data, size_t length) {
unsigned long long * data64 = (unsigned long long *) data;
int i = 0;
size_t i = 0;
for(; i < length/8; ++i) {
unsigned long long mask = 0x0101010101010101ULL;
unsigned long long tmp = 0;
Expand Down
6 changes: 3 additions & 3 deletions emp-tool/io/net_io_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class NetIO: public IOChannel<NetIO> { public:
fflush(stream);
}

void send_data_internal(const void * data, int len) {
int sent = 0;
void send_data_internal(const void * data, size_t len) {
size_t sent = 0;
while(sent < len) {
int res = fwrite(sent + (char*)data, 1, len - sent, stream);
if (res >= 0)
Expand All @@ -130,7 +130,7 @@ class NetIO: public IOChannel<NetIO> { public:
has_sent = true;
}

void recv_data_internal(void * data, int len) {
void recv_data_internal(void * data, size_t len) {
if(has_sent)
fflush(stream);
has_sent = false;
Expand Down

0 comments on commit 81f5ed2

Please sign in to comment.