Skip to content

Commit 015c657

Browse files
authored
Merge pull request #28 from sfiligoi/igor_int64_230114
Enforce int64, to avoid overflow
2 parents 4e72fbf + ebddc61 commit 015c657

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/unifrac_task.hpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ namespace SUCMP_NM {
6969
#ifdef _OPENACC
7070
const uint64_t bufels = n_samples_r * (stop_idx-start_idx);
7171
#endif
72-
for(unsigned int stripe=start_idx; stripe < stop_idx; stripe++) {
72+
for(uint64_t stripe=start_idx; stripe < stop_idx; stripe++) {
7373
double * dm_stripe = dm_stripes[stripe];
74-
TFloat * buf_stripe = this->operator[](stripe);
75-
for(unsigned int j=0; j<n_samples; j++) {
74+
TFloat * buf_stripe = ibuf+buf_idx(stripe);
75+
for(uint64_t j=0; j<n_samples; j++) {
7676
// Note: We could probably just initialize to zero
7777
buf_stripe[j] = dm_stripe[j];
7878
}
79-
for(unsigned int j=n_samples; j<n_samples_r; j++) {
79+
for(uint64_t j=n_samples; j<n_samples_r; j++) {
8080
// Avoid NaNs
8181
buf_stripe[j] = 0.0;
8282
}
@@ -90,8 +90,8 @@ namespace SUCMP_NM {
9090
UnifracTaskVector<TFloat>(const UnifracTaskVector<TFloat>& ) = delete;
9191
UnifracTaskVector<TFloat>& operator= (const UnifracTaskVector<TFloat>&) = delete;
9292

93-
TFloat * operator[](unsigned int idx) { return buf+((idx-start_idx)*n_samples_r);}
94-
const TFloat * operator[](unsigned int idx) const { return buf+((idx-start_idx)*n_samples_r);}
93+
TFloat * operator[](unsigned int idx) { return buf+buf_idx(idx);}
94+
const TFloat * operator[](unsigned int idx) const { return buf+buf_idx(idx);}
9595

9696

9797
~UnifracTaskVector()
@@ -102,10 +102,10 @@ namespace SUCMP_NM {
102102
const uint64_t bufels = n_samples_r * (stop_idx-start_idx);
103103
#pragma acc exit data copyout(ibuf[:bufels])
104104
#endif
105-
for(unsigned int stripe=start_idx; stripe < stop_idx; stripe++) {
105+
for(uint64_t stripe=start_idx; stripe < stop_idx; stripe++) {
106106
double * dm_stripe = dm_stripes[stripe];
107-
TFloat * buf_stripe = this->operator[](stripe);
108-
for(unsigned int j=0; j<n_samples; j++) {
107+
TFloat * buf_stripe = ibuf+buf_idx(stripe);
108+
for(uint64_t j=0; j<n_samples; j++) {
109109
dm_stripe[j] = buf_stripe[j];
110110
}
111111
}
@@ -116,6 +116,8 @@ namespace SUCMP_NM {
116116
private:
117117
UnifracTaskVector() = delete;
118118
UnifracTaskVector operator=(const UnifracTaskVector&other) const = delete;
119+
120+
uint64_t buf_idx(uint64_t idx) const { return ((idx-start_idx)*n_samples_r);}
119121
};
120122

121123
// Base task class to be shared by all tasks

0 commit comments

Comments
 (0)