Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
balos1 committed Dec 13, 2023
1 parent 7efa09f commit 70776b8
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 192 deletions.
2 changes: 1 addition & 1 deletion doc/superbuild/source/developers/getting_started/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Getting Started
SUNDIALS uses Git for distributed version control. If you have not setup Git on
your system, see the :ref:`GitSetup` section for details on configuring Git and
cloning the SUNDIALS repository. A list of helpful commands can be found in the
:ref:`GitCheatSheet`. The typical evelopment workflow is described in the
:ref:`GitCheatSheet`. The typical development workflow is described in the
:ref:`Workflow` section.

.. toctree::
Expand Down
4 changes: 2 additions & 2 deletions doc/superbuild/source/developers/style_guide/SourceCode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Coding Conventions and Rules
are the ``SUNLogger`` and ``SUNProfiler`` classes.

#. All SUNDIALS functions should return a ``SUNErrCode``. Many older functions
do not do this and are exceptions to the rule for backwards compatiblilty.
do not do this and are exceptions to the rule for backwards compatibility.
In addition, internal helper functions may or may-not return a ``SUNErrCode``.

#. All SUNDIALS functions, with the exception of some functions
Expand Down Expand Up @@ -385,7 +385,7 @@ Coding Conventions and Rules
#. If statements and loops should always have braces even if they are one line.

#. Return statements should not unecessarily use parentheses. Prefer ``return
#. Return statements should not unnecessarily use parentheses. Prefer ``return
x;`` to ``return(x);``. Note, however, lots of older SUNDIALS source code
uses ``return(x);``.

Expand Down
49 changes: 32 additions & 17 deletions src/nvector/manyvector/nvector_manyvector.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* of the NVECTOR package.
* -----------------------------------------------------------------*/

#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>

Expand Down Expand Up @@ -268,8 +269,14 @@ N_Vector N_VNew_MPIManyVector(sunindextype num_subvectors, N_Vector* vec_array,
else
{
SUNCheckMPICallNoRet(MPI_Comm_compare(vcomm, comm, &comparison));
SUNCheckNull((comparison == MPI_IDENT) || (comparison == MPI_CONGRUENT),
SUN_ERR_ARG_INCOMPATIBLE);
if ((comparison != MPI_IDENT) && (comparison != MPI_CONGRUENT))
{
SUNHandleErrWithMsg(__LINE__, __func__, __FILE__,
"All subvectors must have the same communicator, "
"i.e., MPI_Comm_compare must return MPI_IDENT or "
"MPI_CONGRUENT.",
SUN_ERR_ARG_INCOMPATIBLE, SUNCTX_);
}
}
}

Expand Down Expand Up @@ -398,6 +405,7 @@ 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_NOT_IMPLEMENTED);
local_length += N_VGetLength(vec_array[i]);
SUNCheckLastErrNull();
}
Expand All @@ -413,7 +421,7 @@ N_Vector MVAPPEND(N_VGetSubvector)(N_Vector v, sunindextype vec_num)
{
SUNFunctionBegin(v->sunctx);
SUNAssertNull(vec_num >= 0, SUN_ERR_ARG_OUTOFRANGE);
SUNAssertNull(vec_num <= MANYVECTOR_NUM_SUBVECS(v), SUN_ERR_ARG_OUTOFRANGE);
SUNAssertNull(vec_num < MANYVECTOR_NUM_SUBVECS(v), SUN_ERR_ARG_OUTOFRANGE);
return (MANYVECTOR_SUBVEC(v, vec_num));
}

Expand All @@ -426,7 +434,7 @@ sunrealtype* MVAPPEND(N_VGetSubvectorArrayPointer)(N_Vector v,
{
SUNFunctionBegin(v->sunctx);
SUNAssertNull(vec_num >= 0, SUN_ERR_ARG_OUTOFRANGE);
SUNAssertNull(vec_num <= MANYVECTOR_NUM_SUBVECS(v), SUN_ERR_ARG_OUTOFRANGE);
SUNAssertNull(vec_num < MANYVECTOR_NUM_SUBVECS(v), SUN_ERR_ARG_OUTOFRANGE);
sunrealtype* arr = NULL;
if (MANYVECTOR_SUBVEC(v, vec_num)->ops->nvgetarraypointer)
{
Expand All @@ -445,7 +453,7 @@ SUNErrCode MVAPPEND(N_VSetSubvectorArrayPointer)(sunrealtype* v_data, N_Vector v
{
SUNFunctionBegin(v->sunctx);
SUNAssert(vec_num >= 0, SUN_ERR_ARG_OUTOFRANGE);
SUNAssert(vec_num <= MANYVECTOR_NUM_SUBVECS(v), SUN_ERR_ARG_OUTOFRANGE);
SUNAssert(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 @@ -600,7 +608,12 @@ sunindextype MVAPPEND(N_VGetLength)(N_Vector v)

sunindextype MVAPPEND(N_VGetSubvectorLocalLength)(N_Vector v, sunindextype vec_num)
{
return (N_VGetLocalLength(MVAPPEND(N_VGetSubvector)(v, vec_num)));
SUNFunctionBegin(v->sunctx);
N_Vector subvector = MVAPPEND(N_VGetSubvector)(v, vec_num);
SUNCheckLastErrNoRet();
sunindextype loc_length = N_VGetLocalLength(subvector);
SUNCheckLastErrNoRet();
return loc_length;
}

/* Performs the linear sum z = a*x + b*y by calling N_VLinearSum on all subvectors;
Expand Down Expand Up @@ -1715,7 +1728,6 @@ SUNErrCode MVAPPEND(N_VWrmsNormVectorArray)(int nvec, N_Vector* X, N_Vector* W,
{
SUNFunctionBegin(X[0]->sunctx);
sunindextype i;
int retval;

SUNAssert(nvec > 0, SUN_ERR_ARG_OUTOFRANGE);

Expand All @@ -1727,7 +1739,6 @@ SUNErrCode MVAPPEND(N_VWrmsNormVectorArray)(int nvec, N_Vector* X, N_Vector* W,
}

/* accumulate totals */
retval = 0;
#ifdef MANYVECTOR_BUILD_WITH_MPI
if (MANYVECTOR_COMM(X[0]) != MPI_COMM_NULL)
{
Expand All @@ -1742,7 +1753,7 @@ SUNErrCode MVAPPEND(N_VWrmsNormVectorArray)(int nvec, N_Vector* X, N_Vector* W,
nrm[i] = SUNRsqrt(nrm[i] / (MANYVECTOR_GLOBLENGTH(X[i])));
}

return (retval);
return SUN_SUCCESS;
}

/* Performs the WrmsNormMaskVectorArray operation by calling N_VWSqrSumMaskLocal and
Expand All @@ -1759,8 +1770,8 @@ SUNErrCode MVAPPEND(N_VWrmsNormMaskVectorArray)(int nvec, N_Vector* X,
sunrealtype* nrm)
{
SUNFunctionBegin(X[0]->sunctx);

sunindextype i;
int retval;

SUNAssert(nvec > 0, SUN_ERR_ARG_OUTOFRANGE);

Expand All @@ -1772,7 +1783,6 @@ SUNErrCode MVAPPEND(N_VWrmsNormMaskVectorArray)(int nvec, N_Vector* X,
}

/* accumulate totals */
retval = 0;
#ifdef MANYVECTOR_BUILD_WITH_MPI
if (MANYVECTOR_COMM(X[0]) != MPI_COMM_NULL)
{
Expand All @@ -1787,7 +1797,7 @@ SUNErrCode MVAPPEND(N_VWrmsNormMaskVectorArray)(int nvec, N_Vector* X,
nrm[i] = SUNRsqrt(nrm[i] / (MANYVECTOR_GLOBLENGTH(X[i])));
}

return (retval);
return SUN_SUCCESS;
}

/* Performs the BufSize operation by calling N_VBufSize for each subvector and
Expand Down Expand Up @@ -1823,7 +1833,6 @@ 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 @@ -1854,7 +1863,6 @@ 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 Expand Up @@ -2101,12 +2109,19 @@ static N_Vector ManyVectorClone(N_Vector w, sunbooleantype cloneempty)
returns 0. If an error occurs in the call to MPI_Comm_Rank, it returns -1. */
static int SubvectorMPIRank(N_Vector x)
{
int rank = 0;
SUNFunctionBegin(x->sunctx);

int rank = 0;
MPI_Comm comm = N_VGetCommunicator(x);
SUNCheckLastErrNoRet();
if (comm == MPI_COMM_NULL) { return SUN_SUCCESS; }
SUNCheckMPICallNoRet(MPI_Comm_rank(comm, &rank));

if (comm != MPI_COMM_NULL)
{
int status = MPI_Comm_rank(comm, &rank);
SUNCheckMPICallNoRet(status);
if (status != MPI_SUCCESS) { return -1; }
}

return rank;
}
#endif
4 changes: 3 additions & 1 deletion src/nvector/mpiplusx/nvector_mpiplusx.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ N_Vector N_VGetLocalVector_MPIPlusX(N_Vector v)
sunindextype N_VGetLocalLength_MPIPlusX(N_Vector v)
{
SUNFunctionBegin(v->sunctx);
sunindextype len = N_VGetLength(N_VGetLocalVector_MPIPlusX(v));
N_Vector local_vector = N_VGetLocalVector_MPIPlusX(v);
SUNCheckLastErrNoRet();
sunindextype len = N_VGetLength(local_vector);
SUNCheckLastErrNoRet();
return len;
}
Expand Down
58 changes: 36 additions & 22 deletions src/nvector/openmp/nvector_openmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,15 @@ N_Vector N_VNew_OpenMP(sunindextype length, int num_threads, SUNContext sunctx)

/* Create data */
data = NULL;
data = (sunrealtype*)malloc(length * sizeof(sunrealtype));
SUNAssertNull(data, SUN_ERR_MALLOC_FAIL);
if (length > 0)
{
data = (sunrealtype*)malloc(length * sizeof(sunrealtype));
SUNAssertNull(data, SUN_ERR_MALLOC_FAIL);

/* Attach data */
NV_OWN_DATA_OMP(v) = SUNTRUE;
NV_DATA_OMP(v) = data;
/* Attach data */
NV_OWN_DATA_OMP(v) = SUNTRUE;
NV_DATA_OMP(v) = data;
}

return (v);
}
Expand All @@ -222,9 +225,12 @@ N_Vector N_VMake_OpenMP(sunindextype length, sunrealtype* v_data,
v = N_VNewEmpty_OpenMP(length, num_threads, sunctx);
SUNCheckLastErrNull();

/* Attach data */
NV_OWN_DATA_OMP(v) = SUNFALSE;
NV_DATA_OMP(v) = v_data;
if (length > 0)
{
/* Attach data */
NV_OWN_DATA_OMP(v) = SUNFALSE;
NV_DATA_OMP(v) = v_data;
}

return (v);
}
Expand Down Expand Up @@ -342,8 +348,11 @@ N_Vector N_VClone_OpenMP(N_Vector w)

/* Create data */
data = NULL;
data = (sunrealtype*)malloc(length * sizeof(sunrealtype));
SUNAssertNull(data, SUN_ERR_MALLOC_FAIL);
if (length > 0)
{
data = (sunrealtype*)malloc(length * sizeof(sunrealtype));
SUNAssertNull(data, SUN_ERR_MALLOC_FAIL);
}

/* Attach data */
NV_OWN_DATA_OMP(v) = SUNTRUE;
Expand Down Expand Up @@ -759,7 +768,10 @@ sunrealtype N_VMaxNorm_OpenMP(N_Vector x)

sunrealtype N_VWrmsNorm_OpenMP(N_Vector x, N_Vector w)
{
return (SUNRsqrt(N_VWSqrSumLocal_OpenMP(x, w) / (NV_LENGTH_OMP(x))));
SUNFunctionBegin(x->sunctx);
sunrealtype sqr_sum = N_VWSqrSumLocal_OpenMP(x, w);
SUNCheckLastErrNoRet();
return (SUNRsqrt(sqr_sum / (NV_LENGTH_OMP(x))));
}

/* ----------------------------------------------------------------------------
Expand All @@ -768,11 +780,14 @@ sunrealtype N_VWrmsNorm_OpenMP(N_Vector x, N_Vector w)

sunrealtype N_VWrmsNormMask_OpenMP(N_Vector x, N_Vector w, N_Vector id)
{
return (SUNRsqrt(N_VWSqrSumMaskLocal_OpenMP(x, w, id) / (NV_LENGTH_OMP(x))));
SUNFunctionBegin(x->sunctx);
sunrealtype sqr_sum = N_VWSqrSumMaskLocal_OpenMP(x, w, id);
SUNCheckLastErrNoRet();
return (SUNRsqrt(sqr_sum / (NV_LENGTH_OMP(x))));
}

/* ----------------------------------------------------------------------------
* Finds the minimun component of a vector
* Finds the minimum component of a vector
*/

sunrealtype N_VMin_OpenMP(N_Vector x)
Expand Down Expand Up @@ -1621,7 +1636,6 @@ SUNErrCode N_VScaleAddMultiVectorArray_OpenMP(int nvec, int nsum,
sunrealtype* yd = NULL;
sunrealtype* zd = NULL;

int retval;
N_Vector* YY;
N_Vector* ZZ;

Expand All @@ -1647,19 +1661,21 @@ SUNErrCode N_VScaleAddMultiVectorArray_OpenMP(int nvec, int nsum,

/* should have called N_VScaleAddMulti */
YY = (N_Vector*)malloc(nsum * sizeof(N_Vector));
SUNAssert(YY, SUN_ERR_MALLOC_FAIL);
ZZ = (N_Vector*)malloc(nsum * sizeof(N_Vector));
SUNAssert(ZZ, SUN_ERR_MALLOC_FAIL);

for (j = 0; j < nsum; j++)
{
YY[j] = Y[j][0];
ZZ[j] = Z[j][0];
}

retval = N_VScaleAddMulti_OpenMP(nsum, a, X[0], YY, ZZ);
SUNCheckCall(N_VScaleAddMulti_OpenMP(nsum, a, X[0], YY, ZZ));

free(YY);
free(ZZ);
return (retval);
return SUN_SUCCESS;
}

/* --------------------------
Expand All @@ -1669,8 +1685,8 @@ SUNErrCode N_VScaleAddMultiVectorArray_OpenMP(int nvec, int nsum,
/* should have called N_VLinearSumVectorArray */
if (nsum == 1)
{
retval = N_VLinearSumVectorArray_OpenMP(nvec, a[0], X, ONE, Y[0], Z[0]);
return (retval);
SUNCheckCall(N_VLinearSumVectorArray_OpenMP(nvec, a[0], X, ONE, Y[0], Z[0]));
return SUN_SUCCESS;
}

/* ----------------------------
Expand Down Expand Up @@ -1790,8 +1806,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();
SUNCheckCall(N_VScaleVectorArray_OpenMP(nvec, ctmp, X[0], Z));

free(ctmp);
return SUN_SUCCESS;
Expand All @@ -1800,8 +1815,7 @@ SUNErrCode N_VLinearCombinationVectorArray_OpenMP(int nvec, int nsum,
/* should have called N_VLinearSumVectorArray */
if (nsum == 2)
{
N_VLinearSumVectorArray_OpenMP(nvec, c[0], X[0], c[1], X[1], Z);
SUNCheckLastErr();
SUNCheckCall(N_VLinearSumVectorArray_OpenMP(nvec, c[0], X[0], c[1], X[1], Z));
return SUN_SUCCESS;
}

Expand Down
Loading

0 comments on commit 70776b8

Please sign in to comment.