Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/error-handling-nvector' …
Browse files Browse the repository at this point in the history
…into feature/error-handling-nvector
  • Loading branch information
balos1 committed Dec 11, 2023
2 parents 810aac3 + f906dd8 commit ff1ef9d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 28 deletions.
39 changes: 21 additions & 18 deletions src/nvector/manyvector/nvector_manyvector.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ N_Vector N_VNew_ManyVector(sunindextype num_subvectors, N_Vector* vec_array,
local_length = 0;
for (i = 0; i < num_subvectors; i++)
{
SUNAssertNull(vec_array[i]->ops->nvgetlength, SUN_ERR_ARG_CORRUPT);
local_length += N_VGetLength(vec_array[i]);
SUNCheckLastErrNull();
}
content->global_length = local_length;

Expand All @@ -411,7 +411,7 @@ N_Vector N_VNew_ManyVector(sunindextype num_subvectors, N_Vector* vec_array,
N_Vector MVAPPEND(N_VGetSubvector)(N_Vector v, sunindextype vec_num)
{
SUNFunctionBegin(v->sunctx);
SUNAssertNull(vec_num >= 0 || vec_num <= MANYVECTOR_NUM_SUBVECS(v),
SUNAssertNull(vec_num >= 0 && vec_num <= MANYVECTOR_NUM_SUBVECS(v),
SUN_ERR_ARG_OUTOFRANGE);
return (MANYVECTOR_SUBVEC(v, vec_num));
}
Expand All @@ -424,7 +424,7 @@ sunrealtype* MVAPPEND(N_VGetSubvectorArrayPointer)(N_Vector v,
sunindextype vec_num)
{
SUNFunctionBegin(v->sunctx);
SUNAssertNull(vec_num >= 0 || vec_num <= MANYVECTOR_NUM_SUBVECS(v),
SUNAssertNull(vec_num >= 0 && vec_num <= MANYVECTOR_NUM_SUBVECS(v),
SUN_ERR_ARG_OUTOFRANGE);
if (MANYVECTOR_SUBVEC(v, vec_num)->ops->nvgetarraypointer == NULL)
{
Expand All @@ -441,9 +441,10 @@ SUNErrCode MVAPPEND(N_VSetSubvectorArrayPointer)(sunrealtype* v_data, N_Vector v
sunindextype vec_num)
{
SUNFunctionBegin(v->sunctx);
SUNAssert(vec_num >= 0 || vec_num <= MANYVECTOR_NUM_SUBVECS(v),
SUNAssert(vec_num >= 0 && vec_num <= MANYVECTOR_NUM_SUBVECS(v),
SUN_ERR_ARG_OUTOFRANGE);
N_VSetArrayPointer(v_data, MANYVECTOR_SUBVEC(v, vec_num));
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -567,7 +568,7 @@ void MVAPPEND(N_VSpace)(N_Vector v, sunindextype* lrw, sunindextype* liw)
if ((MANYVECTOR_SUBVEC(v, i))->ops->nvspace != NULL)
{
N_VSpace(MANYVECTOR_SUBVEC(v, i), &lrw1, &liw1);
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
*lrw += lrw1;
*liw += liw1;
}
Expand Down Expand Up @@ -609,7 +610,7 @@ void MVAPPEND(N_VLinearSum)(sunrealtype a, N_Vector x, sunrealtype b,
{
N_VLinearSum(a, MANYVECTOR_SUBVEC(x, i), b, MANYVECTOR_SUBVEC(y, i),
MANYVECTOR_SUBVEC(z, i));
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
}
return;
}
Expand All @@ -622,7 +623,7 @@ void MVAPPEND(N_VConst)(sunrealtype c, N_Vector z)
for (i = 0; i < MANYVECTOR_NUM_SUBVECS(z); i++)
{
N_VConst(c, MANYVECTOR_SUBVEC(z, i));
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
}
return;
}
Expand All @@ -638,7 +639,7 @@ void MVAPPEND(N_VProd)(N_Vector x, N_Vector y, N_Vector z)
{
N_VProd(MANYVECTOR_SUBVEC(x, i), MANYVECTOR_SUBVEC(y, i),
MANYVECTOR_SUBVEC(z, i));
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
}
return;
}
Expand All @@ -654,7 +655,7 @@ void MVAPPEND(N_VDiv)(N_Vector x, N_Vector y, N_Vector z)
{
N_VDiv(MANYVECTOR_SUBVEC(x, i), MANYVECTOR_SUBVEC(y, i),
MANYVECTOR_SUBVEC(z, i));
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
}
return;
}
Expand All @@ -669,7 +670,7 @@ void MVAPPEND(N_VScale)(sunrealtype c, N_Vector x, N_Vector z)
for (i = 0; i < MANYVECTOR_NUM_SUBVECS(x); i++)
{
N_VScale(c, MANYVECTOR_SUBVEC(x, i), MANYVECTOR_SUBVEC(z, i));
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
}
return;
}
Expand All @@ -684,7 +685,7 @@ void MVAPPEND(N_VAbs)(N_Vector x, N_Vector z)
for (i = 0; i < MANYVECTOR_NUM_SUBVECS(x); i++)
{
N_VAbs(MANYVECTOR_SUBVEC(x, i), MANYVECTOR_SUBVEC(z, i));
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
}
return;
}
Expand All @@ -699,7 +700,7 @@ void MVAPPEND(N_VInv)(N_Vector x, N_Vector z)
for (i = 0; i < MANYVECTOR_NUM_SUBVECS(x); i++)
{
N_VInv(MANYVECTOR_SUBVEC(x, i), MANYVECTOR_SUBVEC(z, i));
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
}
return;
}
Expand All @@ -714,7 +715,7 @@ void MVAPPEND(N_VAddConst)(N_Vector x, sunrealtype b, N_Vector z)
for (i = 0; i < MANYVECTOR_NUM_SUBVECS(x); i++)
{
N_VAddConst(MANYVECTOR_SUBVEC(x, i), b, MANYVECTOR_SUBVEC(z, i));
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
}
return;
}
Expand Down Expand Up @@ -1178,7 +1179,7 @@ void MVAPPEND(N_VCompare)(sunrealtype c, N_Vector x, N_Vector z)
for (i = 0; i < MANYVECTOR_NUM_SUBVECS(x); i++)
{
N_VCompare(c, MANYVECTOR_SUBVEC(x, i), MANYVECTOR_SUBVEC(z, i));
SUNCheckLastErrNoRet();
SUNCheckLastErrVoid();
}
return;
}
Expand Down Expand Up @@ -1524,7 +1525,7 @@ SUNErrCode MVAPPEND(N_VDotProdMulti)(int nvec, N_Vector x, N_Vector* Y,
for (i = 0; i < nvec; i++)
{
dotprods[i] = N_VDotProdLocal(x, Y[i]);
SUNCheckLastErrNoRet();
SUNCheckLastErr();
}

#ifdef MANYVECTOR_BUILD_WITH_MPI
Expand Down Expand Up @@ -1584,7 +1585,7 @@ SUNErrCode MVAPPEND(N_VLinearSumVectorArray)(int nvec, sunrealtype a,
}

/* now call N_VLinearSumVectorArray for this array of subvectors */
SUNCheckCallNoRet(N_VLinearSumVectorArray(nvec, a, Xsub, b, Ysub, Zsub));
SUNCheckCall(N_VLinearSumVectorArray(nvec, a, Xsub, b, Ysub, Zsub));
}

/* clean up and return */
Expand Down Expand Up @@ -1695,7 +1696,7 @@ SUNErrCode MVAPPEND(N_VWrmsNormVectorArray)(int nvec, N_Vector* X, N_Vector* W,
for (i = 0; i < nvec; i++)
{
nrm[i] = N_VWSqrSumLocal(X[i], W[i]);
SUNCheckLastErrNoRet();
SUNCheckLastErr();
}

/* accumulate totals */
Expand Down Expand Up @@ -1740,7 +1741,7 @@ SUNErrCode MVAPPEND(N_VWrmsNormMaskVectorArray)(int nvec, N_Vector* X,
for (i = 0; i < nvec; i++)
{
nrm[i] = N_VWSqrSumMaskLocal(X[i], W[i], id);
SUNCheckLastErrNoRet();
SUNCheckLastErr();
}

/* accumulate totals */
Expand Down Expand Up @@ -1795,6 +1796,7 @@ SUNErrCode MVAPPEND(N_VBufPack)(N_Vector x, void* buf)
sunindextype offset; /* subvector buffer offset */
sunindextype i;

SUNAssert(x, SUN_ERR_ARG_CORRUPT);
SUNAssert(buf, SUN_ERR_ARG_CORRUPT);

/* start at the beginning of the output buffer */
Expand Down Expand Up @@ -1825,6 +1827,7 @@ SUNErrCode MVAPPEND(N_VBufUnpack)(N_Vector x, void* buf)
sunindextype offset; /* subvector buffer offset */
sunindextype i;

SUNAssert(x, SUN_ERR_ARG_CORRUPT);
SUNAssert(buf, SUN_ERR_ARG_CORRUPT);

/* start at the beginning of the input buffer */
Expand Down
18 changes: 17 additions & 1 deletion src/nvector/openmp/nvector_openmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1068,13 +1068,15 @@ SUNErrCode N_VLinearCombination_OpenMP(int nvec, sunrealtype* c, N_Vector* X,
if (nvec == 1)
{
N_VScale_OpenMP(c[0], X[0], z);
SUNCheckLastErr();
return SUN_SUCCESS;
}

/* should have called N_VLinearSum */
if (nvec == 2)
{
N_VLinearSum_OpenMP(c[0], X[0], c[1], X[1], z);
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1162,6 +1164,7 @@ SUNErrCode N_VScaleAddMulti_OpenMP(int nvec, sunrealtype* a, N_Vector x,
if (nvec == 1)
{
N_VLinearSum_OpenMP(a[0], x, ONE, Y[0], Z[0]);
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1225,6 +1228,7 @@ SUNErrCode N_VDotProdMulti_OpenMP(int nvec, N_Vector x, N_Vector* Y,
if (nvec == 1)
{
dotprods[0] = N_VDotProd_OpenMP(x, Y[0]);
SUNCheckLastCall();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1286,6 +1290,7 @@ SUNErrCode N_VLinearSumVectorArray_OpenMP(int nvec, sunrealtype a, N_Vector* X,
if (nvec == 1)
{
N_VLinearSum_OpenMP(a, X[0], b, Y[0], Z[0]);
SUNCheckLastCall();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1406,6 +1411,7 @@ SUNErrCode N_VScaleVectorArray_OpenMP(int nvec, sunrealtype* c, N_Vector* X,
if (nvec == 1)
{
N_VScale_OpenMP(c[0], X[0], Z[0]);
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1465,6 +1471,7 @@ SUNErrCode N_VConstVectorArray_OpenMP(int nvec, sunrealtype c, N_Vector* Z)
if (nvec == 1)
{
N_VConst_OpenMP(c, Z[0]);
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1507,6 +1514,7 @@ SUNErrCode N_VWrmsNormVectorArray_OpenMP(int nvec, N_Vector* X, N_Vector* W,
if (nvec == 1)
{
nrm[0] = N_VWrmsNorm_OpenMP(X[0], W[0]);
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1561,6 +1569,7 @@ SUNErrCode N_VWrmsNormMaskVectorArray_OpenMP(int nvec, N_Vector* X, N_Vector* W,
if (nvec == 1)
{
nrm[0] = N_VWrmsNormMask_OpenMP(X[0], W[0], id);
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1629,6 +1638,7 @@ SUNErrCode N_VScaleAddMultiVectorArray_OpenMP(int nvec, int nsum,
if (nsum == 1)
{
N_VLinearSum_OpenMP(a[0], X[0], ONE, Y[0][0], Z[0][0]);
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1742,13 +1752,15 @@ SUNErrCode N_VLinearCombinationVectorArray_OpenMP(int nvec, int nsum,
if (nsum == 1)
{
N_VScale_OpenMP(c[0], X[0][0], Z[0]);
SUNCheckLastErr();
return SUN_SUCCESS;
}

/* should have called N_VLinearSum */
if (nsum == 2)
{
N_VLinearSum_OpenMP(c[0], X[0][0], c[1], X[1][0], Z[0]);
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand All @@ -1757,7 +1769,7 @@ SUNErrCode N_VLinearCombinationVectorArray_OpenMP(int nvec, int nsum,

for (i = 0; i < nsum; i++) { Y[i] = X[i][0]; }

N_VLinearCombination_OpenMP(nsum, c, Y, Z[0]);
SUNCheckCall(N_VLinearCombination_OpenMP(nsum, c, Y, Z[0]));

free(Y);
return SUN_SUCCESS;
Expand All @@ -1775,6 +1787,7 @@ SUNErrCode N_VLinearCombinationVectorArray_OpenMP(int nvec, int nsum,
for (j = 0; j < nvec; j++) { ctmp[j] = c[0]; }

N_VScaleVectorArray_OpenMP(nvec, ctmp, X[0], Z);
SUNCheckLastErr();

free(ctmp);
return SUN_SUCCESS;
Expand All @@ -1784,6 +1797,7 @@ SUNErrCode N_VLinearCombinationVectorArray_OpenMP(int nvec, int nsum,
if (nsum == 2)
{
N_VLinearSumVectorArray_OpenMP(nvec, c[0], X[0], c[1], X[1], Z);
SUNCheckLastErr();
return SUN_SUCCESS;
}

Expand Down Expand Up @@ -1885,6 +1899,7 @@ SUNErrCode N_VBufPack_OpenMP(N_Vector x, void* buf)
sunrealtype* xd = NULL;
sunrealtype* bd = NULL;

SUNAssert(x, SUN_ERR_ARG_CORRUPT);
SUNAssert(buf, SUN_ERR_ARG_CORRUPT);

N = NV_LENGTH_OMP(x);
Expand All @@ -1905,6 +1920,7 @@ SUNErrCode N_VBufUnpack_OpenMP(N_Vector x, void* buf)
sunrealtype* xd = NULL;
sunrealtype* bd = NULL;

SUNAssert(x, SUN_ERR_ARG_CORRPUT);
SUNAssert(buf, SUN_ERR_ARG_CORRUPT);

N = NV_LENGTH_OMP(x);
Expand Down
8 changes: 4 additions & 4 deletions src/nvector/parallel/nvector_parallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ SUNErrCode N_VDotProdMulti_Parallel(int nvec, N_Vector x, N_Vector* Y,
for (j = 0; j < N; j++) { dotprods[i] += xd[j] * yd[j]; }
}

SUNCheckMPICallNoRet(MPI_Allreduce(MPI_IN_PLACE, dotprods, nvec,
SUNCheckMPICall(MPI_Allreduce(MPI_IN_PLACE, dotprods, nvec,
MPI_SUNREALTYPE, MPI_SUM, comm));

return SUN_SUCCESS;
Expand Down Expand Up @@ -1177,7 +1177,7 @@ SUNErrCode N_VDotProdMultiAllReduce_Parallel(int nvec, N_Vector x,
comm = NV_COMM_P(x);

/* perform reduction */
SUNCheckMPICallNoRet(
SUNCheckMPICall(
MPI_Allreduce(MPI_IN_PLACE, sum, nvec, MPI_SUNREALTYPE, MPI_SUM, comm));

return SUN_SUCCESS;
Expand Down Expand Up @@ -1403,7 +1403,7 @@ SUNErrCode N_VWrmsNormVectorArray_Parallel(int nvec, N_Vector* X, N_Vector* W,
nrm[i] = ZERO;
for (j = 0; j < Nl; j++) { nrm[i] += SUNSQR(xd[j] * wd[j]); }
}
SUNCheckMPICallNoRet(
SUNCheckMPICall(
MPI_Allreduce(MPI_IN_PLACE, nrm, nvec, MPI_SUNREALTYPE, MPI_SUM, comm));

for (int i = 0; i < nvec; i++) { nrm[i] = SUNRsqrt(nrm[i] / Ng); }
Expand Down Expand Up @@ -1449,7 +1449,7 @@ SUNErrCode N_VWrmsNormMaskVectorArray_Parallel(int nvec, N_Vector* X, N_Vector*
if (idd[j] > ZERO) { nrm[i] += SUNSQR(xd[j] * wd[j]); }
}
}
SUNCheckMPICallNoRet(
SUNCheckMPICall(
MPI_Allreduce(MPI_IN_PLACE, nrm, nvec, MPI_SUNREALTYPE, MPI_SUM, comm));

for (int i = 0; i < nvec; i++) { nrm[i] = SUNRsqrt(nrm[i] / Ng); }
Expand Down
Loading

0 comments on commit ff1ef9d

Please sign in to comment.