Unifiy headers
This commit is contained in:
parent
9db571faaa
commit
82824ec020
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
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:
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#ifndef __ALLOCATE_H_
|
||||
#define __ALLOCATE_H_
|
||||
|
49
src/comm.c
49
src/comm.c
@ -1,8 +1,7 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -15,7 +14,7 @@
|
||||
#include "comm.h"
|
||||
|
||||
// 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);
|
||||
}
|
||||
@ -576,6 +575,46 @@ void commPrintConfig(Comm* c)
|
||||
#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)
|
||||
{
|
||||
#ifdef _MPI
|
||||
|
12
src/comm.h
12
src/comm.h
@ -1,7 +1,7 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* 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_
|
||||
#define __COMM_H_
|
||||
#if defined(_MPI)
|
||||
@ -35,11 +35,11 @@ typedef struct {
|
||||
#endif
|
||||
} Comm;
|
||||
|
||||
extern int sizeOfRank(int rank, int size, int N);
|
||||
extern void commInit(Comm* c, int argc, char** argv);
|
||||
extern void commFinalize(Comm* c);
|
||||
extern void commPartition(Comm*, Matrix* m);
|
||||
extern void commPrintConfig(Comm*);
|
||||
extern void commPartition(Comm* c, Matrix* m);
|
||||
extern void commPrintConfig(Comm* c);
|
||||
extern void commMatrixDump(Comm* c, Matrix* m);
|
||||
extern void commExchange(Comm* c, Matrix* A, double* x);
|
||||
extern void commReduction(double* v, int op);
|
||||
|
||||
|
22
src/main.c
22
src/main.c
@ -1,7 +1,7 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.*/
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -34,7 +34,6 @@ CG_FLOAT compute_residual(Solver* s)
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int rank;
|
||||
double timeStart, timeStop;
|
||||
Parameter param;
|
||||
Solver s;
|
||||
@ -44,7 +43,10 @@ int main(int argc, char** argv)
|
||||
initParameter(¶m);
|
||||
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s <configFile>\n", argv[0]);
|
||||
if (commIsMaster(&comm)) {
|
||||
printf("Usage: %s <configFile>\n", argv[0]);
|
||||
}
|
||||
commFinalize(&comm);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
@ -53,13 +55,15 @@ int main(int argc, char** argv)
|
||||
CG_FLOAT eps = (CG_FLOAT)param.eps;
|
||||
int itermax = param.itermax;
|
||||
initSolver(&s, &comm, ¶m);
|
||||
// matrixDump(&s.A, &comm);
|
||||
commMatrixDump(&comm, &s.A);
|
||||
commFinalize(&comm);
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
CG_UINT nrow = s.A.nr;
|
||||
CG_UINT ncol = s.A.nc;
|
||||
CG_FLOAT* r = (CG_FLOAT*)allocate(64, nrow * sizeof(CG_FLOAT));
|
||||
CG_FLOAT* p = (CG_FLOAT*)allocate(64, ncol * sizeof(CG_FLOAT));
|
||||
CG_FLOAT* Ap = (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(ARRAY_ALIGNMENT, ncol * sizeof(CG_FLOAT));
|
||||
CG_FLOAT* Ap = (CG_FLOAT*)allocate(ARRAY_ALIGNMENT, nrow * sizeof(CG_FLOAT));
|
||||
CG_FLOAT normr = 0.0;
|
||||
CG_FLOAT rtrans = 0.0, oldrtrans;
|
||||
|
||||
|
48
src/matrix.c
48
src/matrix.c
@ -1,7 +1,7 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.*/
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
@ -96,7 +96,7 @@ void matrixRead(Matrix* m, char* filename)
|
||||
if (sym_flag) {
|
||||
mm = (Entry*)allocate(ARRAY_ALIGNMENT, nz * 2 * sizeof(Entry));
|
||||
} else {
|
||||
mm = (Entry*)allocate(64, nz * sizeof(Entry));
|
||||
mm = (Entry*)allocate(ARRAY_ALIGNMENT, nz * sizeof(Entry));
|
||||
}
|
||||
|
||||
size_t cursor = 0;
|
||||
@ -138,11 +138,11 @@ void matrixRead(Matrix* m, char* filename)
|
||||
mergesort(mm, mms, sizeof(Entry), compareRow);
|
||||
// dumpMMMatrix(mm, nz);
|
||||
|
||||
m->rowPtr = (CG_UINT*)allocate(64, (m->nr + 1) * sizeof(CG_UINT));
|
||||
m->colInd = (CG_UINT*)allocate(64, m->nnz * sizeof(CG_UINT));
|
||||
m->val = (CG_FLOAT*)allocate(64, m->nnz * sizeof(CG_FLOAT));
|
||||
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));
|
||||
|
||||
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++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.*/
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#ifndef __MATRIX_H_
|
||||
#define __MATRIX_H_
|
||||
#include <stdbool.h>
|
||||
@ -23,6 +23,5 @@ typedef struct {
|
||||
} Matrix;
|
||||
|
||||
extern void matrixRead(Matrix* m, char* filename);
|
||||
extern void matrixDump(Matrix* m, int rank, int size);
|
||||
|
||||
#endif // __MATRIX_H_
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#include <stdio.h>
|
||||
@ -7,7 +7,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "parameter.h"
|
||||
#include "util.h"
|
||||
#define MAXLINE 4096
|
||||
|
||||
void initParameter(Parameter* param)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#ifndef __PARAMETER_H_
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#include "progress.h"
|
||||
|
@ -1,9 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#ifndef __PROGRESS_H_
|
||||
#define __PROGRESS_H_
|
||||
|
||||
|
18
src/solver.c
18
src/solver.c
@ -1,7 +1,7 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.*/
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#include <stdbool.h>
|
||||
#include <stddef.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);
|
||||
}
|
||||
|
||||
s->A.val = (CG_FLOAT*)allocate(64, local_nnz * sizeof(CG_FLOAT));
|
||||
s->A.colInd = (CG_UINT*)allocate(64, local_nnz * sizeof(CG_UINT));
|
||||
s->A.rowPtr = (CG_UINT*)allocate(64, (local_nrow + 1) * sizeof(CG_UINT));
|
||||
s->x = (CG_FLOAT*)allocate(64, local_nrow * sizeof(CG_FLOAT));
|
||||
s->b = (CG_FLOAT*)allocate(64, local_nrow * sizeof(CG_FLOAT));
|
||||
s->xexact = (CG_FLOAT*)allocate(64, local_nrow * 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.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));
|
||||
|
||||
CG_FLOAT* curvalptr = s->A.val;
|
||||
CG_UINT* curindptr = s->A.colInd;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of nusif-solver.
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#ifndef __SOLVER_H_
|
||||
|
10
src/timing.c
10
src/timing.c
@ -1,9 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
|
10
src/timing.h
10
src/timing.h
@ -1,9 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
* license that can be found in the LICENSE file.
|
||||
*/
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#ifndef __TIMING_H_
|
||||
#define __TIMING_H_
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved.
|
||||
* Use of this source code is governed by a MIT-style
|
||||
/* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
|
||||
* All rights reserved. This file is part of CG-Bench.
|
||||
* Use of this source code is governed by a MIT style
|
||||
* license that can be found in the LICENSE file. */
|
||||
#ifndef __UTIL_H_
|
||||
#define __UTIL_H_
|
||||
|
Loading…
Reference in New Issue
Block a user