Reformat. Change indent to 2 spaces and line length to 80.

This commit is contained in:
Jan Eitzinger 2025-01-19 07:07:18 +01:00
parent 82824ec020
commit 6f1932cf4f
15 changed files with 1314 additions and 1259 deletions

View File

@ -56,8 +56,8 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 90
CommentPragmas: '^ IWYU pragma:'
ColumnLimit: 80
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
@ -68,7 +68,6 @@ DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: false
@ -88,27 +87,27 @@ IncludeCategories:
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
- Regex: ".*"
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IncludeIsMainRegex: "(Test)?$"
IncludeIsMainSourceRegex: ""
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentWidth: 4
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
ObjCBinPackProtocolList: Auto
@ -173,4 +172,3 @@ WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...

View File

@ -47,10 +47,6 @@ void commPartition(Comm* c, Matrix* A)
int* row_ptr = (int*)A->rowPtr;
int* col_ind = (int*)A->colInd;
// int* nnz_in_row = A->nnz_in_row;
// double** ptr_to_vals_in_row = A->ptr_to_vals_in_row;
// int** ptr_to_inds_in_row = A->ptr_to_inds_in_row;
// We need to convert the index values for the rows on this processor
// to a local index space. We need to:
// - Determine if each index reaches to a local value or external value
@ -66,7 +62,8 @@ void commPartition(Comm* c, Matrix* A)
int* externals = (int*)allocate(ARRAY_ALIGNMENT, A->totalNr * sizeof(int));
int num_external = 1;
int* external_index = (int*)allocate(ARRAY_ALIGNMENT, MAX_EXTERNAL * sizeof(int));
int* external_index = (int*)allocate(ARRAY_ALIGNMENT,
MAX_EXTERNAL * sizeof(int));
c->external_index = external_index;
for (int i = 0; i < A->totalNr; i++) {
@ -96,7 +93,7 @@ void commPartition(Comm* c, Matrix* A)
if (num_external <= MAX_EXTERNAL) {
external_index[num_external - 1] = cur_ind;
// Mark index as external by negating it
col_ind[j] = -col_ind[j];
col_ind[j] = -(col_ind[j] + 1); // FIXME: Offset?
} else {
printf("Must increase MAX_EXTERNAL\n");
exit(EXIT_FAILURE);
@ -145,8 +142,8 @@ void commPartition(Comm* c, Matrix* A)
/*Go through the external elements. For each newly encountered external
point assign it the next index in the local sequence. Then look for other
external elements who are updated by the same node and assign them the next
set of index numbers in the local sequence (ie. elements updated by the same node
have consecutive indices).*/
set of index numbers in the local sequence (ie. elements updated by the same
node have consecutive indices).*/
int* external_local_index = (int*)allocate(ARRAY_ALIGNMENT,
MAX_EXTERNAL * sizeof(int));
c->external_local_index = external_local_index;
@ -229,10 +226,15 @@ void commPartition(Comm* c, Matrix* A)
}
// sum over all processors all the tmp_neighbors arrays
MPI_Allreduce(tmp_neighbors, tmp_buffer, size, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
MPI_Allreduce(tmp_neighbors,
tmp_buffer,
size,
MPI_INT,
MPI_SUM,
MPI_COMM_WORLD);
/* decode the combined 'tmp_neighbors' (stored in tmp_buffer) array from all the
* processors */
/* decode the combined 'tmp_neighbors' (stored in tmp_buffer) array from all
* the processors */
int num_send_neighbors = tmp_buffer[rank] % size;
/* decode 'tmp_buffer[rank] to deduce total number of elements we must send */
@ -247,7 +249,8 @@ void commPartition(Comm* c, Matrix* A)
}
if (total_to_be_sent > MAX_EXTERNAL) {
printf("Must increase MAX_EXTERNAL. Must be at least %d\n", total_to_be_sent);
printf("Must increase MAX_EXTERNAL. Must be at least %d\n",
total_to_be_sent);
exit(EXIT_FAILURE);
}
@ -305,7 +308,12 @@ void commPartition(Comm* c, Matrix* A)
// send messages
for (int i = 0; i < num_recv_neighbors; i++) {
MPI_Send(tmp_buffer + i, 1, MPI_INT, recv_list[i], MPI_MY_TAG, MPI_COMM_WORLD);
MPI_Send(tmp_buffer + i,
1,
MPI_INT,
recv_list[i],
MPI_MY_TAG,
MPI_COMM_WORLD);
}
// Receive message from each send neighbor to construct 'send_list'.
@ -362,7 +370,8 @@ void commPartition(Comm* c, Matrix* A)
// Create 'new_external' which explicitly put the external elements in the
// order given by 'external_local_index'
int* new_external = (int*)allocate(ARRAY_ALIGNMENT, num_external * sizeof(int));
int* new_external = (int*)allocate(ARRAY_ALIGNMENT,
num_external * sizeof(int));
for (int i = 0; i < num_external; i++) {
new_external[external_local_index[i] - local_nrow] = external_index[i];

View File

@ -51,7 +51,8 @@ void matrixRead(Matrix* m, char* filename)
exit(EXIT_FAILURE);
}
if (!((mm_is_real(matcode) || mm_is_pattern(matcode) || mm_is_integer(matcode)) &&
if (!((mm_is_real(matcode) || mm_is_pattern(matcode) ||
mm_is_integer(matcode)) &&
mm_is_matrix(matcode) && mm_is_sparse(matcode))) {
fprintf(stderr, "Sorry, this application does not support ");
fprintf(stderr, "Market Market type: [%s]\n", mm_typecode_to_str(matcode));
@ -138,7 +139,8 @@ void matrixRead(Matrix* m, char* filename)
mergesort(mm, mms, sizeof(Entry), compareRow);
// dumpMMMatrix(mm, nz);
m->rowPtr = (CG_UINT*)allocate(ARRAY_ALIGNMENT, (m->nr + 1) * sizeof(CG_UINT));
m->rowPtr = (CG_UINT*)allocate(ARRAY_ALIGNMENT,
(m->nr + 1) * sizeof(CG_UINT));
m->colInd = (CG_UINT*)allocate(ARRAY_ALIGNMENT, m->nnz * sizeof(CG_UINT));
m->val = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, m->nnz * sizeof(CG_FLOAT));

View File

@ -11,8 +11,13 @@
#include "mmio.h"
int mm_read_unsymmetric_sparse(
const char* fname, int* M_, int* N_, int* nz_, double** val_, int** I_, int** J_)
int mm_read_unsymmetric_sparse(const char* fname,
int* M_,
int* N_,
int* nz_,
double** val_,
int** I_,
int** J_)
{
FILE* f;
MM_typecode matcode;
@ -29,7 +34,8 @@ int mm_read_unsymmetric_sparse(
return -1;
}
if (!(mm_is_real(matcode) && mm_is_matrix(matcode) && mm_is_sparse(matcode))) {
if (!(mm_is_real(matcode) && mm_is_matrix(matcode) &&
mm_is_sparse(matcode))) {
fprintf(stderr, "Sorry, this application does not support ");
fprintf(stderr, "Market Market type: [%s]\n", mm_typecode_to_str(matcode));
return -1;
@ -38,7 +44,8 @@ int mm_read_unsymmetric_sparse(
/* find out size of sparse matrix: M, N, nz .... */
if (mm_read_mtx_crd_size(f, &M, &N, &nz) != 0) {
fprintf(stderr, "read_unsymmetric_sparse(): could not parse matrix size.\n");
fprintf(stderr,
"read_unsymmetric_sparse(): could not parse matrix size.\n");
return -1;
}
@ -75,7 +82,8 @@ int mm_is_valid(MM_typecode matcode)
if (!mm_is_matrix(matcode)) return 0;
if (mm_is_dense(matcode) && mm_is_pattern(matcode)) return 0;
if (mm_is_real(matcode) && mm_is_hermitian(matcode)) return 0;
if (mm_is_pattern(matcode) && (mm_is_hermitian(matcode) || mm_is_skew(matcode)))
if (mm_is_pattern(matcode) &&
(mm_is_hermitian(matcode) || mm_is_skew(matcode)))
return 0;
return 1;
}
@ -94,7 +102,13 @@ int mm_read_banner(FILE* f, MM_typecode* matcode)
if (fgets(line, MM_MAX_LINE_LENGTH, f) == NULL) return MM_PREMATURE_EOF;
if (sscanf(line, "%s %s %s %s %s", banner, mtx, crd, data_type, storage_scheme) != 5)
if (sscanf(line,
"%s %s %s %s %s",
banner,
mtx,
crd,
data_type,
storage_scheme) != 5)
return MM_PREMATURE_EOF;
for (p = mtx; *p != '\0'; *p = tolower(*p), p++)
@ -219,14 +233,24 @@ int mm_write_mtx_array_size(FILE* f, int M, int N)
/* use when I[], J[], and val[]J, and val[] are already allocated */
/******************************************************************/
int mm_read_mtx_crd_data(
FILE* f, int M, int N, int nz, int I[], int J[], double val[], MM_typecode matcode)
int mm_read_mtx_crd_data(FILE* f,
int M,
int N,
int nz,
int I[],
int J[],
double val[],
MM_typecode matcode)
{
int i;
if (mm_is_complex(matcode)) {
for (i = 0; i < nz; i++)
if (fscanf(f, "%d %d %lg %lg", &I[i], &J[i], &val[2 * i], &val[2 * i + 1]) !=
4)
if (fscanf(f,
"%d %d %lg %lg",
&I[i],
&J[i],
&val[2 * i],
&val[2 * i + 1]) != 4)
return MM_PREMATURE_EOF;
} else if (mm_is_real(matcode)) {
for (i = 0; i < nz; i++) {
@ -248,7 +272,8 @@ int mm_read_mtx_crd_entry(
FILE* f, int* I, int* J, double* real, double* imag, MM_typecode matcode)
{
if (mm_is_complex(matcode)) {
if (fscanf(f, "%d %d %lg %lg", I, J, real, imag) != 4) return MM_PREMATURE_EOF;
if (fscanf(f, "%d %d %lg %lg", I, J, real, imag) != 4)
return MM_PREMATURE_EOF;
} else if (mm_is_real(matcode)) {
if (fscanf(f, "%d %d %lg\n", I, J, real) != 3) return MM_PREMATURE_EOF;
@ -288,7 +313,8 @@ int mm_read_mtx_crd(char* fname,
if ((ret_code = mm_read_banner(f, matcode)) != 0) return ret_code;
if (!(mm_is_valid(*matcode) && mm_is_sparse(*matcode) && mm_is_matrix(*matcode)))
if (!(mm_is_valid(*matcode) && mm_is_sparse(*matcode) &&
mm_is_matrix(*matcode)))
return MM_UNSUPPORTED_TYPE;
if ((ret_code = mm_read_mtx_crd_size(f, M, N, nz)) != 0) return ret_code;
@ -360,7 +386,12 @@ int mm_write_mtx_crd(char fname[],
fprintf(f, "%d %d %20.16g\n", I[i], J[i], val[i]);
else if (mm_is_complex(matcode))
for (i = 0; i < nz; i++)
fprintf(f, "%d %d %20.16g %20.16g\n", I[i], J[i], val[2 * i], val[2 * i + 1]);
fprintf(f,
"%d %d %20.16g %20.16g\n",
I[i],
J[i],
val[2 * i],
val[2 * i + 1]);
else {
if (f != stdout) fclose(f);
return MM_UNSUPPORTED_TYPE;

View File

@ -83,14 +83,14 @@ int mm_is_valid(MM_typecode matcode); /* too complex for a macro */
MM_matrix_typecode: 4-character sequence
ojbect sparse/ data storage dense
type scheme
ojbect sparse/ data
storage dense type scheme
string position: [0] [1] [2] [3]
Matrix typecode: M(atrix) C(oord) R(eal) G(eneral)
A(array) C(omplex)
H(ermitian) P(attern) S(ymmetric) I(nteger) K(kew)
A(array)
C(omplex) H(ermitian) P(attern) S(ymmetric) I(nteger) K(kew)
***********************************************************************/
@ -118,12 +118,23 @@ int mm_write_mtx_crd(char fname[],
int J[],
double val[],
MM_typecode matcode);
int mm_read_mtx_crd_data(
FILE* f, int M, int N, int nz, int I[], int J[], double val[], MM_typecode matcode);
int mm_read_mtx_crd_data(FILE* f,
int M,
int N,
int nz,
int I[],
int J[],
double val[],
MM_typecode matcode);
int mm_read_mtx_crd_entry(
FILE* f, int* I, int* J, double* real, double* img, MM_typecode matcode);
int mm_read_unsymmetric_sparse(
const char* fname, int* M_, int* N_, int* nz_, double** val_, int** I_, int** J_);
int mm_read_unsymmetric_sparse(const char* fname,
int* M_,
int* N_,
int* nz_,
double** val_,
int** I_,
int** J_);
#endif

View File

@ -13,7 +13,8 @@
#include "solver.h"
#include "util.h"
static void matrixGenerate(Parameter* p, Solver* s, Comm* c, bool use_7pt_stencil)
static void matrixGenerate(
Parameter* p, Solver* s, Comm* c, bool use_7pt_stencil)
{
int size = c->size;
int rank = c->rank;
@ -37,11 +38,14 @@ static void matrixGenerate(Parameter* p, Solver* s, Comm* c, bool use_7pt_stenci
}
s->A.val = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, local_nnz * sizeof(CG_FLOAT));
s->A.colInd = (CG_UINT*)allocate(ARRAY_ALIGNMENT, local_nnz * sizeof(CG_UINT));
s->A.rowPtr = (CG_UINT*)allocate(ARRAY_ALIGNMENT, (local_nrow + 1) * sizeof(CG_UINT));
s->A.colInd = (CG_UINT*)allocate(ARRAY_ALIGNMENT,
local_nnz * sizeof(CG_UINT));
s->A.rowPtr = (CG_UINT*)allocate(ARRAY_ALIGNMENT,
(local_nrow + 1) * sizeof(CG_UINT));
s->x = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, local_nrow * sizeof(CG_FLOAT));
s->b = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, local_nrow * sizeof(CG_FLOAT));
s->xexact = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, local_nrow * sizeof(CG_FLOAT));
s->xexact = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT,
local_nrow * sizeof(CG_FLOAT));
CG_FLOAT* curvalptr = s->A.val;
CG_UINT* curindptr = s->A.colInd;
@ -78,8 +82,7 @@ static void matrixGenerate(Parameter* p, Solver* s, Comm* c, bool use_7pt_stenci
(iy + sy < ny) && (curcol >= 0 && curcol < total_nrow)) {
// This logic will skip over point that are not part of a
// 7-pt stencil
if (!use_7pt_stencil ||
(sz * sz + sy * sy + sx * sx <= 1)) {
if (!use_7pt_stencil || (sz * sz + sy * sy + sx * sx <= 1)) {
if (curcol == currow) {
*curvalptr++ = 27.0;
} else {
@ -140,7 +143,8 @@ void spMVM(Matrix* m, const CG_FLOAT* restrict x, CG_FLOAT* restrict y)
CG_FLOAT tmp = y[rowID];
// loop over all elements in row
for (size_t rowEntry = rowPtr[rowID]; rowEntry < rowPtr[rowID + 1]; rowEntry++) {
for (size_t rowEntry = rowPtr[rowID]; rowEntry < rowPtr[rowID + 1];
rowEntry++) {
tmp += val[rowEntry] * x[colInd[rowEntry]];
}