Skip to content

Commit

Permalink
make astyle
Browse files Browse the repository at this point in the history
  • Loading branch information
thilinarmtb committed Jan 28, 2019
1 parent c05417b commit 02f91e3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ astyle:
astyle --style=google --indent=spaces=2 --max-code-length=72 \
--keep-one-line-statements --keep-one-line-blocks --lineend=linux \
--suffix=none --preserve-date --formatted --pad-oper \
--unpad-paren tests/*/*.[ch] src/*.[ch] inc/*.[ch] io/*/*.[ch]
--unpad-paren tests/*/*.[ch] src/*.[ch]

print-%:
$(info [ variable name]: $*)
Expand Down
66 changes: 35 additions & 31 deletions src/genmap-algo.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ int GenmapSymTriDiagSolve(GenmapVector x, GenmapVector b,
}
//
//
int GenmapOrthogonalizebyOneVector(GenmapHandle h, GenmapComm c, GenmapVector q1, GenmapLong n) {
int GenmapOrthogonalizebyOneVector(GenmapHandle h, GenmapComm c,
GenmapVector q1, GenmapLong n) {
GenmapInt i;
GenmapScalar sum = 0.0;
for(i = 0; i < q1->size; i++) {
Expand All @@ -153,8 +154,8 @@ int GenmapOrthogonalizebyOneVector(GenmapHandle h, GenmapComm c, GenmapVector q1
}

int GenmapLanczosLegendary(GenmapHandle h, GenmapComm c, GenmapVector f,
GenmapInt niter, GenmapVector **rr, GenmapVector diag,
GenmapVector upper) {
GenmapInt niter, GenmapVector **rr, GenmapVector diag,
GenmapVector upper) {
assert(diag->size == niter);
assert(diag->size == upper->size + 1);
assert(f->size == h->header->lelt);
Expand Down Expand Up @@ -187,14 +188,14 @@ int GenmapLanczosLegendary(GenmapHandle h, GenmapComm c, GenmapVector f,
rtr = GenmapDotVector(r, r);
GenmapGop(c, &rtr, 1, GENMAP_SCALAR, GENMAP_SUM);
rnorm = sqrt(rtr);
rtol = rnorm*eps;
rtol = rnorm * eps;
rni = 1.0 / rnorm;

// Allocate memory for q-vectors
if(*rr == NULL){
GenmapMalloc((size_t)(niter+1), rr);
if(*rr == NULL) {
GenmapMalloc((size_t)(niter + 1), rr);
GenmapInt i;
for(i = 0; i < niter+1; ++i) (*rr)[i] = NULL;
for(i = 0; i < niter + 1; ++i)(*rr)[i] = NULL;
}
GenmapCreateVector(&(*rr)[0], lelt);

Expand All @@ -204,19 +205,19 @@ int GenmapLanczosLegendary(GenmapHandle h, GenmapComm c, GenmapVector f,
for(iter = 0; iter < niter; iter++) {
rtz2 = rtz1;
rtz1 = rtr;
beta = rtz1/rtz2;
beta = rtz1 / rtz2;
if(iter == 0) beta = 0.0;

GenmapAxpbyVector(p, p, beta, r, 1.0);
GenmapOrthogonalizebyOneVector(h, c, p, h->header->nel);
// Multiplication by the laplacian
h->Ax(h, c, p, weights, w);

pap_old = pap;
pap = GenmapDotVector(w, p);
GenmapGop(c, &pap, 1, GENMAP_SCALAR, GENMAP_SUM);
alpha = rtz1 / pap;
GenmapAxpbyVector(r, r, 1.0, w, -1.0*alpha);
GenmapAxpbyVector(r, r, 1.0, w, -1.0 * alpha);

rtr = GenmapDotVector(r, r);
GenmapGop(c, &rtr, 1, GENMAP_SCALAR, GENMAP_SUM);
Expand All @@ -234,8 +235,8 @@ int GenmapLanczosLegendary(GenmapHandle h, GenmapComm c, GenmapVector f,
if(iter == 0) {
diag->data[iter] = pap / rtz1;
} else {
diag->data[iter] = (beta*beta*pap_old + pap)/rtz1;
upper->data[iter - 1] = -beta*pap_old/sqrt(rtz2*rtz1);
diag->data[iter] = (beta * beta * pap_old + pap) / rtz1;
upper->data[iter - 1] = -beta * pap_old / sqrt(rtz2 * rtz1);
}

if(rnorm < rtol) {
Expand Down Expand Up @@ -289,10 +290,10 @@ int GenmapLanczos(GenmapHandle h, GenmapComm c, GenmapVector init,
beta->data[0] = 0.;

// Allocate memory for q-vectors
if(*q == NULL){
GenmapMalloc((size_t)(iter+1), q);
if(*q == NULL) {
GenmapMalloc((size_t)(iter + 1), q);
GenmapInt i;
for(i = 0; i < iter+1; ++i) (*q)[i] = NULL;
for(i = 0; i < iter + 1; ++i)(*q)[i] = NULL;
}

// Store Local Laplacian weights
Expand Down Expand Up @@ -406,8 +407,9 @@ int GenmapFiedler(GenmapHandle h, GenmapComm c, int maxIter,
if(global > 0) {
for(i = 0; i < lelt; i++) {
//initVec->data[i] = (GenmapScalar) elements[i].globalId;
if(h->header->start + lelt < h->header->nel/2)
initVec->data[i] = h->header->start + i + 1000. * (h->header->nel/2.0);
if(h->header->start + lelt < h->header->nel / 2)
initVec->data[i] = h->header->start + i + 1000. * (h->header->nel /
2.0);
else
initVec->data[i] = h->header->start + i;
}
Expand All @@ -422,7 +424,8 @@ int GenmapFiedler(GenmapHandle h, GenmapComm c, int maxIter,
GenmapVector *q = NULL;
// TODO: Lanczos doesn't work well for smaller matrices
// We need to fix this
int iter = GenmapLanczosLegendary(h, c, initVec, maxIter, &q, alphaVec, betaVec);
int iter = GenmapLanczosLegendary(h, c, initVec, maxIter, &q, alphaVec,
betaVec);
//int iter = GenmapLanczos(h, c, initVec, maxIter, &q, alphaVec, betaVec);

// 2. Do inverse power iteration on local communicator and find
Expand Down Expand Up @@ -458,17 +461,17 @@ int GenmapFiedler(GenmapHandle h, GenmapComm c, int maxIter,
elements[i].fiedler = evLanczos->data[i];
}
#if defined(GENMAP_DEBUG) && defined(GENMAP_MPI)
MPI_Barrier(h->local->gsComm.c);
for(i = 0; i < h->Np(h->local); i++) {
if(i == h->Id(h->local)) {
for(j = 0; j < lelt; j++)
printf("id = "GenmapIntFormat" globalId = "GenmapLongFormat" fiedler = "GenmapScalarFormat"\n",
h->Id(h->global),
elements[j].globalId, elements[j].fiedler);
}
MPI_Barrier(h->local->gsComm.c);
MPI_Barrier(h->local->gsComm.c);
for(i = 0; i < h->Np(h->local); i++) {
if(i == h->Id(h->local)) {
for(j = 0; j < lelt; j++)
printf("id = "GenmapIntFormat" globalId = "GenmapLongFormat" fiedler = "GenmapScalarFormat"\n",
h->Id(h->global),
elements[j].globalId, elements[j].fiedler);
}
MPI_Barrier(h->local->gsComm.c);
}
MPI_Barrier(h->local->gsComm.c);
#endif


Expand All @@ -479,7 +482,7 @@ int GenmapFiedler(GenmapHandle h, GenmapComm c, int maxIter,
GenmapDestroyVector(evLanczos);
GenmapDestroyVector(evTriDiag);
GenmapDestroyVector(evInit);
for(i = 0; i < iter+1; i++) {
for(i = 0; i < iter + 1; i++) {
GenmapDestroyVector(q[i]);
}
GenmapFree(q);
Expand Down Expand Up @@ -534,7 +537,7 @@ void GenmapRSB(GenmapHandle h) {
int iter = maxIter;
int npass = 50, ipass = 0;

if(h->Id(h->global) == 0 && h->dbgLevel > 0)
if(h->Id(h->global) == 0 && h->dbgLevel > 0)
printf("running RSB "), fflush(stdout);
#if defined(GENMAP_MPI)
MPI_Barrier(h->global->gsComm.c);
Expand All @@ -555,7 +558,8 @@ void GenmapRSB(GenmapHandle h) {

while(h->Np(h->local) > 1) {

if(h->Id(h->global) == 0 && h->dbgLevel > 1) printf("."), fflush(stdout);
if(h->Id(h->global) == 0
&& h->dbgLevel > 1) printf("."), fflush(stdout);

int global = (h->Np(h->local) == h->Np(h->global));
ipass = 0;
Expand Down Expand Up @@ -663,6 +667,6 @@ void GenmapRSB(GenmapHandle h) {
#else
time = ((double)clock() - t0) / CLOCKS_PER_SEC;
#endif
if(h->Id(h->global) == 0 && h->dbgLevel > 0)
if(h->Id(h->global) == 0 && h->dbgLevel > 0)
printf("\nfinished in %lfs\n", time), fflush(stdout);
}
2 changes: 1 addition & 1 deletion src/genmap-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct GenmapHandle_private {
int (*Write)(GenmapHandle h, char *fileNameBase);

GenmapInt dbgLevel;
GenmapInt printStat;
GenmapInt printStat;
};

// GenmapHandle
Expand Down
4 changes: 2 additions & 2 deletions src/parRSB.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ int parRSB_partMesh(long long *egl, long long *vl, int *negl,
GenmapHandle h;
GenmapInit(&h, comm, "interface");

if (options[0] != 0){
if(options[0] != 0) {
h->dbgLevel = options[1];
h->printStat = options[2];
h->printStat = options[2];
}

// Check if negl is large enough
Expand Down
3 changes: 2 additions & 1 deletion tests/con/con-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ int main(int argc, char *argv[]) {
options[0] = 1; // use custom options
options[1] = 5; // debug level
options[2] = 1; // print statistics
ierr = parRSB_partMesh(el, vl, &nelo, c.el, c.vl, c.nel, c.nv, options, comm);
ierr = parRSB_partMesh(el, vl, &nelo, c.el, c.vl, c.nel, c.nv, options,
comm);
if(ierr) goto quit;


Expand Down

0 comments on commit 02f91e3

Please sign in to comment.