Unifiy headers

This commit is contained in:
Jan Eitzinger 2025-01-18 09:31:56 +01:00
parent 9db571faaa
commit 82824ec020
17 changed files with 114 additions and 113 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2025 moebiusband Copyright (c) NHR@FAU, University Erlangen-Nuremberg
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -1,9 +1,7 @@
/* /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of CG-Bench.
* All rights reserved. * Use of this source code is governed by a MIT style
* Use of this source code is governed by a MIT-style * license that can be found in the LICENSE file. */
* license that can be found in the LICENSE file.
*/
#include <errno.h> #include <errno.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>

View File

@ -1,6 +1,6 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT-style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file. */ * license that can be found in the LICENSE file. */
#ifndef __ALLOCATE_H_ #ifndef __ALLOCATE_H_
#define __ALLOCATE_H_ #define __ALLOCATE_H_

View File

@ -1,8 +1,7 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. This file is part of nusif-solver. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file. * license that can be found in the LICENSE file. */
*/
#include "util.h" #include "util.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -15,7 +14,7 @@
#include "comm.h" #include "comm.h"
// subroutines local to this module // subroutines local to this module
int sizeOfRank(int rank, int size, int N) static int sizeOfRank(int rank, int size, int N)
{ {
return N / size + ((N % size > rank) ? 1 : 0); return N / size + ((N % size > rank) ? 1 : 0);
} }
@ -576,6 +575,46 @@ void commPrintConfig(Comm* c)
#endif #endif
} }
void commMatrixDump(Comm* c, Matrix* m)
{
int rank = c->rank;
int size = c->size;
CG_UINT numRows = m->nr;
CG_UINT* rowPtr = m->rowPtr;
CG_UINT* colInd = m->colInd;
CG_FLOAT* val = m->val;
if (commIsMaster(c)) {
printf("Matrix: %lld total non zeroes, total number of rows %lld\n",
m->totalNnz,
m->totalNr);
}
for (int i = 0; i < size; i++) {
if (i == rank) {
printf("Rank %d: %lld non zeroes, number of rows %lld\n",
rank,
m->nnz,
numRows);
for (int rowID = 0; rowID < numRows; rowID++) {
printf("Row [%d]: ", rowID);
for (size_t rowEntry = rowPtr[rowID]; rowEntry < rowPtr[rowID + 1];
rowEntry++) {
printf("[%lld]:%.2f ", colInd[rowEntry], val[rowEntry]);
}
printf("\n");
}
fflush(stdout);
}
#ifdef _MPI
MPI_Barrier(MPI_COMM_WORLD);
#endif
}
}
void commInit(Comm* c, int argc, char** argv) void commInit(Comm* c, int argc, char** argv)
{ {
#ifdef _MPI #ifdef _MPI

View File

@ -1,7 +1,7 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. This file is part of nusif-solver. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.*/ * license that can be found in the LICENSE file. */
#ifndef __COMM_H_ #ifndef __COMM_H_
#define __COMM_H_ #define __COMM_H_
#if defined(_MPI) #if defined(_MPI)
@ -35,11 +35,11 @@ typedef struct {
#endif #endif
} Comm; } Comm;
extern int sizeOfRank(int rank, int size, int N);
extern void commInit(Comm* c, int argc, char** argv); extern void commInit(Comm* c, int argc, char** argv);
extern void commFinalize(Comm* c); extern void commFinalize(Comm* c);
extern void commPartition(Comm*, Matrix* m); extern void commPartition(Comm* c, Matrix* m);
extern void commPrintConfig(Comm*); extern void commPrintConfig(Comm* c);
extern void commMatrixDump(Comm* c, Matrix* m);
extern void commExchange(Comm* c, Matrix* A, double* x); extern void commExchange(Comm* c, Matrix* A, double* x);
extern void commReduction(double* v, int op); extern void commReduction(double* v, int op);

View File

@ -1,7 +1,7 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT-style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.*/ * license that can be found in the LICENSE file. */
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -34,7 +34,6 @@ CG_FLOAT compute_residual(Solver* s)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int rank;
double timeStart, timeStop; double timeStart, timeStop;
Parameter param; Parameter param;
Solver s; Solver s;
@ -44,7 +43,10 @@ int main(int argc, char** argv)
initParameter(&param); initParameter(&param);
if (argc != 2) { if (argc != 2) {
if (commIsMaster(&comm)) {
printf("Usage: %s <configFile>\n", argv[0]); printf("Usage: %s <configFile>\n", argv[0]);
}
commFinalize(&comm);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -53,13 +55,15 @@ int main(int argc, char** argv)
CG_FLOAT eps = (CG_FLOAT)param.eps; CG_FLOAT eps = (CG_FLOAT)param.eps;
int itermax = param.itermax; int itermax = param.itermax;
initSolver(&s, &comm, &param); initSolver(&s, &comm, &param);
// matrixDump(&s.A, &comm); commMatrixDump(&comm, &s.A);
commFinalize(&comm);
exit(EXIT_SUCCESS);
CG_UINT nrow = s.A.nr; CG_UINT nrow = s.A.nr;
CG_UINT ncol = s.A.nc; CG_UINT ncol = s.A.nc;
CG_FLOAT* r = (CG_FLOAT*)allocate(64, nrow * sizeof(CG_FLOAT)); CG_FLOAT* r = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, nrow * sizeof(CG_FLOAT));
CG_FLOAT* p = (CG_FLOAT*)allocate(64, ncol * sizeof(CG_FLOAT)); CG_FLOAT* p = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, ncol * sizeof(CG_FLOAT));
CG_FLOAT* Ap = (CG_FLOAT*)allocate(64, nrow * sizeof(CG_FLOAT)); CG_FLOAT* Ap = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, nrow * sizeof(CG_FLOAT));
CG_FLOAT normr = 0.0; CG_FLOAT normr = 0.0;
CG_FLOAT rtrans = 0.0, oldrtrans; CG_FLOAT rtrans = 0.0, oldrtrans;

View File

@ -1,7 +1,7 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT-style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.*/ * license that can be found in the LICENSE file. */
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
@ -96,7 +96,7 @@ void matrixRead(Matrix* m, char* filename)
if (sym_flag) { if (sym_flag) {
mm = (Entry*)allocate(ARRAY_ALIGNMENT, nz * 2 * sizeof(Entry)); mm = (Entry*)allocate(ARRAY_ALIGNMENT, nz * 2 * sizeof(Entry));
} else { } else {
mm = (Entry*)allocate(64, nz * sizeof(Entry)); mm = (Entry*)allocate(ARRAY_ALIGNMENT, nz * sizeof(Entry));
} }
size_t cursor = 0; size_t cursor = 0;
@ -138,11 +138,11 @@ 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(64, (m->nr + 1) * sizeof(CG_UINT)); m->rowPtr = (CG_UINT*)allocate(ARRAY_ALIGNMENT, (m->nr + 1) * sizeof(CG_UINT));
m->colInd = (CG_UINT*)allocate(64, m->nnz * sizeof(CG_UINT)); m->colInd = (CG_UINT*)allocate(ARRAY_ALIGNMENT, m->nnz * sizeof(CG_UINT));
m->val = (CG_FLOAT*)allocate(64, m->nnz * sizeof(CG_FLOAT)); m->val = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, m->nnz * sizeof(CG_FLOAT));
int* valsPerRow = (int*)allocate(64, m->nr * sizeof(int)); int* valsPerRow = (int*)allocate(ARRAY_ALIGNMENT, m->nr * sizeof(int));
for (int i = 0; i < m->nr; i++) { for (int i = 0; i < m->nr; i++) {
valsPerRow[i] = 0; valsPerRow[i] = 0;
@ -166,35 +166,3 @@ void matrixRead(Matrix* m, char* filename)
} }
} }
} }
void matrixDump(Matrix* m, int rank, int size)
{
CG_UINT numRows = m->nr;
CG_UINT* rowPtr = m->rowPtr;
CG_UINT* colInd = m->colInd;
CG_FLOAT* val = m->val;
if (!rank) {
printf("Matrix: %lld total non zeroes, total number of rows %lld\n",
m->totalNnz,
m->totalNr);
}
for (int i = 0; i < size; i++) {
if (i == rank) {
printf("Matrix: %lld non zeroes, number of rows %lld\n", m->nnz, numRows);
for (int rowID = 0; rowID < numRows; rowID++) {
printf("Row [%d]: ", rowID);
for (size_t rowEntry = rowPtr[rowID]; rowEntry < rowPtr[rowID + 1];
rowEntry++) {
printf("[%lld]:%.2f ", colInd[rowEntry], val[rowEntry]);
}
printf("\n");
}
fflush(stdout);
}
}
}

View File

@ -1,7 +1,7 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT-style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.*/ * license that can be found in the LICENSE file. */
#ifndef __MATRIX_H_ #ifndef __MATRIX_H_
#define __MATRIX_H_ #define __MATRIX_H_
#include <stdbool.h> #include <stdbool.h>
@ -23,6 +23,5 @@ typedef struct {
} Matrix; } Matrix;
extern void matrixRead(Matrix* m, char* filename); extern void matrixRead(Matrix* m, char* filename);
extern void matrixDump(Matrix* m, int rank, int size);
#endif // __MATRIX_H_ #endif // __MATRIX_H_

View File

@ -1,5 +1,5 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. This file is part of nusif-solver. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file. */ * license that can be found in the LICENSE file. */
#include <stdio.h> #include <stdio.h>
@ -7,7 +7,6 @@
#include <string.h> #include <string.h>
#include "parameter.h" #include "parameter.h"
#include "util.h"
#define MAXLINE 4096 #define MAXLINE 4096
void initParameter(Parameter* param) void initParameter(Parameter* param)

View File

@ -1,5 +1,5 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. This file is part of nusif-solver. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file. */ * license that can be found in the LICENSE file. */
#ifndef __PARAMETER_H_ #ifndef __PARAMETER_H_

View File

@ -1,5 +1,5 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. This file is part of nusif-solver. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file. */ * license that can be found in the LICENSE file. */
#include "progress.h" #include "progress.h"

View File

@ -1,9 +1,7 @@
/* /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of CG-Bench.
* All rights reserved. * Use of this source code is governed by a MIT style
* Use of this source code is governed by a MIT-style * license that can be found in the LICENSE file. */
* license that can be found in the LICENSE file.
*/
#ifndef __PROGRESS_H_ #ifndef __PROGRESS_H_
#define __PROGRESS_H_ #define __PROGRESS_H_

View File

@ -1,7 +1,7 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT-style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file.*/ * license that can be found in the LICENSE file. */
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
@ -36,12 +36,12 @@ static void matrixGenerate(Parameter* p, Solver* s, Comm* c, bool use_7pt_stenci
printf("%d total rows and %d nonzeros\n", (int)total_nrow, (int)local_nnz); printf("%d total rows and %d nonzeros\n", (int)total_nrow, (int)local_nnz);
} }
s->A.val = (CG_FLOAT*)allocate(64, local_nnz * sizeof(CG_FLOAT)); s->A.val = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, local_nnz * sizeof(CG_FLOAT));
s->A.colInd = (CG_UINT*)allocate(64, local_nnz * sizeof(CG_UINT)); s->A.colInd = (CG_UINT*)allocate(ARRAY_ALIGNMENT, local_nnz * sizeof(CG_UINT));
s->A.rowPtr = (CG_UINT*)allocate(64, (local_nrow + 1) * sizeof(CG_UINT)); s->A.rowPtr = (CG_UINT*)allocate(ARRAY_ALIGNMENT, (local_nrow + 1) * sizeof(CG_UINT));
s->x = (CG_FLOAT*)allocate(64, local_nrow * sizeof(CG_FLOAT)); s->x = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, local_nrow * sizeof(CG_FLOAT));
s->b = (CG_FLOAT*)allocate(64, local_nrow * sizeof(CG_FLOAT)); s->b = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, local_nrow * sizeof(CG_FLOAT));
s->xexact = (CG_FLOAT*)allocate(64, 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;

View File

@ -1,5 +1,5 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. This file is part of nusif-solver. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file. */ * license that can be found in the LICENSE file. */
#ifndef __SOLVER_H_ #ifndef __SOLVER_H_

View File

@ -1,9 +1,7 @@
/* /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of CG-Bench.
* All rights reserved. * Use of this source code is governed by a MIT style
* Use of this source code is governed by a MIT-style * license that can be found in the LICENSE file. */
* license that can be found in the LICENSE file.
*/
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>

View File

@ -1,9 +1,7 @@
/* /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. * All rights reserved. This file is part of CG-Bench.
* All rights reserved. * Use of this source code is governed by a MIT style
* Use of this source code is governed by a MIT-style * license that can be found in the LICENSE file. */
* license that can be found in the LICENSE file.
*/
#ifndef __TIMING_H_ #ifndef __TIMING_H_
#define __TIMING_H_ #define __TIMING_H_

View File

@ -1,6 +1,6 @@
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg. /* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
* All rights reserved. * All rights reserved. This file is part of CG-Bench.
* Use of this source code is governed by a MIT-style * Use of this source code is governed by a MIT style
* license that can be found in the LICENSE file. */ * license that can be found in the LICENSE file. */
#ifndef __UTIL_H_ #ifndef __UTIL_H_
#define __UTIL_H_ #define __UTIL_H_