Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQiao Mu <qiaomu@bytedance.com>2014-07-24 08:16:00 +0400
committerQiao Mu <qiaomu@bytedance.com>2014-07-24 09:54:25 +0400
commit7088e5a6665f95b5ca3267fd2ca075b4fe470c8d (patch)
tree6c7010e5a6cd1f30d7b833b819a69bbd8d32afc2 /vowpalwabbit/allreduce.h
parent3c18847b1935f83608824e095385d042d1d77bb9 (diff)
Fix float point overflow when doing pass up
The old way of rounding floor(x/((float)sizeof(int)))*sizeof(int)) will cause overflow when x is greater than 203672784. For example, if x is 203672792, the above expression will give 203672800. When this bigger value is minus by parent_sent_pos, negative value can be generated which is later assigned to an unsigned integer. This will cause the whole learning fail. This patch fixes the above expression and a potential network problem.
Diffstat (limited to 'vowpalwabbit/allreduce.h')
-rw-r--r--vowpalwabbit/allreduce.h9
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;
}
}