Skip to content

Commit

Permalink
Refactored code to eliminate some redundancies.
Browse files Browse the repository at this point in the history
  • Loading branch information
oseikuffuor1 authored and jeanlucf22 committed Aug 25, 2023
1 parent 8f37715 commit f5e0d5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
23 changes: 10 additions & 13 deletions src/C-interface/ellblock/bml_norm_ellblock_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,21 @@ double TYPED_FUNC(
for (int ib = 0; ib < NB; ib++)
y_ptr[ib] = calloc(maxbsize2, sizeof(REAL_T));

int ix[NB], jjb[NB];
int ix[NB], jjb[MB];

memset(ix, 0, NB * sizeof(int));
memset(jjb, 0, NB * sizeof(int));

for (int ib = 0; ib < NB; ib++)
{
int lb = 0;
/* reset marker ix */
memset(ix, 0, NB * sizeof(int));
for (int jp = 0; jp < A_nnzb[ib]; jp++)
{
int ind = ROWMAJOR(ib, jp, NB, MB);
int jb = A_indexb[ind];

ix[jb] = ib + 1;
ix[jb] = 1;

REAL_T *y_value = y_ptr[jb];
REAL_T *A_value = A_ptr_value[ind];
Expand Down Expand Up @@ -152,7 +153,6 @@ double TYPED_FUNC(
if (normx > threshold * threshold)
sum += normx;
}
memset(ix, 0, NB * sizeof(int));
}

for (int ib = 0; ib < NB; ib++)
Expand Down Expand Up @@ -216,13 +216,11 @@ double TYPED_FUNC(
int ind = ROWMAJOR(ib, jp, NB, MB);
int jb = A_indexb[ind];
int nelements = bsize[ib] * bsize[jb];
if (ix[jb] == 0)
{
memset(y_ptr[jb], 0, nelements * sizeof(REAL_T));
ix[jb] = ib + 1;
jjb[lb] = jb;
lb++;
}

ix[jb] = 1;
jjb[lb] = jb;
lb++;

REAL_T *y_value = y_ptr[jb];
REAL_T *A_value = A_ptr_value[ind];
for (int ii = 0; ii < bsize[ib]; ii++)
Expand All @@ -240,8 +238,6 @@ double TYPED_FUNC(
int nelements = bsize[ib] * bsize[jb];
if (ix[jb] == 0)
{
memset(y_ptr[jb], 0, nelements * sizeof(REAL_T));
ix[jb] = ib + 1;
jjb[lb] = jb;
lb++;
}
Expand All @@ -263,6 +259,7 @@ double TYPED_FUNC(
if (normx > threshold * threshold)
sum += normx;

/* reset arrays */
ix[jjb[jp]] = 0;
memset(y_ptr[jjb[jp]], 0, maxbsize2 * sizeof(REAL_T));
jjb[jp] = 0;
Expand Down
31 changes: 13 additions & 18 deletions src/C-interface/ellpack/bml_norm_ellpack_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ double TYPED_FUNC(

#if !(defined(__IBMC__) || defined(__ibmxl__))
REAL_T y[A_N];
int ix[A_N], jjb[A_N];
int ix[A_N], jjb[A_M];

memset(y, 0.0, A_N * sizeof(REAL_T));
memset(ix, 0, A_N * sizeof(int));
memset(jjb, 0, A_N * sizeof(int));
memset(jjb, 0, A_M * sizeof(int));
#endif

#ifdef USE_OMP_OFFLOAD
Expand Down Expand Up @@ -181,16 +181,15 @@ double TYPED_FUNC(
{
#if defined(__IBMC__) || defined(__ibmxl__)
REAL_T y[A_N];
int ix[A_N], jjb[A_N];

memset(ix, 0, A_N * sizeof(int));
int ix[A_N], jjb[A_M];
#endif

/* reset marker ix */
memset(ix, 0, A_N * sizeof(int));
int l = 0;
for (int jp = 0; jp < A_nnz[i]; jp++)
{
int k = A_index[ROWMAJOR(i, jp, A_N, A_M)];
ix[k] = i + 1;
ix[k] = 1;
y[k] = alpha_ * A_value[ROWMAJOR(i, jp, A_N, A_M)];
}

Expand All @@ -210,7 +209,6 @@ double TYPED_FUNC(
if (ABS(y[jjb[jp]]) > threshold)
sum += y[jjb[jp]]; //* y[jjb[jp]];
}
memset(ix, 0, A_N * sizeof(int));
}

return (double) REAL_PART(sum);
Expand Down Expand Up @@ -304,13 +302,12 @@ double TYPED_FUNC(
for (int jp = 0; jp < A_nnz[i]; jp++)
{
int k = A_index[ROWMAJOR(i, jp, A_N, A_M)];
if (ix[k] == 0)
{
y[k] = 0.0;
ix[k] = i + 1;
jjb[l] = k;
l++;
}

y[k] = 0.0;
ix[k] = 1;
jjb[l] = k;
l++;

y[k] += alpha_ * A_value[ROWMAJOR(i, jp, A_N, A_M)];
}

Expand All @@ -320,7 +317,6 @@ double TYPED_FUNC(
if (ix[k] == 0)
{
y[k] = 0.0;
ix[k] = i + 1;
jjb[l] = k;
l++;
}
Expand All @@ -332,9 +328,8 @@ double TYPED_FUNC(
if (ABS(y[jjb[jp]]) > threshold)
sum += y[jjb[jp]] * y[jjb[jp]];

/* reset marker array */
ix[jjb[jp]] = 0;
y[jjb[jp]] = 0.0;
jjb[jp] = 0;
}
}

Expand Down

0 comments on commit f5e0d5c

Please sign in to comment.