Skip to content

Commit

Permalink
Merge pull request #515 from gruenich/feature/use-more-cpp
Browse files Browse the repository at this point in the history
[ParU] Use more C++
  • Loading branch information
DrTimothyAldenDavis authored Nov 25, 2023
2 parents f42f189 + a684309 commit a676c46
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 86 deletions.
2 changes: 1 addition & 1 deletion ParU/Include/ParU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ struct ParU_Control
int64_t trivial = 4; //dgemms with sizes less than trivial doesn't call BLAS
int64_t worthwhile_dgemm = 512; // dgemms bigger than worthwhile are tasked
int64_t worthwhile_trsm = 4096; // trsm bigger than worthwhile are tasked
int64_t paru_max_threads = 0; //It will be initialized with omp_max_threads
int32_t paru_max_threads = 0; //It will be initialized with omp_max_threads
// if the user do not provide a smaller number
};
// =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion ParU/Include/ParU_C.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef struct ParU_C_Control_struct
int64_t trivial; // dgemms with sizes less than trivial doesn't call BLAS
int64_t worthwhile_dgemm; // dgemms bigger than worthwhile are tasked
int64_t worthwhile_trsm; // trsm bigger than worthwhile are tasked
int64_t paru_max_threads; // It will be initialized with omp_max_threads
int32_t paru_max_threads; // It will be initialized with omp_max_threads
// if the user do not provide a smaller number
} ParU_C_Control;

Expand Down
24 changes: 13 additions & 11 deletions ParU/Source/paru_analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@
paru_free((n + 1), sizeof(int64_t), Front_parent); \
paru_free((n + 1), sizeof(int64_t), Front_npivcol); \
paru_free((m - n1), sizeof(int64_t), Ps); \
paru_free((MAX(m, n) + 2), sizeof(int64_t), Work); \
paru_free((std::max(m, n) + 2), sizeof(int64_t), Work); \
paru_free((cs1 + 1), sizeof(int64_t), cSup); \
paru_free((rs1 + 1), sizeof(int64_t), cSlp); \
umfpack_dl_free_symbolic(&Symbolic); \
umfpack_dl_paru_free_sw(&SW);

// =============================================================================

#include <algorithm>

#include "paru_internal.hpp"

ParU_Ret ParU_Analyze(cholmod_sparse *A, ParU_Symbolic **S_handle,
Expand Down Expand Up @@ -589,16 +591,16 @@ ParU_Ret ParU_Analyze(cholmod_sparse *A, ParU_Symbolic **S_handle,
// }

PRLEVEL(PR, ("Forthwith Pinit =\n"));
for (int64_t i = 0; i < MIN(77, m); i++) PRLEVEL(PR, ("" LD " ", Pinit[i]));
for (int64_t i = 0; i < std::min(77, m); i++) PRLEVEL(PR, ("" LD " ", Pinit[i]));
PRLEVEL(PR, ("\n"));
PRLEVEL(PR, ("Forthwith Qinit =\n"));
for (int64_t i = 0; i < MIN(77, m); i++) PRLEVEL(PR, ("" LD " ", Qinit[i]));
for (int64_t i = 0; i < std::min(77, m); i++) PRLEVEL(PR, ("" LD " ", Qinit[i]));
PRLEVEL(PR, ("\n"));
PR = -1;
if (Diag_map)
{
PRLEVEL(PR, ("Forthwith Diag_map =\n"));
for (int64_t i = 0; i < MIN(77, n); i++) PRLEVEL(PR, ("" LD " ", Diag_map[i]));
for (int64_t i = 0; i < std::min(77, n); i++) PRLEVEL(PR, ("" LD " ", Diag_map[i]));
PRLEVEL(PR, ("\n"));
}
PR = 1;
Expand Down Expand Up @@ -1010,7 +1012,7 @@ ParU_Ret ParU_Analyze(cholmod_sparse *A, ParU_Symbolic **S_handle,
}
}
// copy of Childp using Work for other places also
Work = (int64_t *)paru_alloc((MAX(m, n) + 2), sizeof(int64_t));
Work = (int64_t *)paru_alloc(std::max(m, n) + 2, sizeof(int64_t));
int64_t *cChildp = Work;
if (cChildp == NULL)
{
Expand Down Expand Up @@ -1078,11 +1080,11 @@ ParU_Ret ParU_Analyze(cholmod_sparse *A, ParU_Symbolic **S_handle,

#ifndef NDEBUG
PRLEVEL(PR, ("Qinit =\n"));
for (int64_t j = 0; j < MIN(64, n); j++) PRLEVEL(PR, ("" LD " ", Qinit[j]));
for (int64_t j = 0; j < std::min(64, n); j++) PRLEVEL(PR, ("" LD " ", Qinit[j]));
PRLEVEL(PR, ("\n"));

PRLEVEL(PR, ("Pinit =\n"));
for (int64_t i = 0; i < MIN(64, m); i++) PRLEVEL(PR, ("" LD " ", Pinit[i]));
for (int64_t i = 0; i < std::min(64, m); i++) PRLEVEL(PR, ("" LD " ", Pinit[i]));
PRLEVEL(PR, ("\n"));

PR = 1;
Expand All @@ -1094,7 +1096,7 @@ ParU_Ret ParU_Analyze(cholmod_sparse *A, ParU_Symbolic **S_handle,
if (inv_Diag_map)
{
PRLEVEL(PR, ("inv_Diag_map =\n"));
for (int64_t i = 0; i < MIN(64, n); i++)
for (int64_t i = 0; i < std::min(64, n); i++)
PRLEVEL(PR, ("" LD " ", inv_Diag_map[i]));
PRLEVEL(PR, ("\n"));
}
Expand Down Expand Up @@ -1260,7 +1262,7 @@ ParU_Ret ParU_Analyze(cholmod_sparse *A, ParU_Symbolic **S_handle,
if (Diag_map)
{
PRLEVEL(PR, ("Symbolic Diag_map (" LD ") =\n", n));
for (int64_t i = 0; i < MIN(64, n); i++) PRLEVEL(PR, ("" LD " ", Diag_map[i]));
for (int64_t i = 0; i < std::min(64, n); i++) PRLEVEL(PR, ("" LD " ", Diag_map[i]));
PRLEVEL(PR, ("\n"));
}
PR = 1;
Expand Down Expand Up @@ -1777,7 +1779,7 @@ ParU_Ret ParU_Analyze(cholmod_sparse *A, ParU_Symbolic **S_handle,
}
else
{
task_depth[t] = MAX(Depth[node], task_depth[t]);
task_depth[t] = std::max(Depth[node], task_depth[t]);
while (task_helper[rep] < 0) rep = Parent[rep];
PRLEVEL(1,
("After a while t=" LD " node=" LD " rep =" LD "\n", t, node, rep));
Expand Down Expand Up @@ -1805,7 +1807,7 @@ ParU_Ret ParU_Analyze(cholmod_sparse *A, ParU_Symbolic **S_handle,
// ii++;
// }
// PRLEVEL(1, ("after ii = " LD "\n", ii));
// max_chain = MAX(chain_size, max_chain);
// max_chain = std::max(chain_size, max_chain);
// PRLEVEL(1, ("max_chain = " LD "\n", max_chain));
// ii++;
//}
Expand Down
10 changes: 4 additions & 6 deletions ParU/Source/paru_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void paru_assemble_all(int64_t e, int64_t f, std::vector<int64_t> &colHash,
#pragma omp atomic read
naft = Work->naft;
ParU_Control *Control = Num->Control;
const int64_t max_threads = Control->paru_max_threads;
const int32_t max_threads = Control->paru_max_threads;

if (el->nrowsleft * el->ncolsleft < 4096 || el->nrowsleft < 1024
#ifndef PARU_COVERAGE
Expand Down Expand Up @@ -357,7 +357,7 @@ void paru_assemble_cols(int64_t e, int64_t f, std::vector<int64_t> &colHash,
// int64_t naft; //number of active frontal tasks
// pragma omp atomic read
// naft = Num->naft;
// const int64_t max_threads = Num->paru_max_threads;
// const int32_t max_threads = Num->paru_max_threads;
////int64_t *Depth = Sym->Depth;
// pragma omp parallel proc_bind(close) num_threads(max_threads/naft)
// if (naft < max_threads/2 &&
Expand Down Expand Up @@ -642,9 +642,8 @@ void paru_assemble_rows(int64_t e, int64_t f, std::vector<int64_t> &colHash,
PRLEVEL(1, ("%% fcolind=" LD " \n", fcolind));
double *dC = curEl_Num + fcolind * curEl->nrows;

for (int64_t ii = 0; ii < (int64_t)tempRow.size(); ii++)
for (int64_t i1 : tempRow)
{
int64_t i1 = tempRow[ii];
int64_t rowInd = el_rowIndex[i1];
int64_t ri = isRowInFront[rowInd];

Expand All @@ -660,9 +659,8 @@ void paru_assemble_rows(int64_t e, int64_t f, std::vector<int64_t> &colHash,
}

// invalidating assembled rows
for (int64_t ii = 0; ii < (int64_t)tempRow.size(); ii++)
for (int64_t i2 : tempRow)
{
int64_t i2 = tempRow[ii];
el_rowIndex[i2] = -1;
rowRelIndex[i2] = -1;
}
Expand Down
3 changes: 2 additions & 1 deletion ParU/Source/paru_backward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* @author Aznaveh
* */
#include <algorithm>

#include "paru_internal.hpp"

Expand Down Expand Up @@ -65,7 +66,7 @@ ParU_Ret paru_backward(double *x1, double &resid, double &anorm, double &xnorm,
#ifndef NDEBUG
PR = 1;
PRLEVEL(PR, ("x2 = [ "));
for (int64_t i = 0; i < MIN(m, 10); ++i) PRLEVEL(PR, ("%lf ", b[i]));
for (int64_t i = 0; i < std::min(m, 10); ++i) PRLEVEL(PR, ("%lf ", b[i]));
PRLEVEL(PR, (" ...]\n"));
#endif

Expand Down
24 changes: 13 additions & 11 deletions ParU/Source/paru_factorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*
* @author Aznaveh
*/
#include <algorithm>

#include "paru_internal.hpp"

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -243,10 +245,10 @@ ParU_Ret ParU_Factorize(cholmod_sparse *A, ParU_Symbolic *Sym,
if (worthwhile_dgemm < 0) my_Control.worthwhile_dgemm = 512;
int64_t worthwhile_trsm = my_Control.worthwhile_trsm;
if (worthwhile_trsm < 0) my_Control.worthwhile_trsm = 4096;
int64_t max_threads = PARU_OPENMP_MAX_THREADS;
int32_t max_threads = PARU_OPENMP_MAX_THREADS;
if (my_Control.paru_max_threads > 0)
my_Control.paru_max_threads =
MIN(max_threads, my_Control.paru_max_threads);
std::min(max_threads, my_Control.paru_max_threads);
else
my_Control.paru_max_threads = max_threads;

Expand Down Expand Up @@ -344,7 +346,7 @@ ParU_Ret ParU_Factorize(cholmod_sparse *A, ParU_Symbolic *Sym,
#if ! defined ( PARU_GCC_WINDOWS )
// The parallel factorization gets stuck intermittently on Windows with GCC.
// Use the sequential factorization unconditionally in that case.
if ((int64_t)task_Q.size() * 2 > Control->paru_max_threads)
if (task_Q.size() * 2 > Control->paru_max_threads)
{
printf ("Parallel:\n") ; // FIXME
PRLEVEL(1, ("Parallel\n"));
Expand Down Expand Up @@ -501,14 +503,14 @@ ParU_Ret ParU_Factorize(cholmod_sparse *A, ParU_Symbolic *Sym,
int64_t col1 = Super[f];
int64_t col2 = Super[f + 1];
int64_t fp = col2 - col1;
max_rc = MAX(max_rc, rowCount);
max_cc = MAX(max_cc, colCount + fp);
max_rc = std::max(max_rc, rowCount);
max_cc = std::max(max_cc, colCount + fp);
double *X = LUs[f].p;
for (int64_t i = 0; i < fp; i++)
{
double udiag = fabs(X[rowCount * i + i]);
min_udiag = MIN(min_udiag, udiag);
max_udiag = MAX(max_udiag, udiag);
min_udiag = std::min(min_udiag, udiag);
max_udiag = std::max(max_udiag, udiag);
}
}
}
Expand All @@ -525,8 +527,8 @@ ParU_Ret ParU_Factorize(cholmod_sparse *A, ParU_Symbolic *Sym,
int64_t col1 = Super[f];
int64_t col2 = Super[f + 1];
int64_t fp = col2 - col1;
max_rc = MAX(max_rc, rowCount);
max_cc = MAX(max_cc, colCount + fp);
max_rc = std::max(max_rc, rowCount);
max_cc = std::max(max_cc, colCount + fp);
}

for (int64_t f = 0; f < nf; f++)
Expand All @@ -542,8 +544,8 @@ ParU_Ret ParU_Factorize(cholmod_sparse *A, ParU_Symbolic *Sym,
for (int64_t i = 0; i < fp; i++)
{
double udiag = fabs(X[rowCount * i + i]);
min_udiag = MIN(min_udiag, udiag);
max_udiag = MAX(max_udiag, udiag);
min_udiag = std::min(min_udiag, udiag);
max_udiag = std::max(max_udiag, udiag);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion ParU/Source/paru_finalize_perm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// All Rights Reserved.
// SPDX-License-Identifier: GNU GPL 3.0

#include <algorithm>

#include "paru_internal.hpp"

ParU_Ret paru_finalize_perm(ParU_Symbolic *Sym, ParU_Numeric *Num)
Expand Down Expand Up @@ -81,7 +83,7 @@ ParU_Ret paru_finalize_perm(ParU_Symbolic *Sym, ParU_Numeric *Num)
PRLEVEL(PR, (" \n"));
PR = 1;
PRLEVEL(PR, ("%% n1=" LD " Final row permutaion is:\n%%", n1));
for (int64_t k = 0; k < MIN(77, m); k++) PRLEVEL(PR, ("" LD " ", Pfin[k]));
for (int64_t k = 0; k < std::min(77, m); k++) PRLEVEL(PR, ("" LD " ", Pfin[k]));
PRLEVEL(PR, (" \n"));
#endif
return PARU_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion ParU/Source/paru_fs_factorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void paru_swap_rows(double *F, int64_t *frowList, int64_t m, int64_t n, int64_t
// int64_t naft; //number of active frontal tasks
// pragma omp atomic read
// naft = Num->naft;
// const int64_t max_threads = Control->paru_max_threads;
// const int32_t max_threads = Control->paru_max_threads;
// if ( (naft == 1) && (n > 1024) )
// printf ("naft=" LD ", max_threads=" LD " num_tasks=" LD " n =" LD " \n",
// naft, max_threads, max_threads/(naft), n);
Expand Down
42 changes: 19 additions & 23 deletions ParU/Source/paru_heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ ParU_Ret paru_make_heap(int64_t f, int64_t start_fac,
std::vector<int64_t> *chHeap = heapList[chelid];
if (chHeap == NULL) continue;
// concatening the child and freeing the memory
for (int64_t k = 0; k < (int64_t)chHeap->size(); k++)
for (int64_t e : *chHeap)
{
int64_t e = (*chHeap)[k];
if (elementList[e] != NULL)
{
paru_check_prior_element(e, f, start_fac, colHash, Work,
Expand All @@ -109,17 +108,17 @@ ParU_Ret paru_make_heap(int64_t f, int64_t start_fac,
heapList[chelid] = NULL;
}

for (int64_t i = 0; i < (int64_t)pivotal_elements.size(); i++)
for (int64_t e : pivotal_elements)
{
int64_t e = pivotal_elements[i];
paru_element *el = elementList[e];
#ifndef NDEBUG
ASSERT(el != NULL);
ASSERT(elementList[e] != NULL);
#endif
if (el == NULL) continue;
PRLEVEL(PR, ("" LD " ", e));
curHeap->push_back(e);
std::push_heap(curHeap->begin(), curHeap->end(), greater);
if (elementList[e] != NULL)
{
PRLEVEL(PR, ("" LD " ", e));
curHeap->push_back(e);
std::push_heap(curHeap->begin(), curHeap->end(), greater);
}
}
curHeap->push_back(eli);
std::push_heap(curHeap->begin(), curHeap->end(), greater);
Expand All @@ -137,9 +136,8 @@ ParU_Ret paru_make_heap(int64_t f, int64_t start_fac,

// curHeap->insert(curHeap->end(),
// chHeap->begin(), chHeap->end());
for (int64_t k = 0; k < (int64_t)chHeap->size(); k++)
for (int64_t e : *chHeap)
{
int64_t e = (*chHeap)[k];
if (elementList[e] != NULL)
{
paru_check_prior_element(e, f, start_fac, colHash, Work,
Expand Down Expand Up @@ -258,9 +256,8 @@ ParU_Ret paru_make_heap_empty_el(int64_t f, std::vector<int64_t> &pivotal_elemen
std::vector<int64_t> *chHeap = heapList[chelid];
if (chHeap == NULL) continue;
// concatening the child and freeing the memory
for (int64_t k = 0; k < (int64_t)chHeap->size(); k++)
for (int64_t e : *chHeap)
{
int64_t e = (*chHeap)[k];
if (elementList[e] != NULL)
{
curHeap->push_back(e);
Expand All @@ -272,14 +269,14 @@ ParU_Ret paru_make_heap_empty_el(int64_t f, std::vector<int64_t> &pivotal_elemen
heapList[chelid] = NULL;
}

for (int64_t i = 0; i < (int64_t)pivotal_elements.size(); i++)
for (int64_t e : pivotal_elements)
{
int64_t e = pivotal_elements[i];
paru_element *el = elementList[e];
if (el == NULL) continue;
PRLEVEL(PR, ("" LD " ", e));
curHeap->push_back(e);
std::push_heap(curHeap->begin(), curHeap->end(), greater);
if (elementList[e] != NULL)
{
PRLEVEL(PR, ("" LD " ", e));
curHeap->push_back(e);
std::push_heap(curHeap->begin(), curHeap->end(), greater);
}
}
std::push_heap(curHeap->begin(), curHeap->end(), greater);
PRLEVEL(PR, ("%% " LD " pushed ", eli));
Expand All @@ -296,9 +293,8 @@ ParU_Ret paru_make_heap_empty_el(int64_t f, std::vector<int64_t> &pivotal_elemen

// curHeap->insert(curHeap->end(),
// chHeap->begin(), chHeap->end());
for (int64_t k = 0; k < (int64_t)chHeap->size(); k++)
for (int64_t e : *chHeap)
{
int64_t e = (*chHeap)[k];
if (elementList[e] != NULL)
{
curHeap->push_back(e);
Expand Down
8 changes: 5 additions & 3 deletions ParU/Source/paru_init_rowFronts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
* @author Aznaveh
*/
#include <algorithm>

#include "paru_internal.hpp"

ParU_Ret paru_init_rowFronts(paru_work *Work,
Expand Down Expand Up @@ -265,7 +267,7 @@ ParU_Ret paru_init_rowFronts(paru_work *Work,
for (int64_t p = Ap[oldcol]; p < Ap[oldcol + 1]; p++)
{
int64_t oldrow = Ai[p];
Rs[oldrow] = MAX(Rs[oldrow], fabs(Ax[p]));
Rs[oldrow] = std::max(Rs[oldrow], fabs(Ax[p]));
}
}
}
Expand Down Expand Up @@ -389,11 +391,11 @@ ParU_Ret paru_init_rowFronts(paru_work *Work,
#ifndef NDEBUG
PR = 1;
PRLEVEL(PR, ("init_row Diag_map (" LD ") =\n", Sym->n));
for (int64_t i = 0; i < MIN(64, Sym->n); i++)
for (int64_t i = 0; i < std::min(64, Sym->n); i++)
PRLEVEL(PR, ("" LD " ", Diag_map[i]));
PRLEVEL(PR, ("\n"));
PRLEVEL(PR, ("inv_Diag_map =\n"));
for (int64_t i = 0; i < MIN(64, Sym->n); i++)
for (int64_t i = 0; i < std::min(64, Sym->n); i++)
PRLEVEL(PR, ("" LD " ", inv_Diag_map[i]));
PRLEVEL(PR, ("\n"));
for (int64_t i = 0; i < Sym->n; i++)
Expand Down
Loading

0 comments on commit a676c46

Please sign in to comment.