Skip to content

Commit

Permalink
create inital code for the Omp Executor
Browse files Browse the repository at this point in the history
  • Loading branch information
Eoli-an committed Jan 21, 2020
1 parent aee5f40 commit 4e0cd70
Showing 1 changed file with 57 additions and 51 deletions.
108 changes: 57 additions & 51 deletions omp/solver/bicg_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,79 +58,85 @@ void initialize(std::shared_ptr<const OmpExecutor> exec,
const matrix::Dense<ValueType> *b, matrix::Dense<ValueType> *r,
matrix::Dense<ValueType> *z, matrix::Dense<ValueType> *p,
matrix::Dense<ValueType> *q, matrix::Dense<ValueType> *prev_rho,
matrix::Dense<ValueType> *rho,
matrix::Dense<ValueType> *rho, matrix::Dense<ValueType> *r2,
matrix::Dense<ValueType> *z2, matrix::Dense<ValueType> *p2,
matrix::Dense<ValueType> *q2,
Array<stopping_status> *stop_status) GKO_NOT_IMPLEMENTED;
//{
// TODO (script): change the code imported from solver/cg if needed
//#pragma omp parallel for
// for (size_type j = 0; j < b->get_size()[1]; ++j) {
// rho->at(j) = zero<ValueType>();
// prev_rho->at(j) = one<ValueType>();
// stop_status->get_data()[j].reset();
// }
//#pragma omp parallel for
// for (size_type i = 0; i < b->get_size()[0]; ++i) {
// for (size_type j = 0; j < b->get_size()[1]; ++j) {
// r->at(i, j) = b->at(i, j);
// z->at(i, j) = p->at(i, j) = q->at(i, j) = zero<ValueType>();
// }
// }
//}
{
#pragma omp parallel for
for (size_type j = 0; j < b->get_size()[1]; ++j) {
rho->at(j) = zero<ValueType>();
prev_rho->at(j) = one<ValueType>();
stop_status->get_data()[j].reset();
}
#pragma omp parallel for
for (size_type i = 0; i < b->get_size()[0]; ++i) {
for (size_type j = 0; j < b->get_size()[1]; ++j) {
r->at(i, j) = b->at(i, j);
r2->at(i, j) = b->at(i, j);
z->at(i, j) = p->at(i, j) = q->at(i, j) = zero<ValueType>();
z2->at(i, j) = p2->at(i, j) = q2->at(i, j) = zero<ValueType>();
}
}
}

GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_BICG_INITIALIZE_KERNEL);


template <typename ValueType>
void step_1(std::shared_ptr<const OmpExecutor> exec,
matrix::Dense<ValueType> *p, const matrix::Dense<ValueType> *z,
matrix::Dense<ValueType> *p2, const matrix::Dense<ValueType> *z2,
const matrix::Dense<ValueType> *rho,
const matrix::Dense<ValueType> *prev_rho,
const Array<stopping_status> *stop_status) GKO_NOT_IMPLEMENTED;
//{
// TODO (script): change the code imported from solver/cg if needed
//#pragma omp parallel for
// for (size_type i = 0; i < p->get_size()[0]; ++i) {
// for (size_type j = 0; j < p->get_size()[1]; ++j) {
// if (stop_status->get_const_data()[j].has_stopped()) {
// continue;
// }
// if (prev_rho->at(j) == zero<ValueType>()) {
// p->at(i, j) = z->at(i, j);
// } else {
// auto tmp = rho->at(j) / prev_rho->at(j);
// p->at(i, j) = z->at(i, j) + tmp * p->at(i, j);
// }
// }
// }
//}
{
#pragma omp parallel for
for (size_type i = 0; i < p->get_size()[0]; ++i) {
for (size_type j = 0; j < p->get_size()[1]; ++j) {
if (stop_status->get_const_data()[j].has_stopped()) {
continue;
}
if (prev_rho->at(j) == zero<ValueType>()) {
p->at(i, j) = z->at(i, j);
p2->at(i, j) = z2->at(i, j);
} else {
auto tmp = rho->at(j) / prev_rho->at(j);
p->at(i, j) = z->at(i, j) + tmp * p->at(i, j);
p2->at(i, j) = z2->at(i, j) + tmp * p2->at(i, j);
}
}
}
}

GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_BICG_STEP_1_KERNEL);


template <typename ValueType>
void step_2(std::shared_ptr<const OmpExecutor> exec,
matrix::Dense<ValueType> *x, matrix::Dense<ValueType> *r,
const matrix::Dense<ValueType> *p,
matrix::Dense<ValueType> *r2, const matrix::Dense<ValueType> *p,
const matrix::Dense<ValueType> *q,
const matrix::Dense<ValueType> *q2,
const matrix::Dense<ValueType> *beta,
const matrix::Dense<ValueType> *rho,
const Array<stopping_status> *stop_status) GKO_NOT_IMPLEMENTED;
//{
// TODO (script): change the code imported from solver/cg if needed
//#pragma omp parallel for
// for (size_type i = 0; i < x->get_size()[0]; ++i) {
// for (size_type j = 0; j < x->get_size()[1]; ++j) {
// if (stop_status->get_const_data()[j].has_stopped()) {
// continue;
// }
// if (beta->at(j) != zero<ValueType>()) {
// auto tmp = rho->at(j) / beta->at(j);
// x->at(i, j) += tmp * p->at(i, j);
// r->at(i, j) -= tmp * q->at(i, j);
// }
// }
// }
//}
{
#pragma omp parallel for
for (size_type i = 0; i < x->get_size()[0]; ++i) {
for (size_type j = 0; j < x->get_size()[1]; ++j) {
if (stop_status->get_const_data()[j].has_stopped()) {
continue;
}
if (beta->at(j) != zero<ValueType>()) {
auto tmp = rho->at(j) / beta->at(j);
x->at(i, j) += tmp * p->at(i, j); // p2?
r->at(i, j) -= tmp * q->at(i, j);
r2->at(i, j) -= tmp * q2->at(i, j);
}
}
}
}

GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_BICG_STEP_2_KERNEL);

Expand Down

0 comments on commit 4e0cd70

Please sign in to comment.