Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes for norm calculation. #729

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 7 additions & 10 deletions src/C-interface/csr/bml_norm_csr_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ double TYPED_FUNC(
const int N = A->N_;
REAL_T sum = 0.0;
REAL_T cvals[N];
int ipos[N];

memset(cvals, 0.0, N * sizeof(REAL_T));
memset(ipos, 0, N * sizeof(int));

for (int i = 0; i < N; i++)
{
Expand All @@ -124,32 +126,27 @@ double TYPED_FUNC(
int *bcols = B->data_[i]->cols_;
REAL_T *bvals = (REAL_T *) B->data_[i]->vals_;
const int bnnz = B->data_[i]->NNZ_;
int cnt = annz;
int cnt = 0;
for (int pos = 0; pos < bnnz; pos++)
{
int *idx = (int *) csr_table_lookup(table, bcols[pos]);
REAL_T val = bvals[pos];
if (idx)
{
cvals[*idx] *= val;
ipos[cnt] = *idx;
cnt++;
}
//else
//{
// cvals[cnt] = val;
// cnt++;
//}
}
// clear table
csr_deallocate_table(table);
// apply threshold and compute norm
for (int k = 0; k < cnt; k++)
{
if (ABS(cvals[k]) > threshold)
if (ABS(cvals[ipos[k]]) > threshold)
{
sum += cvals[k]; //* cvals[k];
sum += cvals[ipos[k]];
}
// reset cvals
cvals[k] = 0.;
}
}

Expand Down
44 changes: 18 additions & 26 deletions src/C-interface/ellblock/bml_norm_ellblock_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,58 +109,50 @@ 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] = ib + 1;

REAL_T *y_value = y_ptr[jb];
REAL_T *A_value = A_ptr_value[ind];
for (int ii = 0; ii < bsize[ib]; ii++)
for (int jj = 0; jj < bsize[jb]; jj++)
{
int index = ROWMAJOR(ii, jj, bsize[ib], bsize[jb]);
y_value[index] += alpha_ * A_value[index];
y_value[index] = alpha_ * A_value[index];
}
}

for (int jp = 0; jp < B_nnzb[ib]; jp++)
{
int ind = ROWMAJOR(ib, jp, NB, MB);
int jb = B_indexb[ind];
int nelements = bsize[ib] * bsize[jb];
if (ix[jb] == 0)
if (ix[jb] != 0)
{
memset(y_ptr[jb], 0, nelements * sizeof(REAL_T));
ix[jb] = ib + 1;
jjb[lb] = jb;
lb++;
}
REAL_T *y_value = y_ptr[jb];
REAL_T *B_value = B_ptr_value[ind];
for (int ii = 0; ii < bsize[ib]; ii++)
for (int jj = 0; jj < bsize[jb]; jj++)

REAL_T *y_value = y_ptr[jb];
REAL_T *B_value = B_ptr_value[ind];
for (int ii = 0; ii < bsize[ib]; ii++)
{
int index = ROWMAJOR(ii, jj, bsize[ib], bsize[jb]);
y_value[index] *= B_value[index];
for (int jj = 0; jj < bsize[jb]; jj++)
{
int index = ROWMAJOR(ii, jj, bsize[ib], bsize[jb]);
y_value[index] *= B_value[index];
}
}
}
}

for (int jp = 0; jp < lb; jp++)
{
double normx = TYPED_FUNC(bml_sum_AB)
(y_ptr[jjb[jp]], bsize[ib], bsize[jp], bsize[jp]);
(y_ptr[jjb[jp]], bsize[ib], bsize[jjb[jp]], bsize[jjb[jp]]);

if (normx > threshold * threshold)
sum += normx;

ix[jjb[jp]] = 0;
memset(y_ptr[jjb[jp]], 0, maxbsize2 * sizeof(REAL_T));
jjb[jp] = 0;
}
memset(ix, 0, NB * sizeof(int));
}

for (int ib = 0; ib < NB; ib++)
Expand Down Expand Up @@ -266,7 +258,7 @@ double TYPED_FUNC(
for (int jp = 0; jp < lb; jp++)
{
double normx = TYPED_FUNC(bml_sum_squares)
(y_ptr[jjb[jp]], bsize[ib], bsize[jp], bsize[jp]);
(y_ptr[jjb[jp]], bsize[ib], bsize[jjb[jp]], bsize[jjb[jp]]);

if (normx > threshold * threshold)
sum += normx;
Expand Down
21 changes: 5 additions & 16 deletions src/C-interface/ellpack/bml_norm_ellpack_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,38 +190,27 @@ 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] += alpha_ * A_value[ROWMAJOR(i, jp, A_N, A_M)];
ix[k] = i + 1;
y[k] = alpha_ * A_value[ROWMAJOR(i, jp, A_N, A_M)];
}

for (int jp = 0; jp < B_nnz[i]; jp++)
{
int k = B_index[ROWMAJOR(i, jp, B_N, B_M)];
if (ix[k] == 0)
if (ix[k] != 0)
{
y[k] = 0.0;
ix[k] = i + 1;
jjb[l] = k;
l++;
y[k] *= B_value[ROWMAJOR(i, jp, B_N, B_M)];
}
y[k] *= B_value[ROWMAJOR(i, jp, B_N, B_M)];
}

for (int jp = 0; jp < l; jp++)
{
if (ABS(y[jjb[jp]]) > threshold)
sum += y[jjb[jp]]; //* y[jjb[jp]];

ix[jjb[jp]] = 0;
y[jjb[jp]] = 0.0;
jjb[jp] = 0;
}
memset(ix, 0, A_N * sizeof(int));
jeanlucf22 marked this conversation as resolved.
Show resolved Hide resolved
}

return (double) REAL_PART(sum);
Expand Down