Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/PCGSolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ bool PCGSolver<OperatorType, ScalarDataType, PrecondDataType>::solve(
pb::GridFunc<PrecondDataType> prec_z(finegrid, bc_[0], bc_[1], bc_[2]);
pb::GridFunc<PrecondDataType> prec_res(res);
/* preconditioning step */
prec_z.setValues(0.);
prec_z.setZero();
preconSolve(prec_z, prec_res, 0);
pb::GridFunc<ScalarDataType> z(prec_z);

Expand Down Expand Up @@ -236,7 +236,7 @@ bool PCGSolver<OperatorType, ScalarDataType, PrecondDataType>::solve(
converged = true;
break;
}
prec_z.setValues(0.);
prec_z.setZero();
prec_res.setValues(res);
preconSolve(prec_z, prec_res, 0);
z.setValues(prec_z);
Expand Down
33 changes: 16 additions & 17 deletions src/pb/GridFunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ double GridFunc<double>::fmax()
int n = grid_.sizeg();
int imax = IDAMAX(&n, &uu_[0], &ione) - 1;

double vmax = mype_env().double_max_all(uu_[imax]);

return vmax;
return mype_env().double_max_all(uu_[imax]);
}

template <>
Expand All @@ -90,9 +88,7 @@ double GridFunc<float>::fmax()
int n = grid_.sizeg();
int imax = ISAMAX(&n, &uu_[0], &ione) - 1;

double vmax = mype_env().double_max_all((double)uu_[imax]);

return vmax;
return mype_env().double_max_all((double)uu_[imax]);
}

template <typename T>
Expand Down Expand Up @@ -219,8 +215,7 @@ GridFunc<T>::GridFunc(const GridFunc<double>& A) : grid_(A.grid())

alloc();

int n = grid_.sizeg();
MPcpy(uu_, A.uu(), n);
MPcpy(uu_, A.uu(), grid_.sizeg());

updated_boundaries_ = A.updated_boundaries();
}
Expand Down Expand Up @@ -276,13 +271,11 @@ GridFunc<T>::GridFunc(const GridFunc<T>& A, const Grid& new_grid)

for (int ix = 0; ix < dim_[0]; ix++)
{

int ix1 = (ix + shift1) * incx_ + shift1;
int ix2 = (ix + shift2) * incx2 + shift2;

for (int iy = 0; iy < dim_[1]; iy++)
{

int iy1 = ix1 + (iy + shift1) * incy_;
int iy2 = ix2 + (iy + shift2) * incy2;

Expand Down Expand Up @@ -331,13 +324,11 @@ void GridFunc<T>::set_max(const T val)
}

template <typename T>
void GridFunc<T>::setValues(const int n, const T* src, const int pos)
void GridFunc<T>::setValues(const int n, const T* src)
{
assert((pos + n) <= static_cast<int>(grid_.sizeg()));
assert(n <= static_cast<int>(grid_.sizeg()));

size_t ssize = n * sizeof(T);
// int ione=1;
memcpy(&uu_[pos], src, ssize);
memcpy(uu_, src, n * sizeof(T));
}

template <typename T>
Expand Down Expand Up @@ -365,6 +356,14 @@ GridFunc<T>& GridFunc<T>::operator=(const GridFunc<T>& func)
return *this;
}

template <typename T>
void GridFunc<T>::setZero()
{
memset(uu_, 0, grid_.sizeg()*sizeof(T));

updated_boundaries_ = true;
}

template <typename T>
void GridFunc<T>::setValues(const T val)
{
Expand All @@ -373,14 +372,15 @@ void GridFunc<T>::setValues(const T val)

for (int i = 0; i < n; i++)
pu[i] = val;

updated_boundaries_ = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a bug, since we were not doing this before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not a bug. But by not doing that, we were triggering ghost values filling later when not needed (since ghost values are set here)

}

template <typename T>
GridFunc<T>& GridFunc<T>::operator=(const T val)
{
setValues(val);

updated_boundaries_ = true;
return *this;
}

Expand Down Expand Up @@ -516,7 +516,6 @@ GridFunc<T>& GridFunc<T>::operator*=(const double alpha)
template <typename T>
void GridFunc<T>::scal(const double alpha)
{

LinearAlgebraUtils<MemorySpace::Host>::MPscal(grid_.sizeg(), alpha, uu_);
}

Expand Down
3 changes: 2 additions & 1 deletion src/pb/GridFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class GridFunc : public GridFuncInterface
static std::vector<T> buf3_;
static std::vector<T> buf4_;

void setValues(const int n, const T* src, const int pos = 0);
void setValues(const int n, const T* src);

public:
// Constructors
Expand All @@ -114,6 +114,7 @@ class GridFunc : public GridFuncInterface

void setValues(const GridFunc<T>& src);
void setValues(const T val);
void setZero();

int inc(const short dir) const { return grid_.inc(dir); }

Expand Down