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

View File

@ -47,10 +47,6 @@ void commPartition(Comm* c, Matrix* A)
int* row_ptr = (int*)A->rowPtr; int* row_ptr = (int*)A->rowPtr;
int* col_ind = (int*)A->colInd; 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 // We need to convert the index values for the rows on this processor
// to a local index space. We need to: // to a local index space. We need to:
// - Determine if each index reaches to a local value or external value // - 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* externals = (int*)allocate(ARRAY_ALIGNMENT, A->totalNr * sizeof(int));
int num_external = 1; 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; c->external_index = external_index;
for (int i = 0; i < A->totalNr; i++) { for (int i = 0; i < A->totalNr; i++) {
@ -96,7 +93,7 @@ void commPartition(Comm* c, Matrix* A)
if (num_external <= MAX_EXTERNAL) { if (num_external <= MAX_EXTERNAL) {
external_index[num_external - 1] = cur_ind; external_index[num_external - 1] = cur_ind;
// Mark index as external by negating it // Mark index as external by negating it
col_ind[j] = -col_ind[j]; col_ind[j] = -(col_ind[j] + 1); // FIXME: Offset?
} else { } else {
printf("Must increase MAX_EXTERNAL\n"); printf("Must increase MAX_EXTERNAL\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -145,8 +142,8 @@ void commPartition(Comm* c, Matrix* A)
/*Go through the external elements. For each newly encountered external /*Go through the external elements. For each newly encountered external
point assign it the next index in the local sequence. Then look for other 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 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 set of index numbers in the local sequence (ie. elements updated by the same
have consecutive indices).*/ node have consecutive indices).*/
int* external_local_index = (int*)allocate(ARRAY_ALIGNMENT, int* external_local_index = (int*)allocate(ARRAY_ALIGNMENT,
MAX_EXTERNAL * sizeof(int)); MAX_EXTERNAL * sizeof(int));
c->external_local_index = external_local_index; 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 // 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 /* decode the combined 'tmp_neighbors' (stored in tmp_buffer) array from all
* processors */ * the processors */
int num_send_neighbors = tmp_buffer[rank] % size; int num_send_neighbors = tmp_buffer[rank] % size;
/* decode 'tmp_buffer[rank] to deduce total number of elements we must send */ /* 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) { 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); exit(EXIT_FAILURE);
} }
@ -305,7 +308,12 @@ void commPartition(Comm* c, Matrix* A)
// send messages // send messages
for (int i = 0; i < num_recv_neighbors; i++) { 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'. // 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 // Create 'new_external' which explicitly put the external elements in the
// order given by 'external_local_index' // 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++) { for (int i = 0; i < num_external; i++) {
new_external[external_local_index[i] - local_nrow] = external_index[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); 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))) { mm_is_matrix(matcode) && mm_is_sparse(matcode))) {
fprintf(stderr, "Sorry, this application does not support "); fprintf(stderr, "Sorry, this application does not support ");
fprintf(stderr, "Market Market type: [%s]\n", mm_typecode_to_str(matcode)); 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); mergesort(mm, mms, sizeof(Entry), compareRow);
// dumpMMMatrix(mm, nz); // 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->colInd = (CG_UINT*)allocate(ARRAY_ALIGNMENT, m->nnz * sizeof(CG_UINT));
m->val = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, m->nnz * sizeof(CG_FLOAT)); m->val = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, m->nnz * sizeof(CG_FLOAT));

View File

@ -11,8 +11,13 @@
#include "mmio.h" #include "mmio.h"
int mm_read_unsymmetric_sparse( int mm_read_unsymmetric_sparse(const char* fname,
const char* fname, int* M_, int* N_, int* nz_, double** val_, int** I_, int** J_) int* M_,
int* N_,
int* nz_,
double** val_,
int** I_,
int** J_)
{ {
FILE* f; FILE* f;
MM_typecode matcode; MM_typecode matcode;
@ -29,7 +34,8 @@ int mm_read_unsymmetric_sparse(
return -1; 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, "Sorry, this application does not support ");
fprintf(stderr, "Market Market type: [%s]\n", mm_typecode_to_str(matcode)); fprintf(stderr, "Market Market type: [%s]\n", mm_typecode_to_str(matcode));
return -1; return -1;
@ -38,7 +44,8 @@ int mm_read_unsymmetric_sparse(
/* find out size of sparse matrix: M, N, nz .... */ /* find out size of sparse matrix: M, N, nz .... */
if (mm_read_mtx_crd_size(f, &M, &N, &nz) != 0) { 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; return -1;
} }
@ -75,7 +82,8 @@ int mm_is_valid(MM_typecode matcode)
if (!mm_is_matrix(matcode)) return 0; if (!mm_is_matrix(matcode)) return 0;
if (mm_is_dense(matcode) && mm_is_pattern(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_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 0;
return 1; 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 (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; return MM_PREMATURE_EOF;
for (p = mtx; *p != '\0'; *p = tolower(*p), p++) 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 */ /* use when I[], J[], and val[]J, and val[] are already allocated */
/******************************************************************/ /******************************************************************/
int mm_read_mtx_crd_data( int mm_read_mtx_crd_data(FILE* f,
FILE* f, int M, int N, int nz, int I[], int J[], double val[], MM_typecode matcode) int M,
int N,
int nz,
int I[],
int J[],
double val[],
MM_typecode matcode)
{ {
int i; int i;
if (mm_is_complex(matcode)) { if (mm_is_complex(matcode)) {
for (i = 0; i < nz; i++) for (i = 0; i < nz; i++)
if (fscanf(f, "%d %d %lg %lg", &I[i], &J[i], &val[2 * i], &val[2 * i + 1]) != if (fscanf(f,
4) "%d %d %lg %lg",
&I[i],
&J[i],
&val[2 * i],
&val[2 * i + 1]) != 4)
return MM_PREMATURE_EOF; return MM_PREMATURE_EOF;
} else if (mm_is_real(matcode)) { } else if (mm_is_real(matcode)) {
for (i = 0; i < nz; i++) { 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) FILE* f, int* I, int* J, double* real, double* imag, MM_typecode matcode)
{ {
if (mm_is_complex(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)) { } else if (mm_is_real(matcode)) {
if (fscanf(f, "%d %d %lg\n", I, J, real) != 3) return MM_PREMATURE_EOF; 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 ((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; return MM_UNSUPPORTED_TYPE;
if ((ret_code = mm_read_mtx_crd_size(f, M, N, nz)) != 0) return ret_code; 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]); fprintf(f, "%d %d %20.16g\n", I[i], J[i], val[i]);
else if (mm_is_complex(matcode)) else if (mm_is_complex(matcode))
for (i = 0; i < nz; i++) 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 { else {
if (f != stdout) fclose(f); if (f != stdout) fclose(f);
return MM_UNSUPPORTED_TYPE; 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 MM_matrix_typecode: 4-character sequence
ojbect sparse/ data storage dense ojbect sparse/ data
type scheme storage dense type scheme
string position: [0] [1] [2] [3] string position: [0] [1] [2] [3]
Matrix typecode: M(atrix) C(oord) R(eal) G(eneral) Matrix typecode: M(atrix) C(oord) R(eal) G(eneral)
A(array) C(omplex) A(array)
H(ermitian) P(attern) S(ymmetric) I(nteger) K(kew) 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[], int J[],
double val[], double val[],
MM_typecode matcode); MM_typecode matcode);
int mm_read_mtx_crd_data( int mm_read_mtx_crd_data(FILE* f,
FILE* f, int M, int N, int nz, int I[], int J[], double val[], MM_typecode matcode); int M,
int N,
int nz,
int I[],
int J[],
double val[],
MM_typecode matcode);
int mm_read_mtx_crd_entry( int mm_read_mtx_crd_entry(
FILE* f, int* I, int* J, double* real, double* img, MM_typecode matcode); FILE* f, int* I, int* J, double* real, double* img, MM_typecode matcode);
int mm_read_unsymmetric_sparse( int mm_read_unsymmetric_sparse(const char* fname,
const char* fname, int* M_, int* N_, int* nz_, double** val_, int** I_, int** J_); int* M_,
int* N_,
int* nz_,
double** val_,
int** I_,
int** J_);
#endif #endif

View File

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