Created
July 5, 2016 11:26
-
-
Save Saurabh7/5840fb533c90ed233c5ad4a29777ce6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Reduce_Vectors | |
{ | |
public: | |
Reduce_Vectors(int size); | |
~Reduce_Vectors(); | |
void init(void); | |
void sum_scale_x(double scalar, feature_node *x); | |
void reduce_sum(double* v); | |
private: | |
int nr_thread; | |
int size; | |
double **tmp_array; | |
}; | |
Reduce_Vectors::Reduce_Vectors(int size) | |
{ | |
nr_thread = omp_get_max_threads(); | |
this->size = size; | |
tmp_array = new double*[nr_thread]; | |
for(int i = 0; i < nr_thread; i++) | |
tmp_array[i] = new double[size]; | |
} | |
Reduce_Vectors::~Reduce_Vectors(void) | |
{ | |
for(int i = 0; i < nr_thread; i++) | |
delete[] tmp_array[i]; | |
delete[] tmp_array; | |
} | |
void Reduce_Vectors::init(void) | |
{ | |
#pragma omp parallel for schedule(static) | |
for(int i = 0; i < size; i++) | |
for(int j = 0; j < nr_thread; j++) | |
tmp_array[j][i] = 0.0; | |
} | |
void Reduce_Vectors::sum_scale_x(double scalar, feature_node *x) | |
{ | |
int thread_id = omp_get_thread_num(); | |
sparse_operator::axpy(scalar, x, tmp_array[thread_id]); | |
} | |
void Reduce_Vectors::reduce_sum(double* v) | |
{ | |
#pragma omp parallel for schedule(static) | |
for(int i = 0; i < size; i++) | |
{ | |
v[i] = 0; | |
for(int j = 0; j < nr_thread; j++) | |
v[i] += tmp_array[j][i]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment