diff options
author | John <jl@hunch.net> | 2014-07-24 17:35:12 +0400 |
---|---|---|
committer | John <jl@hunch.net> | 2014-07-24 17:35:12 +0400 |
commit | 0e032b78dfb886ba96e3eb9ae9eaa227653ee5ca (patch) | |
tree | 6c7010e5a6cd1f30d7b833b819a69bbd8d32afc2 | |
parent | 3c18847b1935f83608824e095385d042d1d77bb9 (diff) | |
parent | 7088e5a6665f95b5ca3267fd2ca075b4fe470c8d (diff) |
Merge pull request #348 from qiaomuf/master
Fix float point overflow when doing pass up
-rw-r--r-- | vowpalwabbit/allreduce.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/vowpalwabbit/allreduce.h b/vowpalwabbit/allreduce.h index 07ecafc7..ecac009b 100644 --- a/vowpalwabbit/allreduce.h +++ b/vowpalwabbit/allreduce.h @@ -62,15 +62,16 @@ template <class T, void (*f)(T&, const T&)> void addbufs(T* buf1, const T* buf2, void all_reduce_init(const string master_location, const size_t unique_id, const size_t total, const size_t node, node_socks& socks); template <class T> void pass_up(char* buffer, size_t left_read_pos, size_t right_read_pos, size_t& parent_sent_pos, socket_t parent_sock, size_t n) { - size_t my_bufsize = min(ar_buf_size, ((int)(floor(left_read_pos/((float)sizeof(T)))*sizeof(T)) - parent_sent_pos)); - my_bufsize = min(my_bufsize, ((int)(floor(right_read_pos/((float)sizeof(T)))*sizeof(T)) - parent_sent_pos)); + size_t my_bufsize = min(ar_buf_size, min(left_read_pos, right_read_pos) / sizeof(T) * sizeof(T) - parent_sent_pos); if(my_bufsize > 0) { //going to pass up this chunk of data to the parent int write_size = send(parent_sock, buffer+parent_sent_pos, (int)my_bufsize, 0); - if(write_size < (int)my_bufsize) + if(write_size < 0) { cerr<<"Write to parent failed "<<my_bufsize<<" "<<write_size<<" "<<parent_sent_pos<<" "<<left_read_pos<<" "<<right_read_pos<<endl ; - parent_sent_pos += my_bufsize; + throw exception(); + } + parent_sent_pos += write_size; } } |