diff --git a/splash2/codes/Makefile.config b/splash2/codes/Makefile.config index 9bcad6686..ffc4ac2ff 100644 --- a/splash2/codes/Makefile.config +++ b/splash2/codes/Makefile.config @@ -6,7 +6,7 @@ CFLAGS := $(CFLAGS) -Wpadded -Winline -Wpointer-arith -Wsign-compare -Wendif-lab LDFLAGS := -lm libpthread.a m5op_x86.o BASEDIR := $(HOME)/GitSource/gem5/splash2/codes -MACROS := $(BASEDIR)/null_macros/c.m4.null.POSIX_BARRIER +MACROS := $(BASEDIR)/null_macros/c.m4.null.POSIX M4 := m4 -s -Ulen -Uindex x = * diff --git a/splash2/codes/apps/barnes/Makefile b/splash2/codes/apps/barnes/Makefile index 9fa5cff9d..4bc3bc9ff 100644 --- a/splash2/codes/apps/barnes/Makefile +++ b/splash2/codes/apps/barnes/Makefile @@ -3,7 +3,7 @@ OBJS = code.o code_io.o load.o grav.o getparam.o util.o include ../../Makefile.config -stdinc.h: code.h defs.h util.h vectmath.h load.h code_io.h grav.h getparam.h stdinc.H +stdinc.h: code.h defs.h util.h vectmath.h load.h code_io.h grav.h getparam.h stdinc.H code.o: code.C stdinc.h code_io.o: code_io.C stdinc.h getparam.o: getparam.C stdinc.h diff --git a/splash2/codes/apps/barnes/code.C b/splash2/codes/apps/barnes/code.C index 3f70c7955..04730ba21 100644 --- a/splash2/codes/apps/barnes/code.C +++ b/splash2/codes/apps/barnes/code.C @@ -131,7 +131,7 @@ string defv[] = { /* DEFAULT PARAMETER VALUES */ static long Child_Sequence[NUM_DIRECTIONS][NSUB] = { - { 2, 5, 6, 1, 0, 3, 4, 7}, /* BRC_FUC */ + { 2, 5, 6, 1, 0, 3, 4, 7}, /* BRC_FUC */ { 2, 5, 6, 1, 0, 7, 4, 3}, /* BRC_FRA */ { 1, 6, 5, 2, 3, 0, 7, 4}, /* BRA_FDA */ { 1, 6, 5, 2, 3, 4, 7, 0}, /* BRA_FRC */ @@ -168,7 +168,7 @@ static long Child_Sequence[NUM_DIRECTIONS][NSUB] = static long Direction_Sequence[NUM_DIRECTIONS][NSUB] = { - { FRC_BUC, BRA_FRC, FDA_BDC, BLA_FUA, BUC_FLC, FUA_BUC, BRA_FRC, FDA_BLA }, + { FRC_BUC, BRA_FRC, FDA_BDC, BLA_FUA, BUC_FLC, FUA_BUC, BRA_FRC, FDA_BLA }, /* BRC_FUC */ { FRC_BUC, BRA_FRC, FDA_BDC, BLA_FUA, BRA_FDA, FRC_BRA, BUC_FUA, FLC_BDC }, /* BRC_FRA */ @@ -242,13 +242,13 @@ int main (int argc, string argv[]) while ((c = getopt(argc, argv, "h")) != -1) { switch(c) { case 'h': - Help(); - exit(-1); - break; + Help(); + exit(-1); + break; default: - fprintf(stderr, "Only valid option is \"-h\".\n"); - exit(-1); - break; + fprintf(stderr, "Only valid option is \"-h\".\n"); + exit(-1); + break; } } @@ -278,17 +278,17 @@ int main (int argc, string argv[]) printf("COMPUTETIME = %12lu\n",Global->computeend - Global->computestart); printf("TRACKTIME = %12lu\n",Global->tracktime); printf("PARTITIONTIME = %12lu\t%5.2f\n",Global->partitiontime, - ((float)Global->partitiontime)/Global->tracktime); + ((float)Global->partitiontime)/Global->tracktime); printf("TREEBUILDTIME = %12lu\t%5.2f\n",Global->treebuildtime, - ((float)Global->treebuildtime)/Global->tracktime); + ((float)Global->treebuildtime)/Global->tracktime); printf("FORCECALCTIME = %12lu\t%5.2f\n",Global->forcecalctime, - ((float)Global->forcecalctime)/Global->tracktime); + ((float)Global->forcecalctime)/Global->tracktime); printf("RESTTIME = %12lu\t%5.2f\n", - Global->tracktime - Global->partitiontime - - Global->treebuildtime - Global->forcecalctime, - ((float)(Global->tracktime-Global->partitiontime- - Global->treebuildtime-Global->forcecalctime))/ - Global->tracktime); + Global->tracktime - Global->partitiontime - + Global->treebuildtime - Global->forcecalctime, + ((float)(Global->tracktime-Global->partitiontime- + Global->treebuildtime-Global->forcecalctime))/ + Global->tracktime); MAIN_END; } @@ -462,7 +462,7 @@ void startrun() else { nbody = getiparam("nbody"); if (nbody < 1) { - error("startrun: absurd nbody\n"); + error("startrun: absurd nbody\n"); } seed = getiparam("seed"); } @@ -527,14 +527,14 @@ void testdata() r = 1 / sqrt(pow(xrand(0.0, MFRAC), -2.0/3.0) - 1); /* reject radii greater than 10 */ while (r > 9.0) { - rejects++; - r = 1 / sqrt(pow(xrand(0.0, MFRAC), -2.0/3.0) - 1); + rejects++; + r = 1 / sqrt(pow(xrand(0.0, MFRAC), -2.0/3.0) - 1); } pickshell(Pos(p), rsc * r); ADDV(cmr, cmr, Pos(p)); do { - x = xrand(0.0, 1.0); - y = xrand(0.0, 0.1); + x = xrand(0.0, 1.0); + y = xrand(0.0, 0.1); } while (y > x*x * pow(1 - x*x, 3.5)); @@ -552,8 +552,8 @@ void testdata() cp = p - halfnbody; for (i = 0; i < NDIM; i++){ - Pos(p)[i] = Pos(cp)[i] + offset; - Vel(p)[i] = Vel(cp)[i]; + Pos(p)[i] = Pos(cp)[i] + offset; + Vel(p)[i] = Vel(cp)[i]; } ADDV(cmr, cmr, Pos(p)); ADDV(cmv, cmv, Vel(p)); @@ -579,7 +579,7 @@ void pickshell(real vec[], real rad) do { for (k = 0; k < NDIM; k++) { - vec[k] = xrand(-1.0, 1.0); + vec[k] = xrand(-1.0, 1.0); } DOTVP(rsq, vec, vec); } while (rsq > 1.0); @@ -653,7 +653,7 @@ void stepsystem(long ProcessId) Cavg = (real) Cost(Global->G_root) / (real)NPROC ; Local[ProcessId].workMin = (long) (Cavg * ProcessId); Local[ProcessId].workMax = (long) (Cavg * (ProcessId + 1) - + (ProcessId == (NPROC - 1))); + + (ProcessId == (NPROC - 1))); if ((ProcessId == 0) && (Local[ProcessId].nstep >= 2)) { CLOCK(partitionstart); @@ -681,7 +681,7 @@ void stepsystem(long ProcessId) /* advance my bodies */ for (pp = Local[ProcessId].mybodytab; - pp < Local[ProcessId].mybodytab+Local[ProcessId].mynbody; pp++) { + pp < Local[ProcessId].mybodytab+Local[ProcessId].mynbody; pp++) { p = *pp; MULVS(dvel, Acc(p), dthf); ADDV(vel1, Vel(p), dvel); @@ -691,20 +691,20 @@ void stepsystem(long ProcessId) for (i = 0; i < NDIM; i++) { if (Pos(p)[i]Local[ProcessId].max[i]) { - Local[ProcessId].max[i]=Pos(p)[i] ; - } + Local[ProcessId].max[i]=Pos(p)[i] ; + } } } LOCK(Global->CountLock); for (i = 0; i < NDIM; i++) { if (Global->min[i] > Local[ProcessId].min[i]) { - Global->min[i] = Local[ProcessId].min[i]; + Global->min[i] = Local[ProcessId].min[i]; } if (Global->max[i] < Local[ProcessId].max[i]) { - Global->max[i] = Local[ProcessId].max[i]; + Global->max[i] = Local[ProcessId].max[i]; } } UNLOCK(Global->CountLock); @@ -722,9 +722,9 @@ void stepsystem(long ProcessId) Global->rsize=0; SUBV(Global->max,Global->max,Global->min); for (i = 0; i < NDIM; i++) { - if (Global->rsize < Global->max[i]) { - Global->rsize = Global->max[i]; - } + if (Global->rsize < Global->max[i]) { + Global->rsize = Global->max[i]; + } } ADDVS(Global->rmin,Global->min,-Global->rsize/100000.0); Global->rsize = 1.00002*Global->rsize; @@ -743,7 +743,7 @@ void ComputeForces(long ProcessId) vector acc1, dacc, dvel; for (pp = Local[ProcessId].mybodytab; - pp < Local[ProcessId].mybodytab+Local[ProcessId].mynbody;pp++) { + pp < Local[ProcessId].mybodytab+Local[ProcessId].mynbody;pp++) { p = *pp; SETV(acc1, Acc(p)); Cost(p)=0; @@ -751,13 +751,13 @@ void ComputeForces(long ProcessId) Local[ProcessId].myn2bcalc += Local[ProcessId].myn2bterm; Local[ProcessId].mynbccalc += Local[ProcessId].mynbcterm; if (!Local[ProcessId].skipself) { /* did we miss self-int? */ - Local[ProcessId].myselfint++; /* count another goofup */ + Local[ProcessId].myselfint++; /* count another goofup */ } if (Local[ProcessId].nstep > 0) { - /* use change in accel to make 2nd order correction to vel */ - SUBV(dacc, Acc(p), acc1); - MULVS(dvel, dacc, dthf); - ADDV(Vel(p), Vel(p), dvel); + /* use change in accel to make 2nd order correction to vel */ + SUBV(dacc, Acc(p), acc1); + MULVS(dvel, dacc, dthf); + ADDV(Vel(p), Vel(p), dvel); } } } @@ -797,29 +797,29 @@ void find_my_bodies(nodeptr mycell, long work, long direction, long ProcessId) if (Type(mycell) == LEAF) { l = (leafptr) mycell; for (i = 0; i < l->num_bodies; i++) { - if (work >= Local[ProcessId].workMin - .1) { - if ((Local[ProcessId].mynbody+2) > maxmybody) { - error("find_my_bodies: Processor %ld needs more than %ld bodies; increase fleaves\n", ProcessId, maxmybody); - } - Local[ProcessId].mybodytab[Local[ProcessId].mynbody++] = - Bodyp(l)[i]; - } - work += Cost(Bodyp(l)[i]); - if (work >= Local[ProcessId].workMax-.1) { - break; - } + if (work >= Local[ProcessId].workMin - .1) { + if((Local[ProcessId].mynbody+2) > maxmybody) { + error("find_my_bodies: Processor %ld needs more than %ld bodies; increase fleaves\n", ProcessId, maxmybody); + } + Local[ProcessId].mybodytab[Local[ProcessId].mynbody++] = + Bodyp(l)[i]; + } + work += Cost(Bodyp(l)[i]); + if (work >= Local[ProcessId].workMax-.1) { + break; + } } } else { - for (i = 0; (i < NSUB) && (work < (Local[ProcessId].workMax - .1)); i++){ - qptr = Subp(mycell)[Child_Sequence[direction][i]]; - if (qptr!=NULL) { - if ((work+Cost(qptr)) >= (Local[ProcessId].workMin -.1)) { - find_my_bodies(qptr,work, Direction_Sequence[direction][i], - ProcessId); - } - work += Cost(qptr); - } + for(i = 0; (i < NSUB) && (work < (Local[ProcessId].workMax - .1)); i++){ + qptr = Subp(mycell)[Child_Sequence[direction][i]]; + if (qptr!=NULL) { + if ((work+Cost(qptr)) >= (Local[ProcessId].workMin -.1)) { + find_my_bodies(qptr,work, Direction_Sequence[direction][i], + ProcessId); + } + work += Cost(qptr); + } } } } @@ -853,8 +853,8 @@ void setbound() for (p = bodytab; p < bodytab+nbody; p++) { for (i=0; iLocal[0].max[i]) Local[0].max[i]=Pos(p)[i] ; + if (Pos(p)[i]Local[0].max[i]) Local[0].max[i]=Pos(p)[i] ; } } diff --git a/splash2/codes/apps/barnes/code_io.C b/splash2/codes/apps/barnes/code_io.C index 2eea96dc1..9f3b983a4 100644 --- a/splash2/codes/apps/barnes/code_io.C +++ b/splash2/codes/apps/barnes/code_io.C @@ -79,9 +79,9 @@ void initoutput() { printf("\n\t\t%s\n\n", headline); printf("%10s%10s%10s%10s%10s%10s%10s%10s\n", - "nbody", "dtime", "eps", "tol", "dtout", "tstop","fcells","NPROC"); + "nbody", "dtime", "eps", "tol", "dtout", "tstop","fcells","NPROC"); printf("%10ld%10.5f%10.4f%10.2f%10.3f%10.3f%10.2f%10ld\n\n", - nbody, dtime, eps, tol, dtout, tstop, fcells, NPROC); + nbody, dtime, eps, tol, dtout, tstop, fcells, NPROC); } /* @@ -157,7 +157,7 @@ void diagnostics(long ProcessId) CLRV(Local[ProcessId].mycmphase[1]); CLRV(Local[ProcessId].myamvec); for (pp = Local[ProcessId].mybodytab+Local[ProcessId].mynbody -1; - pp >= Local[ProcessId].mybodytab; pp--) { + pp >= Local[ProcessId].mybodytab; pp--) { p= *pp; Local[ProcessId].mymtot += Mass(p); DOTVP(velsq, Vel(p), Vel(p)); @@ -181,9 +181,9 @@ void diagnostics(long ProcessId) + Local[ProcessId].myetot[2]; if (Local[ProcessId].mymtot!=0){ DIVVS(Local[ProcessId].mycmphase[0], Local[ProcessId].mycmphase[0], - Local[ProcessId].mymtot); + Local[ProcessId].mymtot); DIVVS(Local[ProcessId].mycmphase[1], Local[ProcessId].mycmphase[1], - Local[ProcessId].mymtot); + Local[ProcessId].mymtot); } } diff --git a/splash2/codes/apps/barnes/defs.H b/splash2/codes/apps/barnes/defs.H index 2eb6e73b1..cf62336c2 100644 --- a/splash2/codes/apps/barnes/defs.H +++ b/splash2/codes/apps/barnes/defs.H @@ -59,7 +59,7 @@ typedef struct _node { long level; struct _node *parent; /* ptr to parent of this node in tree */ long child_num; /* Index that this node should be put - at in parent cell */ + at in parent cell */ } node; typedef node* nodeptr; diff --git a/splash2/codes/apps/barnes/getparam.C b/splash2/codes/apps/barnes/getparam.C index dfb80fd2f..2a2a7a6de 100644 --- a/splash2/codes/apps/barnes/getparam.C +++ b/splash2/codes/apps/barnes/getparam.C @@ -119,7 +119,7 @@ long scanbind(string bvec[], string name) for (i = 0; bvec[i] != NULL; i++) if (matchname(bvec[i], name)) - return (i); + return (i); return (-1); } @@ -151,7 +151,7 @@ string extrvalue(string arg) ap = (char *) arg; while (*ap != '\0') if (*ap++ == '=') - return ((string) ap); + return ((string) ap); return (NULL); } diff --git a/splash2/codes/apps/barnes/grav.C b/splash2/codes/apps/barnes/grav.C index 96b887925..3963e6929 100644 --- a/splash2/codes/apps/barnes/grav.C +++ b/splash2/codes/apps/barnes/grav.C @@ -69,7 +69,7 @@ void gravsub(register nodeptr p, long ProcessId) mor3 = phii / Local[ProcessId].drsq; MULVS(ai, Local[ProcessId].dr, mor3); ADDV(Local[ProcessId].acc0, Local[ProcessId].acc0, ai); - if (Type(p) != BODY) { /* a body-cell/leaf interaction? */ + if(Type(p) != BODY) { /* a body-cell/leaf interaction? */ Local[ProcessId].mynbcterm++; #ifdef QUADPOLE dr5inv = 1.0/(Local[ProcessId].drsq * Local[ProcessId].drsq * drabs); @@ -111,23 +111,23 @@ void walksub(nodeptr n, real dsq, long ProcessId) if (subdivp(n, dsq, ProcessId)) { if (Type(n) == CELL) { - for (nn = Subp(n); nn < Subp(n) + NSUB; nn++) { - if (*nn != NULL) { - walksub(*nn, dsq / 4.0, ProcessId); - } - } + for (nn = Subp(n); nn < Subp(n) + NSUB; nn++) { + if (*nn != NULL) { + walksub(*nn, dsq / 4.0, ProcessId); + } + } } else { - l = (leafptr) n; - for (i = 0; i < l->num_bodies; i++) { - p = Bodyp(l)[i]; - if (p != Local[ProcessId].pskip) { - gravsub(p, ProcessId); - } - else { - Local[ProcessId].skipself = TRUE; - } - } + l = (leafptr) n; + for (i = 0; i < l->num_bodies; i++) { + p = Bodyp(l)[i]; + if (p != Local[ProcessId].pskip) { + gravsub(p, ProcessId); + } + else { + Local[ProcessId].skipself = TRUE; + } + } } } else { diff --git a/splash2/codes/apps/barnes/load.C b/splash2/codes/apps/barnes/load.C index dc1e3768d..4e7ec5423 100644 --- a/splash2/codes/apps/barnes/load.C +++ b/splash2/codes/apps/barnes/load.C @@ -34,18 +34,18 @@ void maketree(long ProcessId) } Local[ProcessId].Current_Root = (nodeptr) Global->G_root; for (pp = Local[ProcessId].mybodytab; - pp < Local[ProcessId].mybodytab+Local[ProcessId].mynbody; pp++) { + pp < Local[ProcessId].mybodytab+Local[ProcessId].mynbody; pp++) { p = *pp; if (Mass(p) != 0.0) { - Local[ProcessId].Current_Root - = (nodeptr) loadtree(p, (cellptr) Local[ProcessId].Current_Root, - ProcessId); + Local[ProcessId].Current_Root + = (nodeptr) loadtree(p, (cellptr) Local[ProcessId].Current_Root, + ProcessId); } else { - LOCK(Global->io_lock); - fprintf(stderr, "Process %ld found body %ld to have zero mass\n", - ProcessId, (long) p); - UNLOCK(Global->io_lock); + LOCK(Global->io_lock); + fprintf(stderr, "Process %ld found body %ld to have zero mass\n", + ProcessId, (long) p); + UNLOCK(Global->io_lock); } } BARRIER(Global->Barrier,NPROC); @@ -104,29 +104,29 @@ void printtree(nodeptr n) PRTV("Pos", Pos(n)); printf("\n"); for (k = 0; k < NSUB; k++) { - printf("Child #%ld: ", k); - if (Subp(c)[k] == NULL) { - printf("NONE"); - } - else { - if (Type(Subp(c)[k]) == CELL) { - nseq = ((cellptr) Subp(c)[k])->seqnum; - printf("C: Cost = %ld, ", Cost(Subp(c)[k])); - } - else { - nseq = ((leafptr) Subp(c)[k])->seqnum; - printf("L: # Bodies = %2ld, Cost = %ld, ", - ((leafptr) Subp(c)[k])->num_bodies, Cost(Subp(c)[k])); - } - tmp = Subp(c)[k]; - PRTV("Pos", Pos(tmp)); - } - printf("\n"); + printf("Child #%ld: ", k); + if (Subp(c)[k] == NULL) { + printf("NONE"); + } + else { + if (Type(Subp(c)[k]) == CELL) { + nseq = ((cellptr) Subp(c)[k])->seqnum; + printf("C: Cost = %ld, ", Cost(Subp(c)[k])); + } + else { + nseq = ((leafptr) Subp(c)[k])->seqnum; + printf("L: # Bodies = %2ld, Cost = %ld, ", + ((leafptr) Subp(c)[k])->num_bodies, Cost(Subp(c)[k])); + } + tmp = Subp(c)[k]; + PRTV("Pos", Pos(tmp)); + } + printf("\n"); } for (k=0;knum_bodies; k++) { - p = Bodyp(l)[k]; - printf("Body #%2ld: Num = %2ld, Level = %ld, ", - p - bodytab, k, Level(p)); - PRTV("Pos",Pos(p)); - printf("\n"); + p = Bodyp(l)[k]; + printf("Body #%2ld: Num = %2ld, Level = %ld, ", + p - bodytab, k, Level(p)); + PRTV("Pos",Pos(p)); + printf("\n"); } break; default: @@ -171,34 +171,34 @@ nodeptr loadtree(bodyptr p, cellptr root, long ProcessId) } for (i = IMAX >> 1; i > Level(root); i >>= 1) { for (j = 0; j < NDIM; j++) { - if (xor[j] & i) { - valid_root = FALSE; - break; - } + if (xor[j] & i) { + valid_root = FALSE; + break; + } } if (!valid_root) { - break; + break; } } if (!valid_root) { if (root != Global->G_root) { - root_level = Level(root); - for (j = i; j > root_level; j >>= 1) { - root = (cellptr) Parent(root); - } - valid_root = TRUE; - for (i = IMAX >> 1; i > Level(root); i >>= 1) { - for (j = 0; j < NDIM; j++) { - if (xor[j] & i) { - valid_root = FALSE; - break; - } - } - if (!valid_root) { - printf("P%ld body %ld\n", ProcessId, p - bodytab); - root = Global->G_root; - } - } + root_level = Level(root); + for (j = i; j > root_level; j >>= 1) { + root = (cellptr) Parent(root); + } + valid_root = TRUE; + for (i = IMAX >> 1; i > Level(root); i >>= 1) { + for (j = 0; j < NDIM; j++) { + if (xor[j] & i) { + valid_root = FALSE; + break; + } + } + if (!valid_root) { + printf("P%ld body %ld\n", ProcessId, p - bodytab); + root = Global->G_root; + } + } } } root = Global->G_root; @@ -210,50 +210,50 @@ nodeptr loadtree(bodyptr p, cellptr root, long ProcessId) flag = TRUE; while (flag) { /* loop descending tree */ if (l == 0) { - error("not enough levels in tree\n"); + error("not enough levels in tree\n"); } if (*qptr == NULL) { - /* lock the parent cell */ - ALOCK(CellLock->CL, ((cellptr) mynode)->seqnum % MAXLOCK); - if (*qptr == NULL) { - le = InitLeaf((cellptr) mynode, ProcessId); - Parent(p) = (nodeptr) le; - Level(p) = l; - ChildNum(p) = le->num_bodies; - ChildNum(le) = kidIndex; - Bodyp(le)[le->num_bodies++] = p; - *qptr = (nodeptr) le; - flag = FALSE; - } - AULOCK(CellLock->CL, ((cellptr) mynode)->seqnum % MAXLOCK); - /* unlock the parent cell */ + /* lock the parent cell */ + ALOCK(CellLock->CL, ((cellptr) mynode)->seqnum % MAXLOCK); + if (*qptr == NULL) { + le = InitLeaf((cellptr) mynode, ProcessId); + Parent(p) = (nodeptr) le; + Level(p) = l; + ChildNum(p) = le->num_bodies; + ChildNum(le) = kidIndex; + Bodyp(le)[le->num_bodies++] = p; + *qptr = (nodeptr) le; + flag = FALSE; + } + AULOCK(CellLock->CL, ((cellptr) mynode)->seqnum % MAXLOCK); + /* unlock the parent cell */ } if (flag && *qptr && (Type(*qptr) == LEAF)) { - /* reached a "leaf"? */ - ALOCK(CellLock->CL, ((cellptr) mynode)->seqnum % MAXLOCK); - /* lock the parent cell */ - if (Type(*qptr) == LEAF) { /* still a "leaf"? */ - le = (leafptr) *qptr; - if (le->num_bodies == MAX_BODIES_PER_LEAF) { - *qptr = (nodeptr) SubdivideLeaf(le, (cellptr) mynode, l, - ProcessId); - } - else { - Parent(p) = (nodeptr) le; - Level(p) = l; - ChildNum(p) = le->num_bodies; - Bodyp(le)[le->num_bodies++] = p; - flag = FALSE; - } - } - AULOCK(CellLock->CL, ((cellptr) mynode)->seqnum % MAXLOCK); - /* unlock the node */ + /* reached a "leaf"? */ + ALOCK(CellLock->CL, ((cellptr) mynode)->seqnum % MAXLOCK); + /* lock the parent cell */ + if (Type(*qptr) == LEAF) { /* still a "leaf"? */ + le = (leafptr) *qptr; + if (le->num_bodies == MAX_BODIES_PER_LEAF) { + *qptr = (nodeptr) SubdivideLeaf(le, (cellptr) mynode, l, + ProcessId); + } + else { + Parent(p) = (nodeptr) le; + Level(p) = l; + ChildNum(p) = le->num_bodies; + Bodyp(le)[le->num_bodies++] = p; + flag = FALSE; + } + } + AULOCK(CellLock->CL, ((cellptr) mynode)->seqnum % MAXLOCK); + /* unlock the node */ } if (flag) { - mynode = *qptr; + mynode = *qptr; kidIndex = subindex(xp, l); - qptr = &Subp(*qptr)[kidIndex]; /* move down one level */ - l = l >> 1; /* and test next bit */ + qptr = &Subp(*qptr)[kidIndex]; /* move down one level */ + l = l >> 1; /* and test next bit */ } } SETV(Local[ProcessId].Root_Coords, xp); @@ -276,10 +276,10 @@ bool intcoord(long xp[NDIM], vector rp) for (k = 0; k < NDIM; k++) { xsc = (rp[k] - Global->rmin[k]) / Global->rsize; if (0.0 <= xsc && xsc < 1.0) { - xp[k] = floor(IMAX * xsc); + xp[k] = floor(IMAX * xsc); } else { - inb = FALSE; + inb = FALSE; } } return (inb); @@ -304,8 +304,8 @@ long subindex(long x[NDIM], long l) } for (k = 1; k < NDIM; k++) { if (((x[k] & l) && !yes) || (!(x[k] & l) && yes)) { - i += NSUB >> (k + 1); - yes = TRUE; + i += NSUB >> (k + 1); + yes = TRUE; } else yes = FALSE; } @@ -335,72 +335,72 @@ void hackcofm(long ProcessId) /* this way, we look at child cells before parents */ for (ll = Local[ProcessId].myleaftab + Local[ProcessId].mynleaf - 1; - ll >= Local[ProcessId].myleaftab; ll--) { + ll >= Local[ProcessId].myleaftab; ll--) { l = *ll; Mass(l) = 0.0; Cost(l) = 0; CLRV(Pos(l)); for (i = 0; i < l->num_bodies; i++) { - p = Bodyp(l)[i]; - Mass(l) += Mass(p); - Cost(l) += Cost(p); - MULVS(tmpv, Pos(p), Mass(p)); - ADDV(Pos(l), Pos(l), tmpv); + p = Bodyp(l)[i]; + Mass(l) += Mass(p); + Cost(l) += Cost(p); + MULVS(tmpv, Pos(p), Mass(p)); + ADDV(Pos(l), Pos(l), tmpv); } DIVVS(Pos(l), Pos(l), Mass(l)); #ifdef QUADPOLE CLRM(Quad(l)); for (i = 0; i < l->num_bodies; i++) { - p = Bodyp(l)[i]; - SUBV(dr, Pos(p), Pos(l)); - OUTVP(drdr, dr, dr); - DOTVP(drsq, dr, dr); - SETMI(Idrsq); - MULMS(Idrsq, Idrsq, drsq); - MULMS(tmpm, drdr, 3.0); - SUBM(tmpm, tmpm, Idrsq); - MULMS(tmpm, tmpm, Mass(p)); - ADDM(Quad(l), Quad(l), tmpm); + p = Bodyp(l)[i]; + SUBV(dr, Pos(p), Pos(l)); + OUTVP(drdr, dr, dr); + DOTVP(drsq, dr, dr); + SETMI(Idrsq); + MULMS(Idrsq, Idrsq, drsq); + MULMS(tmpm, drdr, 3.0); + SUBM(tmpm, tmpm, Idrsq); + MULMS(tmpm, tmpm, Mass(p)); + ADDM(Quad(l), Quad(l), tmpm); } #endif Done(l)=TRUE; } for (cc = Local[ProcessId].mycelltab+Local[ProcessId].myncell-1; - cc >= Local[ProcessId].mycelltab; cc--) { + cc >= Local[ProcessId].mycelltab; cc--) { q = *cc; Mass(q) = 0.0; Cost(q) = 0; CLRV(Pos(q)); for (i = 0; i < NSUB; i++) { - r = Subp(q)[i]; - if (r != NULL) { - while (!Done(r)) { - /* wait */ - } - Mass(q) += Mass(r); - Cost(q) += Cost(r); - MULVS(tmpv, Pos(r), Mass(r)); - ADDV(Pos(q), Pos(q), tmpv); - Done(r) = FALSE; - } + r = Subp(q)[i]; + if (r != NULL) { + while(!Done(r)) { + /* wait */ + } + Mass(q) += Mass(r); + Cost(q) += Cost(r); + MULVS(tmpv, Pos(r), Mass(r)); + ADDV(Pos(q), Pos(q), tmpv); + Done(r) = FALSE; + } } DIVVS(Pos(q), Pos(q), Mass(q)); #ifdef QUADPOLE CLRM(Quad(q)); for (i = 0; i < NSUB; i++) { - r = Subp(q)[i]; - if (r != NULL) { - SUBV(dr, Pos(r), Pos(q)); - OUTVP(drdr, dr, dr); - DOTVP(drsq, dr, dr); - SETMI(Idrsq); - MULMS(Idrsq, Idrsq, drsq); - MULMS(tmpm, drdr, 3.0); - SUBM(tmpm, tmpm, Idrsq); - MULMS(tmpm, tmpm, Mass(r)); - ADDM(tmpm, tmpm, Quad(r)); - ADDM(Quad(q), Quad(q), tmpm); - } + r = Subp(q)[i]; + if (r != NULL) { + SUBV(dr, Pos(r), Pos(q)); + OUTVP(drdr, dr, dr); + DOTVP(drsq, dr, dr); + SETMI(Idrsq); + MULMS(Idrsq, Idrsq, drsq); + MULMS(tmpm, drdr, 3.0); + SUBM(tmpm, tmpm, Idrsq); + MULMS(tmpm, tmpm, Mass(r)); + ADDM(tmpm, tmpm, Quad(r)); + ADDM(Quad(q), Quad(q), tmpm); + } } #endif Done(q)=TRUE; @@ -446,12 +446,12 @@ cellptr SubdivideLeaf(leafptr le, cellptr parent, long l, long ProcessId) intcoord(xp, Pos(p)); index = subindex(xp, l); if (!Subp(c)[index]) { - le = InitLeaf(c, ProcessId); - ChildNum(le) = index; - Subp(c)[index] = (nodeptr) le; + le = InitLeaf(c, ProcessId); + ChildNum(le) = index; + Subp(c)[index] = (nodeptr) le; } else { - le = (leafptr) Subp(c)[index]; + le = (leafptr) Subp(c)[index]; } Parent(p) = (nodeptr) le; ChildNum(p) = le->num_bodies; @@ -472,7 +472,7 @@ cellptr makecell(long ProcessId) if (Local[ProcessId].mynumcell == maxmycell) { error("makecell: Proc %ld needs more than %ld cells; increase fcells\n", - ProcessId,maxmycell); + ProcessId,maxmycell); } Mycell = Local[ProcessId].mynumcell++; c = Local[ProcessId].ctab + Mycell; @@ -498,7 +498,7 @@ leafptr makeleaf(long ProcessId) if (Local[ProcessId].mynumleaf == maxmyleaf) { error("makeleaf: Proc %ld needs more than %ld leaves; increase fleaves\n", - ProcessId,maxmyleaf); + ProcessId,maxmyleaf); } Myleaf = Local[ProcessId].mynumleaf++; le = Local[ProcessId].ltab + Myleaf; diff --git a/splash2/codes/apps/barnes/stdinc.H b/splash2/codes/apps/barnes/stdinc.H index f8d325441..0769b9aa2 100644 --- a/splash2/codes/apps/barnes/stdinc.H +++ b/splash2/codes/apps/barnes/stdinc.H @@ -21,14 +21,13 @@ #ifndef _STDINC_H_ #define _STDINC_H_ +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include - #define error(msg, ...) printf(msg, ##__VA_ARGS__); /* * STREAM: a replacement for FILE *. @@ -60,9 +59,9 @@ typedef char byte; */ typedef char *string; - + /* - * REAL: default type is double; + * REAL: default type is double; */ typedef double real, *realptr; @@ -99,7 +98,7 @@ typedef real (*rproc)(); #define FOUR_PI 12.56637061435917295385 #define HALF_PI 1.57079632679489661923 #define FRTHRD_PI 4.18879020478639098462 - + /* * ABS: returns the absolute value of its argument * MAX: returns the argument with the highest value @@ -108,13 +107,13 @@ typedef real (*rproc)(); #define ABS(x) (((x) < 0) ? -(x) : (x)) -#include "code.h" -#include "code_io.h" -#include "defs.h" -#include "getparam.h" -#include "grav.h" -#include "load.h" -#include "util.h" #include "vectmath.h" +#include "defs.h" +#include "code.h" +#include "util.h" +#include "load.h" +#include "code_io.h" +#include "grav.h" +#include "getparam.h" #endif diff --git a/splash2/codes/apps/barnes/util.C b/splash2/codes/apps/barnes/util.C index cd19e4fab..97dbf6874 100644 --- a/splash2/codes/apps/barnes/util.C +++ b/splash2/codes/apps/barnes/util.C @@ -50,7 +50,7 @@ void pranset(long seed) double prand() /* - Return a random double in [0, 1.0) + Return a random double in [0, 1.0) */ { lastrand = randx; diff --git a/splash2/codes/apps/fmm/box.C b/splash2/codes/apps/fmm/box.C index b0b81af36..ad5d1b4de 100644 --- a/splash2/codes/apps/fmm/box.C +++ b/splash2/codes/apps/fmm/box.C @@ -14,13 +14,12 @@ /* */ /*************************************************************************/ -#include -#include - -#include "box.h" +#include +#include #include "defs.h" #include "memory.h" #include "particle.h" +#include "box.h" /* How many boxes can fit on one line */ #define BOXES_PER_LINE 4 @@ -48,7 +47,7 @@ CreateBoxes (long my_id, long num_boxes) starting_address = (char *) Local[my_id].B_Heap; ending_address = (((char *) Local[my_id].B_Heap) - + (num_boxes * sizeof(particle *)) - 1); + + (num_boxes * sizeof(particle *)) - 1); Place all addresses x such that (starting_address <= x < ending_address) on node my_id @@ -167,19 +166,19 @@ PrintBox (box *b) printf(" Type = %d\n", b->type); printf(" Child Num = %ld\n", b->child_num); if (b->parent == NULL) - printf(" Parent = NONE\n"); + printf(" Parent = NONE\n"); else - printf(" Parent = B%f\n", b->parent->id); + printf(" Parent = B%f\n", b->parent->id); printf(" Children's IDs : "); if (b->num_children != 0) - PrintBoxArrayIds(b->children, b->num_children); + PrintBoxArrayIds(b->children, b->num_children); else - printf("NONE\n"); + printf("NONE\n"); printf(" Sibling's IDs : "); if (b->num_siblings != 0) - PrintBoxArrayIds(b->siblings, b->num_siblings); + PrintBoxArrayIds(b->siblings, b->num_siblings); else - printf("NONE\n"); + printf("NONE\n"); printf(" Colleagues' IDs : "); PrintBoxArrayIds(b->colleagues, b->num_colleagues); printf(" U List IDs : "); @@ -222,11 +221,11 @@ PrintBoxArrayIds (box *b_array[], long array_length) tab_count = 0; for (i = 0; i < array_length; i++) { if (tab_count == 0) { - printf("\n"); - tab_count = BOXES_PER_LINE; + printf("\n"); + tab_count = BOXES_PER_LINE; } if (b_array[i] != NULL) - printf("\tB%f", b_array[i]->id); + printf("\tB%f", b_array[i]->id); tab_count -= 1; } printf("\n"); @@ -251,13 +250,13 @@ PrintExpansionTerms (complex expansion[]) for (i = 0; i < Expansion_Terms; i++) { if (tab_count == 0) { - printf("\n"); - tab_count = TERMS_PER_LINE; + printf("\n"); + tab_count = TERMS_PER_LINE; } if (expansion[i].i >= (real) 0.0) - printf("\ta%ld = %.3e + %.3ei", i, expansion[i].r, expansion[i].i); + printf("\ta%ld = %.3e + %.3ei", i, expansion[i].r, expansion[i].i); else - printf("\ta%ld = %.3e - %.3ei", i, expansion[i].r, -expansion[i].i); + printf("\ta%ld = %.3e - %.3ei", i, expansion[i].r, -expansion[i].i); tab_count -= 1; } printf("\n"); @@ -271,8 +270,8 @@ ListIterate (long my_id, box *b, box **list, long length, list_function function for (i = 0; i < length; i++) { if (list[i] == NULL) { - LockedPrint("ERROR (P%d) : NULL list entry\n", my_id); - exit(-1); + LockedPrint("ERROR (P%d) : NULL list entry\n", my_id); + exit(-1); } (*function)(my_id, list[i], b); } @@ -312,10 +311,10 @@ AdjacentBoxes (box *b1, box *b2) ret_val = TRUE; else if ((y_separation == exact_separation) && - (x_separation <= exact_separation)) - ret_val = TRUE; + (x_separation <= exact_separation)) + ret_val = TRUE; else - ret_val = FALSE; + ret_val = FALSE; return ret_val; } diff --git a/splash2/codes/apps/fmm/construct_grid.C b/splash2/codes/apps/fmm/construct_grid.C index c99bb1c05..e0a59de23 100644 --- a/splash2/codes/apps/fmm/construct_grid.C +++ b/splash2/codes/apps/fmm/construct_grid.C @@ -14,15 +14,14 @@ /* */ /*************************************************************************/ -#include -#include - -#include "box.h" -#include "construct_grid.h" +#include +#include #include "defs.h" #include "memory.h" #include "particle.h" +#include "box.h" #include "partition_grid.h" +#include "construct_grid.h" #define MY_PARTICLES (Local[my_id].Particles) #define MY_NUM_PARTICLES (Local[my_id].Num_Particles) @@ -74,10 +73,10 @@ ConstructGrid (long my_id, time_info *local_time, long time_all) CLOCK(start); if (MY_NUM_PARTICLES > 0) { ConstructLocalGrid(my_id); /* Each processor constructs their own tree - based on only their particles */ + based on only their particles */ MergeLocalGrid(my_id); /* The processors combine their trees into one - global tree. This step contains - communication between processors. */ + global tree. This step contains + communication between processors. */ } BARRIER(G_Memory->synch, Number_Of_Processors); CleanupGrid(my_id); @@ -128,13 +127,13 @@ DestroyGrid (long my_id, time_info *local_time, long time_all) b_scan = b_scan->next; particle_cost = tb->cost / tb->num_particles; for (i = 0; i < tb->num_particles; i++) { - if (MY_MAX_PARTICLES <= MY_NUM_PARTICLES) { - LockedPrint("ERROR (P%d) : Too many particles in local array\n", my_id); - exit(-1); - } - p = tb->particles[i]; - p->cost = particle_cost; - MY_PARTICLES[MY_NUM_PARTICLES++] = p; + if (MY_MAX_PARTICLES <= MY_NUM_PARTICLES) { + LockedPrint("ERROR (P%d) : Too many particles in local array\n", my_id); + exit(-1); + } + p = tb->particles[i]; + p->cost = particle_cost; + MY_PARTICLES[MY_NUM_PARTICLES++] = p; } } if (my_id == 0) @@ -161,15 +160,15 @@ PrintGrid (long my_id) { if (Grid != NULL) { if (my_id == 0) { - printf("Info for Adaptive Grid :\n"); - printf("Boxes :\n\n"); + printf("Info for Adaptive Grid :\n"); + printf("Boxes :\n\n"); } fflush(stdout); BARRIER(G_Memory->synch, Number_Of_Processors); PartitionIterate(my_id, PrintBox, TOP); BARRIER(G_Memory->synch, Number_Of_Processors); if (my_id == 0) { - printf("\n"); + printf("\n"); } fflush(stdout); BARRIER(G_Memory->synch, Number_Of_Processors); @@ -183,9 +182,9 @@ void DetermineGridSize (long my_id) { DetermineLocalGridSize(my_id); /* Processor looks at its own particles and - finds the x and y max and min */ + finds the x and y max and min */ MergeLocalGridSize(my_id); /* Processors shares info with others and each - one computes the global max and min */ + one computes the global max and min */ } @@ -211,29 +210,29 @@ DetermineLocalGridSize (long my_id) x_pos2 = MY_PARTICLES[i + 1]->pos.x; y_pos2 = MY_PARTICLES[i + 1]->pos.y; if (x_pos1 > x_pos2) { - x_max_challenger = x_pos1; - x_min_challenger = x_pos2; + x_max_challenger = x_pos1; + x_min_challenger = x_pos2; } else { - x_max_challenger = x_pos2; - x_min_challenger = x_pos1; + x_max_challenger = x_pos2; + x_min_challenger = x_pos1; } if (y_pos1 > y_pos2) { - y_max_challenger = y_pos1; - y_min_challenger = y_pos2; + y_max_challenger = y_pos1; + y_min_challenger = y_pos2; } else { - y_max_challenger = y_pos2; - y_min_challenger = y_pos1; + y_max_challenger = y_pos2; + y_min_challenger = y_pos1; } if (x_max_challenger > Local[my_id].Local_X_Max) - Local[my_id].Local_X_Max = x_max_challenger; + Local[my_id].Local_X_Max = x_max_challenger; if (x_min_challenger < Local[my_id].Local_X_Min) - Local[my_id].Local_X_Min = x_min_challenger; + Local[my_id].Local_X_Min = x_min_challenger; if (y_max_challenger > Local[my_id].Local_Y_Max) - Local[my_id].Local_Y_Max = y_max_challenger; + Local[my_id].Local_Y_Max = y_max_challenger; if (y_min_challenger < Local[my_id].Local_Y_Min) - Local[my_id].Local_Y_Min = y_min_challenger; + Local[my_id].Local_Y_Min = y_min_challenger; } if (i == (MY_NUM_PARTICLES - 1)) { x_max_challenger = MY_PARTICLES[i]->pos.x; @@ -241,13 +240,13 @@ DetermineLocalGridSize (long my_id) y_max_challenger = MY_PARTICLES[i]->pos.y; y_min_challenger = MY_PARTICLES[i]->pos.y; if (x_max_challenger > Local[my_id].Local_X_Max) - Local[my_id].Local_X_Max = x_max_challenger; + Local[my_id].Local_X_Max = x_max_challenger; if (x_min_challenger < Local[my_id].Local_X_Min) - Local[my_id].Local_X_Min = x_min_challenger; + Local[my_id].Local_X_Min = x_min_challenger; if (y_max_challenger > Local[my_id].Local_Y_Max) - Local[my_id].Local_Y_Max = y_max_challenger; + Local[my_id].Local_Y_Max = y_max_challenger; if (y_min_challenger < Local[my_id].Local_Y_Min) - Local[my_id].Local_Y_Min = y_min_challenger; + Local[my_id].Local_Y_Min = y_min_challenger; } } @@ -275,13 +274,13 @@ MergeLocalGridSize (long my_id) y_max_challenger = their_f_array[2]; y_min_challenger = their_f_array[3]; if (x_max_challenger > Local[my_id].Local_X_Max) - Local[my_id].Local_X_Max = x_max_challenger; + Local[my_id].Local_X_Max = x_max_challenger; if (x_min_challenger < Local[my_id].Local_X_Min) - Local[my_id].Local_X_Min = x_min_challenger; + Local[my_id].Local_X_Min = x_min_challenger; if (y_max_challenger > Local[my_id].Local_Y_Max) - Local[my_id].Local_Y_Max = y_max_challenger; + Local[my_id].Local_Y_Max = y_max_challenger; if (y_min_challenger < Local[my_id].Local_Y_Min) - Local[my_id].Local_Y_Min = y_min_challenger; + Local[my_id].Local_Y_Min = y_min_challenger; } } @@ -291,7 +290,7 @@ ConstructLocalGrid (long my_id) { Local[my_id].Local_Grid = InitGrid(my_id); /* Create the root box */ InsertParticlesInTree(my_id, MY_PARTICLES, MY_NUM_PARTICLES, - Local[my_id].Local_Grid); + Local[my_id].Local_Grid); /* Put all of your particles into your local tree */ } @@ -309,28 +308,28 @@ InitGrid (long my_id) Local[my_id].Local_X_Max = ldexp(1.0, exp); else { if (Local[my_id].Local_X_Max < 0) - Local[my_id].Local_X_Max = -ldexp(1.0, exp - 1); + Local[my_id].Local_X_Max = -ldexp(1.0, exp - 1); } frexp(Local[my_id].Local_X_Min, &exp); if (Local[my_id].Local_X_Min < 0) Local[my_id].Local_X_Min = -ldexp(1.0, exp); else { if (Local[my_id].Local_X_Min > 0) - Local[my_id].Local_X_Min = ldexp(1.0, exp - 1); + Local[my_id].Local_X_Min = ldexp(1.0, exp - 1); } frexp(Local[my_id].Local_Y_Max, &exp); if (Local[my_id].Local_Y_Max > 0) Local[my_id].Local_Y_Max = ldexp(1.0, exp); else { if (Local[my_id].Local_Y_Max < 0) - Local[my_id].Local_Y_Max = -ldexp(1.0, exp - 1); + Local[my_id].Local_Y_Max = -ldexp(1.0, exp - 1); } frexp(Local[my_id].Local_Y_Min, &exp); if (Local[my_id].Local_Y_Min < 0) Local[my_id].Local_Y_Min = -ldexp(1.0, exp); else { if (Local[my_id].Local_Y_Min > 0) - Local[my_id].Local_Y_Min = ldexp(1.0, exp - 1); + Local[my_id].Local_Y_Min = ldexp(1.0, exp - 1); } x_length = Local[my_id].Local_X_Max - Local[my_id].Local_X_Min; @@ -369,12 +368,12 @@ InsertParticlesInTree (long my_id, particle **p_list, long num_of_particles, box dest_box = FindHome(my_id, p, dest_box); dest_box->particles[dest_box->num_particles++] = p; while (dest_box->num_particles > MAX_PARTICLES_PER_BOX) { - SubdivideBox(my_id, dest_box); - if (dest_box->num_children == 1) { - for (j = 0; dest_box->children[j] == NULL; j++) - ; - dest_box = dest_box->children[j]; - } + SubdivideBox(my_id, dest_box); + if (dest_box->num_children == 1) { + for (j = 0; dest_box->children[j] == NULL; j++) + ; + dest_box = dest_box->children[j]; + } } } } @@ -393,28 +392,28 @@ FindHome (long my_id, particle *p, box *current_home) pb = FindInitialRoot(p, current_home); while (pb->type == PARENT) { if (p->pos.y > pb->y_center) { - if (p->pos.x > pb->x_center) { - if (pb->children[0] == NULL) - CreateChild(my_id, pb, 0); - pb = pb->children[0]; - } - else { - if (pb->children[1] == NULL) - CreateChild(my_id, pb, 1); - pb = pb->children[1]; - } + if (p->pos.x > pb->x_center) { + if (pb->children[0] == NULL) + CreateChild(my_id, pb, 0); + pb = pb->children[0]; + } + else { + if (pb->children[1] == NULL) + CreateChild(my_id, pb, 1); + pb = pb->children[1]; + } } else { - if (p->pos.x > pb->x_center) { - if (pb->children[3] == NULL) - CreateChild(my_id, pb, 3); - pb = pb->children[3]; - } - else { - if (pb->children[2] == NULL) - CreateChild(my_id, pb, 2); - pb = pb->children[2]; - } + if (p->pos.x > pb->x_center) { + if (pb->children[3] == NULL) + CreateChild(my_id, pb, 3); + pb = pb->children[3]; + } + else { + if (pb->children[2] == NULL) + CreateChild(my_id, pb, 2); + pb = pb->children[2]; + } } } return pb; @@ -432,14 +431,14 @@ FindInitialRoot (particle *p, box *current_home) x_center_distance = p->pos.x - current_home->x_center; y_center_distance = p->pos.y - current_home->y_center; if (x_center_distance < 0) - x_center_distance = -x_center_distance; + x_center_distance = -x_center_distance; if (y_center_distance < 0) - y_center_distance = -y_center_distance; + y_center_distance = -y_center_distance; if ((x_center_distance > (current_home->length / 2.0)) || - (y_center_distance > (current_home->length / 2.0))) - current_home = current_home->parent; + (y_center_distance > (current_home->length / 2.0))) + current_home = current_home->parent; else - found = TRUE; + found = TRUE; } return current_home; } @@ -461,26 +460,26 @@ CreateChild (long my_id, box *pb, long new_child_num) child_offset = pb->length / (real) NUM_OFFSPRING; if (new_child_num == 0) { pb->children[0] = InitBox(my_id, (pb->x_center + child_offset), - (pb->y_center + child_offset), child_length, - pb); + (pb->y_center + child_offset), child_length, + pb); pb->shadow[0] = pb->children[0]; } if (new_child_num == 1) { pb->children[1] = InitBox(my_id, (pb->x_center - child_offset), - (pb->y_center + child_offset), child_length, - pb); + (pb->y_center + child_offset), child_length, + pb); pb->shadow[1] = pb->children[1]; } if (new_child_num == 2) { pb->children[2] = InitBox(my_id, (pb->x_center - child_offset), - (pb->y_center - child_offset), child_length, - pb); + (pb->y_center - child_offset), child_length, + pb); pb->shadow[2] = pb->children[2]; } if (new_child_num == 3) { pb->children[3] = InitBox(my_id, (pb->x_center + child_offset), - (pb->y_center - child_offset), child_length, - pb); + (pb->y_center - child_offset), child_length, + pb); pb->shadow[3] = pb->children[3]; } pb->children[new_child_num]->child_num = new_child_num; @@ -502,28 +501,28 @@ SubdivideBox (long my_id, box *b) for (i = 0; i < b->num_particles; i++) { p = b->particles[i]; if (p->pos.y > b->y_center) { - if (p->pos.x > b->x_center) { - child = b->children[0]; - if (child == NULL) - child = CreateChild(my_id, b, 0); - } - else { - child = b->children[1]; - if (child == NULL) - child = CreateChild(my_id, b, 1); - } + if (p->pos.x > b->x_center) { + child = b->children[0]; + if (child == NULL) + child = CreateChild(my_id, b, 0); + } + else { + child = b->children[1]; + if (child == NULL) + child = CreateChild(my_id, b, 1); + } } else { - if (p->pos.x > b->x_center) { - child = b->children[3]; - if (child == NULL) - child = CreateChild(my_id, b, 3); - } - else { - child = b->children[2]; - if (child == NULL) - child = CreateChild(my_id, b, 2); - } + if (p->pos.x > b->x_center) { + child = b->children[3]; + if (child == NULL) + child = CreateChild(my_id, b, 3); + } + else { + child = b->children[2]; + if (child == NULL) + child = CreateChild(my_id, b, 2); + } } child->particles[child->num_particles++] = p; b->particles[i] = NULL; @@ -554,53 +553,53 @@ MLGHelper (long my_id, box *local_box, box *global_box, box *global_parent) success = FALSE; while (success == FALSE) { if (local_box->type == PARENT) { - if (global_box == NULL) { - success = InsertBoxInGrid(my_id, local_box, global_parent); - } - else { - if (global_box->type == PARENT) { - success = TRUE; - for (i = 0; i < NUM_OFFSPRING; i++) { - if (local_box->children[i] != NULL) - MLGHelper(my_id, local_box->children[i], - global_box->children[i], global_box); - } - } - else { - success = RemoveBoxFromGrid(global_box, global_parent); - if (success == TRUE) { - InsertParticlesInTree(my_id, global_box->particles, - global_box->num_particles, local_box); - success = InsertBoxInGrid(my_id, local_box, global_parent); - } - } - } + if (global_box == NULL) { + success = InsertBoxInGrid(my_id, local_box, global_parent); + } + else { + if (global_box->type == PARENT) { + success = TRUE; + for (i = 0; i < NUM_OFFSPRING; i++) { + if (local_box->children[i] != NULL) + MLGHelper(my_id, local_box->children[i], + global_box->children[i], global_box); + } + } + else { + success = RemoveBoxFromGrid(global_box, global_parent); + if (success == TRUE) { + InsertParticlesInTree(my_id, global_box->particles, + global_box->num_particles, local_box); + success = InsertBoxInGrid(my_id, local_box, global_parent); + } + } + } } else { - if (global_box == NULL) { - success = InsertBoxInGrid(my_id, local_box, global_parent); - } - else { - if (global_box->type == PARENT) { - MergeLocalParticles(my_id, local_box->particles, - local_box->num_particles, global_box); - success = TRUE; - } - else { - success = RemoveBoxFromGrid(global_box, global_parent); - if (success == TRUE) { - InsertParticlesInLeaf(my_id, global_box->particles, - global_box->num_particles, local_box); - success = InsertBoxInGrid(my_id, local_box, global_parent); - } - } - } + if (global_box == NULL) { + success = InsertBoxInGrid(my_id, local_box, global_parent); + } + else { + if (global_box->type == PARENT) { + MergeLocalParticles(my_id, local_box->particles, + local_box->num_particles, global_box); + success = TRUE; + } + else { + success = RemoveBoxFromGrid(global_box, global_parent); + if (success == TRUE) { + InsertParticlesInLeaf(my_id, global_box->particles, + global_box->num_particles, local_box); + success = InsertBoxInGrid(my_id, local_box, global_parent); + } + } + } } if (success == FALSE) { - if (global_parent == NULL) - global_box = Grid; - else - global_box = global_parent->children[local_box->child_num]; + if (global_parent == NULL) + global_box = Grid; + else + global_box = global_parent->children[local_box->child_num]; } } } @@ -616,32 +615,32 @@ MergeLocalParticles (long my_id, particle **p_array, long num_of_particles, box long i; SplitParticles(p_array, num_of_particles, - (particle **) p_dist, num_p_dist, pb); + (particle **) p_dist, num_p_dist, pb); for (i= 0; i < NUM_OFFSPRING; i++) { if (num_p_dist[i] > 0) { - child = pb->children[i]; - if (child == NULL) { - child = CreateLeaf(my_id, pb, i, p_dist[i], num_p_dist[i]); - success = InsertBoxInGrid(my_id, child, pb); - } - else { - if (child->type == PARENT) { - MergeLocalParticles(my_id, p_dist[i], num_p_dist[i], child); - success = TRUE; - } - else { - success = RemoveBoxFromGrid(child, pb); - if (success == TRUE) { - InsertParticlesInLeaf(my_id, p_dist[i], num_p_dist[i], child); - success = InsertBoxInGrid(my_id, child, pb); - } - else - child = CreateLeaf(my_id, pb, i, p_dist[i], num_p_dist[i]); - } - } - if (success == FALSE) { - MLGHelper(my_id, child, pb->children[child->child_num], pb); - } + child = pb->children[i]; + if (child == NULL) { + child = CreateLeaf(my_id, pb, i, p_dist[i], num_p_dist[i]); + success = InsertBoxInGrid(my_id, child, pb); + } + else { + if (child->type == PARENT) { + MergeLocalParticles(my_id, p_dist[i], num_p_dist[i], child); + success = TRUE; + } + else { + success = RemoveBoxFromGrid(child, pb); + if (success == TRUE) { + InsertParticlesInLeaf(my_id, p_dist[i], num_p_dist[i], child); + success = InsertBoxInGrid(my_id, child, pb); + } + else + child = CreateLeaf(my_id, pb, i, p_dist[i], num_p_dist[i]); + } + } + if (success == FALSE) { + MLGHelper(my_id, child, pb->children[child->child_num], pb); + } } } } @@ -649,7 +648,7 @@ MergeLocalParticles (long my_id, particle **p_array, long num_of_particles, box void SplitParticles (particle **p_array, long length, particle **p_dist, - long num_p_dist[NUM_OFFSPRING], box *pb) + long num_p_dist[NUM_OFFSPRING], box *pb) { particle *p; long i; @@ -659,16 +658,16 @@ SplitParticles (particle **p_array, long length, particle **p_dist, for (i = 0; i < length; i++) { p = p_array[i]; if (p->pos.y > pb->y_center) { - if (p->pos.x > pb->x_center) - *(p_dist + num_p_dist[0]++) = p; - else - *(p_dist + MAX_PARTICLES_PER_BOX + num_p_dist[1]++) = p; + if (p->pos.x > pb->x_center) + *(p_dist + num_p_dist[0]++) = p; + else + *(p_dist + MAX_PARTICLES_PER_BOX + num_p_dist[1]++) = p; } else { - if (p->pos.x > pb->x_center) - *(p_dist + (3 * MAX_PARTICLES_PER_BOX) + num_p_dist[3]++) = p; - else - *(p_dist + (2 * MAX_PARTICLES_PER_BOX) + num_p_dist[2]++) = p; + if (p->pos.x > pb->x_center) + *(p_dist + (3 * MAX_PARTICLES_PER_BOX) + num_p_dist[3]++) = p; + else + *(p_dist + (2 * MAX_PARTICLES_PER_BOX) + num_p_dist[2]++) = p; } } } @@ -685,23 +684,23 @@ CreateLeaf (long my_id, box *pb, long new_child_num, particle **p_array, long le child_offset = pb->length / (real) NUM_OFFSPRING; if (new_child_num == 0) { ret_box = InitBox(my_id, (pb->x_center + child_offset), - (pb->y_center + child_offset), child_length, - pb); + (pb->y_center + child_offset), child_length, + pb); } if (new_child_num == 1) { ret_box = InitBox(my_id, (pb->x_center - child_offset), - (pb->y_center + child_offset), child_length, - pb); + (pb->y_center + child_offset), child_length, + pb); } if (new_child_num == 2) { ret_box = InitBox(my_id, (pb->x_center - child_offset), - (pb->y_center - child_offset), child_length, - pb); + (pb->y_center - child_offset), child_length, + pb); } if (new_child_num == 3) { ret_box = InitBox(my_id, (pb->x_center + child_offset), - (pb->y_center - child_offset), child_length, - pb); + (pb->y_center - child_offset), child_length, + pb); } ret_box->child_num = new_child_num; for (i = 0; i < length; i++) { @@ -720,8 +719,8 @@ InsertParticlesInLeaf (long my_id, particle **p_array, long length, box *b) if ((length + b->num_particles) > MAX_PARTICLES_PER_BOX) { for (i = b->num_particles, j = length - 1; i < MAX_PARTICLES_PER_BOX; - i++, j--) - b->particles[i] = p_array[j]; + i++, j--) + b->particles[i] = p_array[j]; b->num_particles = MAX_PARTICLES_PER_BOX; length = j + 1; InsertParticlesInTree(my_id, p_array, length, b); @@ -729,7 +728,7 @@ InsertParticlesInLeaf (long my_id, particle **p_array, long length, box *b) else { offset = b->num_particles; for (i = 0; i < length; i++) - b->particles[i + offset] = p_array[i]; + b->particles[i + offset] = p_array[i]; b->num_particles += length; } } @@ -743,23 +742,23 @@ InsertBoxInGrid (long my_id, box *b, box *pb) if (pb == NULL) { LOCK(G_Memory->single_lock); if (Grid == NULL) { - Grid = b; - success = TRUE; + Grid = b; + success = TRUE; } else - success = FALSE; + success = FALSE; UNLOCK(G_Memory->single_lock); } else { ALOCK(G_Memory->lock_array, pb->particle_lock_index); if (pb->children[b->child_num] == NULL) { - pb->children[b->child_num] = b; - pb->num_children += 1; - b->parent = pb; - success = TRUE; + pb->children[b->child_num] = b; + pb->num_children += 1; + b->parent = pb; + success = TRUE; } else - success = FALSE; + success = FALSE; AULOCK(G_Memory->lock_array, pb->particle_lock_index); } if (success == TRUE) @@ -776,23 +775,23 @@ RemoveBoxFromGrid (box *b, box *pb) if (pb == NULL) { LOCK(G_Memory->single_lock); if (Grid == b) { - Grid = NULL; - success = TRUE; + Grid = NULL; + success = TRUE; } else - success = FALSE; + success = FALSE; UNLOCK(G_Memory->single_lock); } else { ALOCK(G_Memory->lock_array, pb->particle_lock_index); if (pb->children[b->child_num] == b) { - pb->children[b->child_num] = NULL; - b->parent = NULL; - pb->num_children -= 1; - success = TRUE; + pb->children[b->child_num] = NULL; + b->parent = NULL; + pb->num_children -= 1; + success = TRUE; } else - success = FALSE; + success = FALSE; AULOCK(G_Memory->lock_array, pb->particle_lock_index); } return success; @@ -810,11 +809,11 @@ InsertSubtreeInPartition (long my_id, box *b) } if (b->type == PARENT) { for (i = 0; i < NUM_OFFSPRING; i++) { - child = b->children[i]; - if (child == NULL) - child = b->shadow[i]; - if (child != NULL) - InsertSubtreeInPartition(my_id, child); + child = b->children[i]; + if (child == NULL) + child = b->shadow[i]; + if (child != NULL) + InsertSubtreeInPartition(my_id, child); } } } @@ -828,21 +827,21 @@ CleanupGrid (long my_id) b_scan = Local[my_id].Childless_Partition; while (b_scan != NULL) { if (((b_scan->parent != NULL) || (b_scan == Grid)) - && (b_scan->type == CHILDLESS)) - b_scan = b_scan->next; + && (b_scan->type == CHILDLESS)) + b_scan = b_scan->next; else { - tb = b_scan; - b_scan = b_scan->next; - if (tb->type == PARENT) { - tb->type = CHILDLESS; - RemoveBoxFromPartition(my_id, tb); - tb->type = PARENT; - if ((tb->parent != NULL) || (tb == Grid)) { - InsertBoxInPartition(my_id, tb); - } - } - else - RemoveBoxFromPartition(my_id, tb); + tb = b_scan; + b_scan = b_scan->next; + if (tb->type == PARENT) { + tb->type = CHILDLESS; + RemoveBoxFromPartition(my_id, tb); + tb->type = PARENT; + if ((tb->parent != NULL) || (tb == Grid)) { + InsertBoxInPartition(my_id, tb); + } + } + else + RemoveBoxFromPartition(my_id, tb); } } } @@ -866,9 +865,9 @@ SetSiblings (box *b) pb = b->parent; if (pb != NULL) { for (i = 0; i < NUM_OFFSPRING; i++) { - sb = pb->children[i]; - if ((sb != NULL) && (sb != b)) - b->siblings[b->num_siblings++] = sb; + sb = pb->children[i]; + if ((sb != NULL) && (sb != b)) + b->siblings[b->num_siblings++] = sb; } } } @@ -884,27 +883,27 @@ SetColleagues (long my_id, box *b) pb = b->parent; if (pb != NULL) { for (i = 0; i < b->num_siblings; i++) - b->colleagues[b->num_colleagues++] = b->siblings[i]; + b->colleagues[b->num_colleagues++] = b->siblings[i]; while (b->construct_synch == 0) { - /* wait */; + /* wait */; } b->construct_synch = 0; for (i = 0; i < pb->num_colleagues; i++) { - cb = pb->colleagues[i]; - for (j = 0; j < NUM_OFFSPRING; j++) { - cousin = cb->children[j]; - if (cousin != NULL) { - if (AdjacentBoxes(b, cousin) == TRUE) - b->colleagues[b->num_colleagues++] = cousin; - } - } + cb = pb->colleagues[i]; + for (j = 0; j < NUM_OFFSPRING; j++) { + cousin = cb->children[j]; + if (cousin != NULL) { + if (AdjacentBoxes(b, cousin) == TRUE) + b->colleagues[b->num_colleagues++] = cousin; + } + } } } if (b->type == PARENT) { for (i = 0; i < NUM_OFFSPRING; i++) { - if (b->children[i] != NULL) { - b->children[i]->construct_synch = 1; - } + if (b->children[i] != NULL) { + b->children[i]->construct_synch = 1; + } } } } @@ -944,14 +943,14 @@ SetVList (long my_id, box *b) pb = b->parent; if (pb != NULL) { for (i = 0; i < pb->num_colleagues; i++) { - cb = pb->colleagues[i]; - for (j = 0; j < NUM_OFFSPRING; j++) { - cousin = cb->children[j]; - if (cousin != NULL) { - if (WellSeparatedBoxes(b, cousin) == TRUE) - b->v_list[b->num_v_list++] = cousin; - } - } + cb = pb->colleagues[i]; + for (j = 0; j < NUM_OFFSPRING; j++) { + cousin = cb->children[j]; + if (cousin != NULL) { + if (WellSeparatedBoxes(b, cousin) == TRUE) + b->v_list[b->num_v_list++] = cousin; + } + } } } } @@ -999,16 +998,16 @@ SetUListHelper (long my_id, box *b, box *pb) for (i = 0; i < NUM_OFFSPRING; i++) { child = pb->children[i]; if (child != NULL) { - if (AdjacentBoxes(b, child) == TRUE) { - if (child->type == CHILDLESS) - b->u_list[b->num_u_list++] = child; - else - SetUListHelper(my_id, b, child); - } - else { - if (AncestorBox(b, child) == TRUE) - SetUListHelper(my_id, b, child); - } + if (AdjacentBoxes(b, child) == TRUE) { + if (child->type == CHILDLESS) + b->u_list[b->num_u_list++] = child; + else + SetUListHelper(my_id, b, child); + } + else { + if (AncestorBox(b, child) == TRUE) + SetUListHelper(my_id, b, child); + } } } @@ -1042,8 +1041,8 @@ AncestorBox (box *b, box *ancestor_box) x_center_distance = fabs((double)(b->x_center - ancestor_box->x_center)); y_center_distance = fabs((double)(b->y_center - ancestor_box->y_center)); if ((x_center_distance > (ancestor_box->length / 2.0)) || - (y_center_distance > (ancestor_box->length / 2.0))) - ret_val = FALSE; + (y_center_distance > (ancestor_box->length / 2.0))) + ret_val = FALSE; } else ret_val = FALSE; @@ -1077,7 +1076,7 @@ SetWList (long my_id, box *b) for (i = 0; i < b->num_colleagues; i++) { co_search = b->colleagues[i]; if (co_search->type == PARENT) - InsertNonAdjChildren(my_id, b, co_search); + InsertNonAdjChildren(my_id, b, co_search); } } @@ -1106,12 +1105,12 @@ InsertNonAdjChildren (long my_id, box *b, box *pb) for (i = 0; i < pb->num_children; i++) { child = pb->children[i]; if (child != NULL) { - if (AdjacentBoxes(b, child) == TRUE) { - if (child->type == PARENT) - InsertNonAdjChildren(my_id, b, child); - } - else - b->w_list[b->num_w_list++] = child; + if (AdjacentBoxes(b, child) == TRUE) { + if (child->type == PARENT) + InsertNonAdjChildren(my_id, b, child); + } + else + b->w_list[b->num_w_list++] = child; } } diff --git a/splash2/codes/apps/fmm/cost_zones.C b/splash2/codes/apps/fmm/cost_zones.C index 5ff5fe2e2..b07901971 100644 --- a/splash2/codes/apps/fmm/cost_zones.C +++ b/splash2/codes/apps/fmm/cost_zones.C @@ -14,11 +14,11 @@ /* */ /*************************************************************************/ -#include "box.h" -#include "cost_zones.h" #include "defs.h" #include "memory.h" +#include "box.h" #include "partition_grid.h" +#include "cost_zones.h" #define NUM_DIRECTIONS 4 @@ -50,13 +50,13 @@ CostZones (long my_id) BARRIER(G_Memory->synch, Number_Of_Processors); Local[my_id].Total_Work = Grid->subtree_cost; Local[my_id].Min_Work = ((Local[my_id].Total_Work / Number_Of_Processors) - * my_id); + * my_id); if (my_id == (Number_Of_Processors - 1)) Local[my_id].Max_Work = Local[my_id].Total_Work; else Local[my_id].Max_Work = (Local[my_id].Min_Work - + (Local[my_id].Total_Work - / Number_Of_Processors)); + + (Local[my_id].Total_Work + / Number_Of_Processors)); InitPartition(my_id); CostZonesHelper(my_id, Grid, 0, RIGHT); BARRIER(G_Memory->synch, Number_Of_Processors); @@ -95,25 +95,25 @@ CostZonesHelper (long my_id, box *b, long work, direction dir) if (b->type == CHILDLESS) { if (work >= Local[my_id].Min_Work) - InsertBoxInPartition(my_id, b); + InsertBoxInPartition(my_id, b); } else { next_child = Child_Sequence[dir]; child_dir = Direction_Sequence[dir]; for (i = 0; (i < NUM_OFFSPRING) && (work < Local[my_id].Max_Work); - i++) { - cb = b->children[next_child[i]]; - if (cb != NULL) { - if ((work + cb->subtree_cost) >= Local[my_id].Min_Work) - CostZonesHelper(my_id, cb, work, child_dir[i]); - work += cb->subtree_cost; - } - if (i == 2) { - if ((work >= Local[my_id].Min_Work) - && (work < Local[my_id].Max_Work)) - InsertBoxInPartition(my_id, b); - work += b->cost; - } + i++) { + cb = b->children[next_child[i]]; + if (cb != NULL) { + if ((work + cb->subtree_cost) >= Local[my_id].Min_Work) + CostZonesHelper(my_id, cb, work, child_dir[i]); + work += cb->subtree_cost; + } + if (i == 2) { + if ((work >= Local[my_id].Min_Work) + && (work < Local[my_id].Max_Work)) + InsertBoxInPartition(my_id, b); + work += b->cost; + } } } diff --git a/splash2/codes/apps/fmm/defs.C b/splash2/codes/apps/fmm/defs.C index afd79d19c..cd54c07d2 100644 --- a/splash2/codes/apps/fmm/defs.C +++ b/splash2/codes/apps/fmm/defs.C @@ -14,10 +14,9 @@ /* */ /*************************************************************************/ -#include -#include -#include - +#include +#include +#include #include "defs.h" #include "memory.h" diff --git a/splash2/codes/apps/fmm/defs.H b/splash2/codes/apps/fmm/defs.H index 77911a455..58094a02d 100644 --- a/splash2/codes/apps/fmm/defs.H +++ b/splash2/codes/apps/fmm/defs.H @@ -17,11 +17,11 @@ #ifndef _Defs_H #define _Defs_H 1 -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /* Define booleans */ #ifdef TRUE diff --git a/splash2/codes/apps/fmm/fmm.C b/splash2/codes/apps/fmm/fmm.C index 0b8f82cdb..d10367a99 100644 --- a/splash2/codes/apps/fmm/fmm.C +++ b/splash2/codes/apps/fmm/fmm.C @@ -66,20 +66,19 @@ */ -#include -#include -#include -#include -#include - -#include "box.h" -#include "construct_grid.h" -#include "cost_zones.h" +#include +#include +#include +#include +#include #include "defs.h" -#include "interactions.h" #include "memory.h" #include "particle.h" +#include "box.h" #include "partition_grid.h" +#include "cost_zones.h" +#include "construct_grid.h" +#include "interactions.h" #define BASE ((((double) 4) - sqrt((double) 2)) / sqrt((double) 2)) #define MAX_LINE_SIZE 100 @@ -189,7 +188,7 @@ ParallelExecute () } else { CreateParticleList(my_id, ((Total_Particles * PDF) - / Number_Of_Processors)); + / Number_Of_Processors)); InitParticleList(my_id, 0, 0); } num_boxes = 1.333 * (Total_Particles / (OCCUPANCY * MAX_PARTICLES_PER_BOX)); @@ -200,7 +199,7 @@ ParallelExecute () if (my_id == 0) { LockedPrint("Starting FMM with %d processor%s\n", Number_Of_Processors, - (Number_Of_Processors == 1) ? "" : "s"); + (Number_Of_Processors == 1) ? "" : "s"); } BARRIER(G_Memory->synch, Number_Of_Processors); Local[my_id].Time = 0.0; @@ -218,10 +217,10 @@ ParallelExecute () } if (MY_TIME_STEP == 0) { - CLOCK(start); + CLOCK(start); } else - start = finish; + start = finish; ConstructGrid(my_id,local_time,time_all); ConstructLists(my_id,local_time,time_all); PartitionGrid(my_id,local_time,time_all); @@ -316,12 +315,12 @@ GetArguments () Cluster = ONE_CLUSTER; else { if ((*input == '\0') || (strcmp(input, "two cluster") == 0)) - Cluster = TWO_CLUSTER; + Cluster = TWO_CLUSTER; else { - fprintf(stderr, "ERROR: The only cluster types available are "); - fprintf(stderr, "\"one cluster\" or \"two cluster\".\n"); - fprintf(stderr, "If you need help, type \"nbody -help\".\n"); - exit(-1); + fprintf(stderr, "ERROR: The only cluster types available are "); + fprintf(stderr, "\"one cluster\" or \"two cluster\".\n"); + fprintf(stderr, "If you need help, type \"nbody -help\".\n"); + exit(-1); } } @@ -330,12 +329,12 @@ GetArguments () Model = UNIFORM; else { if ((*input == '\0') || (strcmp(input, "plummer") == 0)) - Model = PLUMMER; + Model = PLUMMER; else { - fprintf(stderr, "ERROR: The only distributions available are "); - fprintf(stderr, "\"uniform\" or \"plummer\".\n"); - fprintf(stderr, "If you need help, type \"nbody -help\".\n"); - exit(-1); + fprintf(stderr, "ERROR: The only distributions available are "); + fprintf(stderr, "\"uniform\" or \"plummer\".\n"); + fprintf(stderr, "If you need help, type \"nbody -help\".\n"); + exit(-1); } } @@ -416,12 +415,12 @@ GetArguments () Partition_Flag = COST_ZONES; else { if (strcmp(input, "orb") == 0) - Partition_Flag = ORB; + Partition_Flag = ORB; else { - fprintf(stderr, "ERROR: The only partitioning schemes available "); - fprintf(stderr, "are \"cost zones\" \n\t or \"orb\".\n"); - fprintf(stderr, "If you need help, type \"nbody -help\".\n"); - exit(-1); + fprintf(stderr, "ERROR: The only partitioning schemes available "); + fprintf(stderr, "are \"cost zones\" \n\t or \"orb\".\n"); + fprintf(stderr, "If you need help, type \"nbody -help\".\n"); + exit(-1); } } } @@ -465,21 +464,21 @@ PrintTimes () for (i = 0; i < Time_Steps; i++) { fprintf(fp, "Time Step %ld\n", i); for (j = 0; j < Number_Of_Processors; j++) { - timing = &(Local[j].Timing[i]); - fprintf(fp, "Processor %ld\n", j); - fprintf(fp, "\tTotal Time = %lu\n", timing->total_time); - if (do_stats) { - fprintf(fp, "\tTree Construction Time = %lu\n", - timing->construct_time); - fprintf(fp, "\tList Construction Time = %lu\n", timing->list_time); - fprintf(fp, "\tPartition Time = %lu\n", timing->partition_time); - fprintf(fp, "\tTree Pass Time = %lu\n", timing->pass_time); - fprintf(fp, "\tInter Particle Time = %lu\n", timing->inter_time); - fprintf(fp, "\tBarrier Time = %lu\n", timing->barrier_time); - fprintf(fp, "\tIntra Particle Time = %lu\n", timing->intra_time); - fprintf(fp, "\tOther Time = %lu\n", timing->other_time); - } - fflush(fp); + timing = &(Local[j].Timing[i]); + fprintf(fp, "Processor %ld\n", j); + fprintf(fp, "\tTotal Time = %lu\n", timing->total_time); + if (do_stats) { + fprintf(fp, "\tTree Construction Time = %lu\n", + timing->construct_time); + fprintf(fp, "\tList Construction Time = %lu\n", timing->list_time); + fprintf(fp, "\tPartition Time = %lu\n", timing->partition_time); + fprintf(fp, "\tTree Pass Time = %lu\n", timing->pass_time); + fprintf(fp, "\tInter Particle Time = %lu\n", timing->inter_time); + fprintf(fp, "\tBarrier Time = %lu\n", timing->barrier_time); + fprintf(fp, "\tIntra Particle Time = %lu\n", timing->intra_time); + fprintf(fp, "\tOther Time = %lu\n", timing->other_time); + } + fflush(fp); } } fprintf(fp, "END\n"); @@ -554,8 +553,8 @@ PrintTimes () P = Number_Of_Processors; printf(" Avg %12.0f%12.0f%12.0f%12.0f%12.0f%12.0f%12.0f%12.0f%12.0f\n", t_total_time/P,t_tree_time/P,t_list_time/P,t_part_time/P, - t_pass_time/P,t_inter_time/P,t_bar_time/P,t_intra_time/P, - t_other_time/P); + t_pass_time/P,t_inter_time/P,t_bar_time/P,t_intra_time/P, + t_other_time/P); } printf("\n"); if (Time_Steps > 2) { diff --git a/splash2/codes/apps/fmm/interactions.C b/splash2/codes/apps/fmm/interactions.C index 08c98e64b..813a075d1 100644 --- a/splash2/codes/apps/fmm/interactions.C +++ b/splash2/codes/apps/fmm/interactions.C @@ -14,15 +14,14 @@ /* */ /*************************************************************************/ -#include -#include - -#include "box.h" +#include +#include #include "defs.h" -#include "interactions.h" #include "memory.h" #include "particle.h" +#include "box.h" #include "partition_grid.h" +#include "interactions.h" static real Inv[MAX_EXPANSION_TERMS + 1]; static real OverInc[MAX_EXPANSION_TERMS + 1]; @@ -59,7 +58,7 @@ InitExpTables () C[i][1] = (real) i; C[i - 1][i] = (real) 0.0; for (j = 2; j <= i; j++) - C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; + C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; } One.r = (real) 1.0; @@ -83,7 +82,7 @@ PrintExpTables () printf("i\tj\th(i,j)\n"); for (i = 0; i < (2 * MAX_EXPANSION_TERMS); i++) { for (j = 0; j <= i; j++) - printf("%ld\t%ld\t%g\n", i, j, C[i][j]); + printf("%ld\t%ld\t%g\n", i, j, C[i][j]); printf("\n"); } } @@ -101,7 +100,7 @@ UpwardPass (long my_id, box *b) } else { while (b->interaction_synch != b->num_children) { - /* wait */; + /* wait */; } } if (b->parent != NULL) { @@ -131,7 +130,7 @@ DownwardPass (long my_id, box *b) { if (b->parent != NULL) { while (b->parent->interaction_synch != 0) { - /* wait */; + /* wait */; } ShiftLocalExp(b->parent, b); } @@ -165,9 +164,9 @@ ComputeParticlePositions (long my_id, box *b) force.y = p->field.i * p->charge; VECTOR_DIV(new_acc, force, p->mass); if (Local[my_id].Time_Step != 0) { - VECTOR_SUB(delta_acc, new_acc, (p->acc)); - VECTOR_MUL(delta_vel, delta_acc, ((real) Timestep_Dur) / (real) 2.0); - VECTOR_ADD((p->vel), (p->vel), delta_vel); + VECTOR_SUB(delta_acc, new_acc, (p->acc)); + VECTOR_MUL(delta_vel, delta_acc, ((real) Timestep_Dur) / (real) 2.0); + VECTOR_ADD((p->vel), (p->vel), delta_vel); } p->acc.x = new_acc.x; p->acc.y = new_acc.y; @@ -242,9 +241,9 @@ ComputeMPExp (box *b) z0_pow_n.r = One.r; z0_pow_n.i = One.i; for (j = 1; j < Expansion_Terms; j++) { - COMPLEX_MUL(temp, z0_pow_n, charge); - COMPLEX_ADD(result_exp[j], result_exp[j], temp); - COMPLEX_MUL(z0_pow_n, z0_pow_n, z0); + COMPLEX_MUL(temp, z0_pow_n, charge); + COMPLEX_ADD(result_exp[j], result_exp[j], temp); + COMPLEX_MUL(z0_pow_n, z0_pow_n, z0); } } ALOCK(G_Memory->lock_array, b->exp_lock_index); @@ -289,10 +288,10 @@ ShiftMPExp (box *cb, box *pb) COMPLEX_MUL(z0_pow_minus_n, z0_pow_minus_n, z0_inv); COMPLEX_MUL(temp_exp[i], z0_pow_minus_n, cb->mp_expansion[i]); for (j = 1; j <= i; j++) { - temp.r = C[i - 1][j - 1]; - temp.i = (real) 0.0; - COMPLEX_MUL(temp, temp, temp_exp[j]); - COMPLEX_ADD(result_exp[i], result_exp[i], temp); + temp.r = C[i - 1][j - 1]; + temp.i = (real) 0.0; + COMPLEX_MUL(temp, temp, temp_exp[j]); + COMPLEX_ADD(result_exp[i], result_exp[i], temp); } temp.r = Inv[i]; temp.i = (real) 0.0; @@ -330,23 +329,23 @@ UListInteraction (long my_id, box *source_box, box *dest_box) dest_x = dest_box->particles[i]->pos.x; dest_y = dest_box->particles[i]->pos.y; for (j = 0; j < source_box->num_particles; j++) { - x_sep = source_box->particles[j]->pos.x - dest_x; - y_sep = source_box->particles[j]->pos.y - dest_y; - denom = ((real) 1.0) / ((x_sep * x_sep) + (y_sep * y_sep)); - temp_vector.r = x_sep * denom; - temp_vector.i = y_sep * denom; - temp_charge.r = source_box->particles[j]->charge; - temp_charge.i = (real) 0.0; - COMPLEX_MUL(temp_result, temp_vector, temp_charge); - COMPLEX_SUB(result, result, temp_result); + x_sep = source_box->particles[j]->pos.x - dest_x; + y_sep = source_box->particles[j]->pos.y - dest_y; + denom = ((real) 1.0) / ((x_sep * x_sep) + (y_sep * y_sep)); + temp_vector.r = x_sep * denom; + temp_vector.i = y_sep * denom; + temp_charge.r = source_box->particles[j]->charge; + temp_charge.i = (real) 0.0; + COMPLEX_MUL(temp_result, temp_vector, temp_charge); + COMPLEX_SUB(result, result, temp_result); } result.i = -result.i; COMPLEX_ADD((dest_box->particles[i]->field), - (dest_box->particles[i]->field), result); + (dest_box->particles[i]->field), result); } dest_box->cost += U_LIST_COST(source_box->num_particles, - dest_box->num_particles); + dest_box->num_particles); } @@ -366,12 +365,12 @@ VListInteraction (long my_id, box *source_box, box *dest_box) if (source_box->type == CHILDLESS) { while (source_box->interaction_synch != 1) { - /* wait */; + /* wait */; } } else { while (source_box->interaction_synch != source_box->num_children) { - /* wait */; + /* wait */; } } @@ -393,32 +392,32 @@ VListInteraction (long my_id, box *source_box, box *dest_box) result_exp.r = (real) 0.0; result_exp.i = (real) 0.0; for (j = 1; j < Expansion_Terms; j++) { - temp.r = C[i + j - 1][j - 1]; - temp.i = (real) 0.0; - COMPLEX_MUL(temp, temp, temp_exp[j]); - if ((j & 0x1) == 0x0) { - COMPLEX_ADD(result_exp, result_exp, temp); - } - else { - COMPLEX_SUB(result_exp, result_exp, temp); - } + temp.r = C[i + j - 1][j - 1]; + temp.i = (real) 0.0; + COMPLEX_MUL(temp, temp, temp_exp[j]); + if ((j & 0x1) == 0x0) { + COMPLEX_ADD(result_exp, result_exp, temp); + } + else { + COMPLEX_SUB(result_exp, result_exp, temp); + } } COMPLEX_MUL(result_exp, result_exp, z0_pow_minus_n[i]); if (i == 0) { - temp.r = log(COMPLEX_ABS(z0)); - temp.i = (real) 0.0; - COMPLEX_MUL(temp, temp, source_box->mp_expansion[0]); - COMPLEX_ADD(result_exp, result_exp, temp); + temp.r = log(COMPLEX_ABS(z0)); + temp.i = (real) 0.0; + COMPLEX_MUL(temp, temp, source_box->mp_expansion[0]); + COMPLEX_ADD(result_exp, result_exp, temp); } else { - temp.r = Inv[i]; - temp.i = (real) 0.0; - COMPLEX_MUL(temp, temp, z0_pow_minus_n[i]); - COMPLEX_MUL(temp, temp, source_box->mp_expansion[0]); - COMPLEX_SUB(result_exp, result_exp, temp); + temp.r = Inv[i]; + temp.i = (real) 0.0; + COMPLEX_MUL(temp, temp, z0_pow_minus_n[i]); + COMPLEX_MUL(temp, temp, source_box->mp_expansion[0]); + COMPLEX_SUB(result_exp, result_exp, temp); } COMPLEX_ADD((dest_box->local_expansion[i]), - (dest_box->local_expansion[i]), result_exp); + (dest_box->local_expansion[i]), result_exp); } dest_box->cost += V_LIST_COST(Expansion_Terms); } @@ -445,12 +444,12 @@ WListInteraction (box *source_box, box *dest_box) if (source_box->type == CHILDLESS) { while (source_box->interaction_synch != 1) { - /* wait */; + /* wait */; } } else { while (source_box->interaction_synch != source_box->num_children) { - /* wait */; + /* wait */; } } @@ -464,11 +463,11 @@ WListInteraction (box *source_box, box *dest_box) COMPLEX_SUB(z0, particle_pos, source_pos); COMPLEX_DIV(z0_inv, One, z0); for (j = Expansion_Terms - 1; j > 0; j--) { - COMPLEX_ADD(result, result, (source_box->mp_expansion[j])); - COMPLEX_MUL(result, result, z0_inv); + COMPLEX_ADD(result, result, (source_box->mp_expansion[j])); + COMPLEX_MUL(result, result, z0_inv); } COMPLEX_ADD((dest_box->particles[i]->field), - (dest_box->particles[i]->field), result); + (dest_box->particles[i]->field), result); } dest_box->cost += W_LIST_COST(dest_box->num_particles, Expansion_Terms); @@ -505,15 +504,15 @@ XListInteraction (box *source_box, box *dest_box) z0_pow_minus_n.r = z0_inv.r; z0_pow_minus_n.i = z0_inv.i; for (j = 1; j < Expansion_Terms; j++) { - COMPLEX_MUL(z0_pow_minus_n, z0_pow_minus_n, z0_inv); - COMPLEX_MUL(temp, charge, z0_pow_minus_n); - COMPLEX_ADD(result_exp[j], result_exp[j], temp); + COMPLEX_MUL(z0_pow_minus_n, z0_pow_minus_n, z0_inv); + COMPLEX_MUL(temp, charge, z0_pow_minus_n); + COMPLEX_ADD(result_exp[j], result_exp[j], temp); } } ALOCK(G_Memory->lock_array, dest_box->exp_lock_index); for (i = 0; i < Expansion_Terms; i++) { COMPLEX_SUB((dest_box->x_expansion[i]), - (dest_box->x_expansion[i]), result_exp[i]); + (dest_box->x_expansion[i]), result_exp[i]); } AULOCK(G_Memory->lock_array, dest_box->exp_lock_index); source_box->cost += X_LIST_COST(source_box->num_particles, Expansion_Terms); @@ -540,37 +539,37 @@ ComputeSelfInteraction (box *b) for (i = 0; i < b->num_particles; i++) { for (j = i + 1; j < b->num_particles; j++) { - x_sep = b->particles[i]->pos.x - b->particles[j]->pos.x; - y_sep = b->particles[i]->pos.y - b->particles[j]->pos.y; + x_sep = b->particles[i]->pos.x - b->particles[j]->pos.x; + y_sep = b->particles[i]->pos.y - b->particles[j]->pos.y; - if ((fabs(x_sep) < Softening_Param) - && (fabs(y_sep) < Softening_Param)) { - if (x_sep >= 0.0) - x_sep = Softening_Param; - else - x_sep = -Softening_Param; - if (y_sep >= 0.0) - y_sep = Softening_Param; - else - y_sep = -Softening_Param; - } - denom = ((real) 1.0) / ((x_sep * x_sep) + (y_sep * y_sep)); - temp_vector.r = x_sep * denom; - temp_vector.i = y_sep * denom; + if ((fabs(x_sep) < Softening_Param) + && (fabs(y_sep) < Softening_Param)) { + if (x_sep >= 0.0) + x_sep = Softening_Param; + else + x_sep = -Softening_Param; + if (y_sep >= 0.0) + y_sep = Softening_Param; + else + y_sep = -Softening_Param; + } + denom = ((real) 1.0) / ((x_sep * x_sep) + (y_sep * y_sep)); + temp_vector.r = x_sep * denom; + temp_vector.i = y_sep * denom; - temp_charge.r = b->particles[j]->charge; - temp_charge.i = (real) 0.0; - COMPLEX_MUL(temp_result, temp_vector, temp_charge); - COMPLEX_ADD(results[i], results[i], temp_result); + temp_charge.r = b->particles[j]->charge; + temp_charge.i = (real) 0.0; + COMPLEX_MUL(temp_result, temp_vector, temp_charge); + COMPLEX_ADD(results[i], results[i], temp_result); - temp_charge.r = b->particles[i]->charge; - temp_charge.i = (real) 0.0; - COMPLEX_MUL(temp_result, temp_vector, temp_charge); - COMPLEX_SUB(results[j], results[j], temp_result); + temp_charge.r = b->particles[i]->charge; + temp_charge.i = (real) 0.0; + COMPLEX_MUL(temp_result, temp_vector, temp_charge); + COMPLEX_SUB(results[j], results[j], temp_result); } results[i].i = -results[i].i; COMPLEX_ADD((b->particles[i]->field), - (b->particles[i]->field), results[i]); + (b->particles[i]->field), results[i]); } b->cost += SELF_COST(b->num_particles); @@ -604,7 +603,7 @@ ShiftLocalExp (box *pb, box *cb) z0_pow_minus_n.i = One.i; for (i = 0; i < Expansion_Terms; i++) { COMPLEX_ADD(pb->local_expansion[i], pb->local_expansion[i], - pb->x_expansion[i]); + pb->x_expansion[i]); COMPLEX_MUL(temp_exp[i], z0_pow_n, pb->local_expansion[i]); COMPLEX_MUL(z0_pow_n, z0_pow_n, z0); } @@ -612,10 +611,10 @@ ShiftLocalExp (box *pb, box *cb) result_exp[i].r = (real) 0.0; result_exp[i].i = (real) 0.0; for (j = i; j < Expansion_Terms ; j++) { - temp.r = C[j][i]; - temp.i = (real) 0.0; - COMPLEX_MUL(temp, temp, temp_exp[j]); - COMPLEX_ADD(result_exp[i], result_exp[i], temp); + temp.r = C[j][i]; + temp.i = (real) 0.0; + COMPLEX_MUL(temp, temp, temp_exp[j]); + COMPLEX_ADD(result_exp[i], result_exp[i], temp); } COMPLEX_MUL(result_exp[i], temp, z0_pow_minus_n); COMPLEX_MUL(z0_pow_minus_n, z0_pow_minus_n, z0_inv); @@ -623,7 +622,7 @@ ShiftLocalExp (box *pb, box *cb) ALOCK(G_Memory->lock_array, cb->exp_lock_index); for (i = 0; i < Expansion_Terms; i++) { COMPLEX_ADD((cb->local_expansion[i]), (cb->local_expansion[i]), - result_exp[i]); + result_exp[i]); } AULOCK(G_Memory->lock_array, cb->exp_lock_index); } @@ -649,11 +648,11 @@ EvaluateLocalExp (box *b) particle_pos.i = b->particles[i]->pos.y; COMPLEX_SUB(z0, particle_pos, source_pos); for (j = Expansion_Terms - 1; j > 0; j--) { - temp.r = (real) j; - temp.i = (real) 0.0; - COMPLEX_MUL(result, result, z0); - COMPLEX_MUL(temp, temp, (b->local_expansion[j])); - COMPLEX_ADD(result, result, temp); + temp.r = (real) j; + temp.i = (real) 0.0; + COMPLEX_MUL(result, result, z0); + COMPLEX_MUL(temp, temp, (b->local_expansion[j])); + COMPLEX_ADD(result, result, temp); } COMPLEX_ADD((b->particles[i]->field), (b->particles[i]->field), result); b->particles[i]->field.r = -(b->particles[i]->field.r); diff --git a/splash2/codes/apps/fmm/memory.C b/splash2/codes/apps/fmm/memory.C index ba524757c..47195fc28 100644 --- a/splash2/codes/apps/fmm/memory.C +++ b/splash2/codes/apps/fmm/memory.C @@ -14,8 +14,7 @@ /* */ /*************************************************************************/ -#include - +#include #include "defs.h" #include "memory.h" diff --git a/splash2/codes/apps/fmm/memory.H b/splash2/codes/apps/fmm/memory.H index 7388386c9..711977819 100644 --- a/splash2/codes/apps/fmm/memory.H +++ b/splash2/codes/apps/fmm/memory.H @@ -17,9 +17,9 @@ #ifndef _Memory_H #define _Memory_H 1 -#include "box.h" #include "defs.h" #include "particle.h" +#include "box.h" #define MAX_LOCKS 2048 diff --git a/splash2/codes/apps/fmm/particle.C b/splash2/codes/apps/fmm/particle.C index d0a768cb1..b4b8e7fb4 100644 --- a/splash2/codes/apps/fmm/particle.C +++ b/splash2/codes/apps/fmm/particle.C @@ -14,11 +14,9 @@ /* */ /*************************************************************************/ +#include #include - -#include -#include - +#include #include "defs.h" #include "memory.h" #include "particle.h" @@ -85,26 +83,26 @@ CreateDistribution (cluster_type cluster, model_type model) end_limit = Total_Particles; switch (model) { case UNIFORM: - printf("Creating a one cluster, uniform distribution for %ld ", Total_Particles); - printf("particles\n"); - break; + printf("Creating a one cluster, uniform distribution for %ld ", Total_Particles); + printf("particles\n"); + break; case PLUMMER: - printf("Creating a one cluster, non uniform distribution for %ld ", Total_Particles); - printf("particles\n"); - break; + printf("Creating a one cluster, non uniform distribution for %ld ", Total_Particles); + printf("particles\n"); + break; } break; case TWO_CLUSTER: end_limit = (Total_Particles / 2) + (Total_Particles & 0x1); switch (model) { case UNIFORM: - printf("Creating a two cluster, uniform distribution for %ld ", Total_Particles); - printf("particles\n"); - break; + printf("Creating a two cluster, uniform distribution for %ld ", Total_Particles); + printf("particles\n"); + break; case PLUMMER: - printf("Creating a two cluster, non uniform distribution for %ld ", Total_Particles); - printf("particles\n"); - break; + printf("Creating a two cluster, non uniform distribution for %ld ", Total_Particles); + printf("particles\n"); + break; } break; } @@ -116,27 +114,27 @@ CreateDistribution (cluster_type cluster, model_type model) new_particle = InitParticle(charge, charge); switch (model) { case UNIFORM: - do { - new_particle->pos.x = XRand(-1.0, 1.0); - new_particle->pos.y = XRand(-1.0, 1.0); - temp_r = DOT_PRODUCT((new_particle->pos), (new_particle->pos)); - } - while (temp_r > (real) 1.0); - radius = sqrt(temp_r); - break; + do { + new_particle->pos.x = XRand(-1.0, 1.0); + new_particle->pos.y = XRand(-1.0, 1.0); + temp_r = DOT_PRODUCT((new_particle->pos), (new_particle->pos)); + } + while (temp_r > (real) 1.0); + radius = sqrt(temp_r); + break; case PLUMMER: - do - radius = (real) 1.0 / (real) sqrt(pow(XRand(0.0, MAX_FRAC), - -2.0/3.0) - 1); - while (radius > 9.0); - PickShell(&(new_particle->pos), r_scale * radius); - break; + do + radius = (real) 1.0 / (real) sqrt(pow(XRand(0.0, MAX_FRAC), + -2.0/3.0) - 1); + while (radius > 9.0); + PickShell(&(new_particle->pos), r_scale * radius); + break; } VECTOR_ADD(r_sum, r_sum, (new_particle->pos)); do { - x_vel = XRand(0.0, 1.0); - y_vel = XRand(0.0, 0.1); + x_vel = XRand(0.0, 1.0); + y_vel = XRand(0.0, 0.1); } while (y_vel > x_vel * x_vel * (real) pow(1.0 - (x_vel * x_vel), 3.5)); vel = (real) sqrt(2.0) * x_vel / pow(1.0 + (radius * radius), 0.25); @@ -147,21 +145,21 @@ CreateDistribution (cluster_type cluster, model_type model) if (cluster == TWO_CLUSTER) { switch (model) { case UNIFORM: - offset = 1.5; - break; + offset = 1.5; + break; case PLUMMER: - offset = 2.0; - break; + offset = 2.0; + break; } for (i = end_limit; i < Total_Particles; i++) { - new_particle = InitParticle(charge, charge); - twin_particle = Particle_List[i - end_limit]; - new_particle->pos.x = twin_particle->pos.x + offset; - new_particle->pos.y = twin_particle->pos.y + offset; - VECTOR_ADD(r_sum, r_sum, (new_particle->pos)); - new_particle->vel.x = twin_particle->vel.x; - new_particle->vel.y = twin_particle->vel.y; - VECTOR_ADD(v_sum, v_sum, (new_particle->vel)); + new_particle = InitParticle(charge, charge); + twin_particle = Particle_List[i - end_limit]; + new_particle->pos.x = twin_particle->pos.x + offset; + new_particle->pos.y = twin_particle->pos.y + offset; + VECTOR_ADD(r_sum, r_sum, (new_particle->pos)); + new_particle->vel.x = twin_particle->vel.x; + new_particle->vel.y = twin_particle->vel.y; + VECTOR_ADD(v_sum, v_sum, (new_particle->vel)); } } @@ -180,7 +178,7 @@ CreateParticleList (long my_id, long length) { LOCK(G_Memory->mal_lock); Local[my_id].Particles = (particle **) G_MALLOC(length - * sizeof(particle *)); + * sizeof(particle *)); /* POSSIBLE ENHANCEMENT: Here is where one might distribute the Particles data across physically distributed memories as desired. @@ -192,7 +190,7 @@ CreateParticleList (long my_id, long length) starting_address = (char *) Local[my_id].Particles; ending_address = (((char *) Local[my_id].Particles) - + (length * sizeof(particle *)) - 1); + + (length * sizeof(particle *)) - 1); Place all addresses x such that (starting_address <= x < ending_address) on node my_id @@ -263,12 +261,12 @@ PrintParticleArrayIds (particle **p_array, long num_particles) printf("NONE\n"); else { for (i = 0; i < num_particles; i++) { - if (tab_count == 0) { - tab_count = PARTICLES_PER_LINE; - printf("\n"); - } - printf("\tP%ld", p_array[i]->id); - tab_count -= 1; + if (tab_count == 0) { + tab_count = PARTICLES_PER_LINE; + printf("\n"); + } + printf("\tP%ld", p_array[i]->id); + tab_count -= 1; } printf("\n"); } diff --git a/splash2/codes/apps/fmm/partition_grid.C b/splash2/codes/apps/fmm/partition_grid.C index 37ec22a25..ab8b43d75 100644 --- a/splash2/codes/apps/fmm/partition_grid.C +++ b/splash2/codes/apps/fmm/partition_grid.C @@ -14,13 +14,12 @@ /* */ /*************************************************************************/ -#include -#include - -#include "box.h" +#include +#include #include "defs.h" #include "memory.h" #include "particle.h" +#include "box.h" #include "partition_grid.h" #define DIVISOR(x) ((x <= 20) ? 1 : ((x - 20) * 50)) @@ -56,7 +55,7 @@ InitPartition (long my_id) void PartitionIterate (long my_id, partition_function function, - partition_start position) + partition_start position) { box *b; long i; @@ -64,38 +63,38 @@ PartitionIterate (long my_id, partition_function function, if (position == CHILDREN) { b = Local[my_id].Childless_Partition; while (b != NULL) { - (*function)(my_id, b); - b = b->next; + (*function)(my_id, b); + b = b->next; } } else { if (position == TOP) { - for (i = 0; i <= Local[my_id].Max_Parent_Level; i++) { - b = Local[my_id].Parent_Partition[i]; - while (b != NULL) { - (*function)(my_id, b); - b = b->next; - } - } - b = Local[my_id].Childless_Partition; - while (b != NULL) { - (*function)(my_id, b); - b = b->next; - } + for (i = 0; i <= Local[my_id].Max_Parent_Level; i++) { + b = Local[my_id].Parent_Partition[i]; + while (b != NULL) { + (*function)(my_id, b); + b = b->next; + } + } + b = Local[my_id].Childless_Partition; + while (b != NULL) { + (*function)(my_id, b); + b = b->next; + } } else { - b = Local[my_id].Childless_Partition; - while (b != NULL) { - (*function)(my_id, b); - b = b->next; - } - for (i = Local[my_id].Max_Parent_Level; i >= 0; i--) { - b = Local[my_id].Parent_Partition[i]; - while (b != NULL) { - (*function)(my_id, b); - b = b->next; - } - } + b = Local[my_id].Childless_Partition; + while (b != NULL) { + (*function)(my_id, b); + b = b->next; + } + for (i = Local[my_id].Max_Parent_Level; i >= 0; i--) { + b = Local[my_id].Parent_Partition[i]; + while (b != NULL) { + (*function)(my_id, b); + b = b->next; + } + } } } } @@ -109,7 +108,7 @@ InsertBoxInPartition (long my_id, box *b) if (b->type == CHILDLESS) { b->prev = NULL; if (Local[my_id].Childless_Partition != NULL) - Local[my_id].Childless_Partition->prev = b; + Local[my_id].Childless_Partition->prev = b; b->next = Local[my_id].Childless_Partition; Local[my_id].Childless_Partition = b; } @@ -117,11 +116,11 @@ InsertBoxInPartition (long my_id, box *b) level_list = Local[my_id].Parent_Partition[b->level]; b->prev = NULL; if (level_list != NULL) - level_list->prev = b; + level_list->prev = b; b->next = level_list; Local[my_id].Parent_Partition[b->level] = b; if (b->level > Local[my_id].Max_Parent_Level) { - Local[my_id].Max_Parent_Level = b->level; + Local[my_id].Max_Parent_Level = b->level; } } } @@ -132,24 +131,24 @@ RemoveBoxFromPartition (long my_id, box *b) { if (b->type == CHILDLESS) { if (b->prev != NULL) - b->prev->next = b->next; + b->prev->next = b->next; else - Local[my_id].Childless_Partition = b->next; + Local[my_id].Childless_Partition = b->next; if (b->next != NULL) - b->next->prev = b->prev; + b->next->prev = b->prev; } else { if (b->prev != NULL) - b->prev->next = b->next; + b->prev->next = b->next; else - Local[my_id].Parent_Partition[b->level] = b->next; + Local[my_id].Parent_Partition[b->level] = b->next; if (b->next != NULL) - b->next->prev = b->prev; + b->next->prev = b->prev; if ((b->level == Local[my_id].Max_Parent_Level) && - (Local[my_id].Parent_Partition[b->level] == NULL)) { - while (Local[my_id].Parent_Partition[Local[my_id].Max_Parent_Level] - == NULL) - Local[my_id].Max_Parent_Level -= 1; + (Local[my_id].Parent_Partition[b->level] == NULL)) { + while (Local[my_id].Parent_Partition[Local[my_id].Max_Parent_Level] + == NULL) + Local[my_id].Max_Parent_Level -= 1; } } } @@ -169,22 +168,22 @@ ComputeCostOfBox (box *b) if (b->type == PARENT) b->cost = ((b->num_v_list * V_LIST_COST(Expansion_Terms)) - / DIVISOR(Expansion_Terms)) + 1; + / DIVISOR(Expansion_Terms)) + 1; else { different_costs = 0; for (i = 0; i < b->num_particles; i++) { - new_cost = b->particles[i]->cost; - for (j = 0; j < different_costs; j++) { - if (new_cost == cost_list[j].cost) - break; - } - if (j == different_costs) { - cost_list[different_costs].cost = new_cost; - cost_list[different_costs].num = 1; - different_costs += 1; - } - else - cost_list[j].num += 1; + new_cost = b->particles[i]->cost; + for (j = 0; j < different_costs; j++) { + if (new_cost == cost_list[j].cost) + break; + } + if (j == different_costs) { + cost_list[different_costs].cost = new_cost; + cost_list[different_costs].num = 1; + different_costs += 1; + } + else + cost_list[j].num += 1; } winner.cost = cost_list[0].cost; @@ -192,27 +191,27 @@ ComputeCostOfBox (box *b) winner_index = 0; cost_index[0] = 0; for (i = 1; i < different_costs; i++) { - if (cost_list[i].num > cost_list[winner_index].num) { - winner.cost = cost_list[i].cost; - winner.num = 1; - winner_index = i; - cost_index[0] = i; - } - else { - if (cost_list[i].num == cost_list[winner_index].num) { - cost_index[winner.num] = i; - winner.num += 1; - } - } + if (cost_list[i].num > cost_list[winner_index].num) { + winner.cost = cost_list[i].cost; + winner.num = 1; + winner_index = i; + cost_index[0] = i; + } + else { + if (cost_list[i].num == cost_list[winner_index].num) { + cost_index[winner.num] = i; + winner.num += 1; + } + } } if (winner.num != 1) { - for (i = 1; i < winner.num; i++) - winner.cost += cost_list[cost_index[i]].cost; - winner.cost /= winner.num; + for (i = 1; i < winner.num; i++) + winner.cost += cost_list[cost_index[i]].cost; + winner.cost /= winner.num; } b->cost = (winner.cost * b->num_particles) / DIVISOR(Expansion_Terms); if (b->cost == 0) - b->cost = 1; + b->cost = 1; } } @@ -231,30 +230,30 @@ CheckPartition (long my_id) for (i = 0; i <= Local[my_id].Max_Parent_Level; i++) { b = Local[my_id].Parent_Partition[i]; while (b != NULL) { - NE += CheckBox(my_id, b, i); - PB += 1; - PC += b->cost; - b = b->next; + NE += CheckBox(my_id, b, i); + PB += 1; + PC += b->cost; + b = b->next; } } b = Local[my_id].Childless_Partition; while (b != NULL) { NE += CheckBox(my_id, b, -1); for (i = 0; i < b->num_particles; i++) { - xpos = b->particles[i]->pos.x; - ypos = b->particles[i]->pos.y; - if (xpos > Grid->x_center) { - if (ypos > Grid->y_center) - Q1 += 1; - else - Q4 += 1; - } - else { - if (ypos > Grid->y_center) - Q2 += 1; - else - Q3 += 1; - } + xpos = b->particles[i]->pos.x; + ypos = b->particles[i]->pos.y; + if (xpos > Grid->x_center) { + if (ypos > Grid->y_center) + Q1 += 1; + else + Q4 += 1; + } + else { + if (ypos > Grid->y_center) + Q2 += 1; + else + Q3 += 1; + } } NoP += b->num_particles; CB += 1; @@ -272,99 +271,99 @@ CheckBox (long my_id, box *b, long partition_level) num_errors = 0; if (b->type == CHILDLESS) { if (partition_level != -1) { - LOCK(G_Memory->io_lock); - printf("ERROR : CHILDLESS box in parent partition (B%f P%ld %ld)\n", b->id, my_id, b->proc); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + printf("ERROR : CHILDLESS box in parent partition (B%f P%ld %ld)\n", b->id, my_id, b->proc); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } if (b->num_children != 0) { - LOCK(G_Memory->io_lock); - printf("ERROR : CHILDLESS box has children (B%f P%ld)\n", b->id, my_id); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + printf("ERROR : CHILDLESS box has children (B%f P%ld)\n", b->id, my_id); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } if (b->num_particles == 0) { - LOCK(G_Memory->io_lock); - printf("ERROR : CHILDLESS box has no particles (B%f P%ld)\n", b->id, my_id); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + printf("ERROR : CHILDLESS box has no particles (B%f P%ld)\n", b->id, my_id); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } if (b->particles[b->num_particles - 1] == NULL) { - LOCK(G_Memory->io_lock); - printf("ERROR : CHILDLESS box has fewer particles than expected "); - printf("(B%f P%ld)\n", b->id, my_id); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + printf("ERROR : CHILDLESS box has fewer particles than expected "); + printf("(B%f P%ld)\n", b->id, my_id); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } if (b->particles[b->num_particles] != NULL) { - LOCK(G_Memory->io_lock); - printf("ERROR : CHILDLESS box has more particles than expected "); - printf("(B%f P%ld)\n", b->id, my_id); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + printf("ERROR : CHILDLESS box has more particles than expected "); + printf("(B%f P%ld)\n", b->id, my_id); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } } else { if (partition_level == -1) { - LOCK(G_Memory->io_lock); - printf("ERROR : PARENT box in childless partition (B%f P%ld %ld)\n", - b->id, my_id, b->proc); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + printf("ERROR : PARENT box in childless partition (B%f P%ld %ld)\n", + b->id, my_id, b->proc); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } else { - if (partition_level != b->level) { - LOCK(G_Memory->io_lock); - printf("ERROR : PARENT box in wrong partition level "); - printf("(%ld vs %ld) (B%f P%ld)\n", b->level, partition_level, b->id, my_id); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; - } + if (partition_level != b->level) { + LOCK(G_Memory->io_lock); + printf("ERROR : PARENT box in wrong partition level "); + printf("(%ld vs %ld) (B%f P%ld)\n", b->level, partition_level, b->id, my_id); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; + } } if (b->num_children == 0) { - LOCK(G_Memory->io_lock); - printf("ERROR : PARENT box has no children (B%f P%ld)\n", b->id, my_id); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + printf("ERROR : PARENT box has no children (B%f P%ld)\n", b->id, my_id); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } if (b->num_particles != 0) { - LOCK(G_Memory->io_lock); - printf("ERROR : PARENT box has particles (B%f P%ld)\n", b->id, my_id); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + printf("ERROR : PARENT box has particles (B%f P%ld)\n", b->id, my_id); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } } if (b->parent == NULL) { if (b != Grid) { - LOCK(G_Memory->io_lock); - if (b->type == CHILDLESS) - printf("ERROR : Extra CHILDLESS box in partition (B%f P%ld)\n", b->id, my_id); - else - printf("ERROR : Extra PARENT box in partition (B%f P%ld)\n", b->id, my_id); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + if (b->type == CHILDLESS) + printf("ERROR : Extra CHILDLESS box in partition (B%f P%ld)\n", b->id, my_id); + else + printf("ERROR : Extra PARENT box in partition (B%f P%ld)\n", b->id, my_id); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } } else { if (b->parent->children[b->child_num] != b) { - LOCK(G_Memory->io_lock); - if (b->type == CHILDLESS) - printf("ERROR : Extra CHILDLESS box in partition (B%f P%ld)\n", b->id, my_id); - else - printf("ERROR : Extra PARENT box in partition (B%f P%ld)\n", b->id, my_id); - fflush(stdout); - UNLOCK(G_Memory->io_lock); - num_errors += 1; + LOCK(G_Memory->io_lock); + if (b->type == CHILDLESS) + printf("ERROR : Extra CHILDLESS box in partition (B%f P%ld)\n", b->id, my_id); + else + printf("ERROR : Extra PARENT box in partition (B%f P%ld)\n", b->id, my_id); + fflush(stdout); + UNLOCK(G_Memory->io_lock); + num_errors += 1; } } return num_errors; diff --git a/splash2/codes/apps/fmm/partition_grid.H b/splash2/codes/apps/fmm/partition_grid.H index d3e8a538c..196a2ae71 100644 --- a/splash2/codes/apps/fmm/partition_grid.H +++ b/splash2/codes/apps/fmm/partition_grid.H @@ -17,8 +17,8 @@ #ifndef _Partition_H #define _Partition_H 1 -#include "box.h" #include "defs.h" +#include "box.h" /* Void function type */ typedef void (*partition_function)(long my_id, box *b); @@ -28,7 +28,7 @@ typedef enum { ORB, COST_ZONES } partition_alg; extern void InitPartition(long my_id); extern void PartitionIterate(long my_id, partition_function function, - partition_start position); + partition_start position); extern void InsertBoxInPartition(long my_id, box *b); extern void RemoveBoxFromPartition(long my_id, box *b); extern void ComputeCostOfBox(box *b); diff --git a/splash2/codes/apps/ocean/contiguous_partitions/jacobcalc.C b/splash2/codes/apps/ocean/contiguous_partitions/jacobcalc.C index 04e20f149..37e3fe832 100644 --- a/splash2/codes/apps/ocean/contiguous_partitions/jacobcalc.C +++ b/splash2/codes/apps/ocean/contiguous_partitions/jacobcalc.C @@ -19,10 +19,9 @@ EXTERN_ENV -#include -#include -#include - +#include +#include +#include #include "decs.h" void jacobcalc(double ***x, double ***y, double ***z, long pid, long firstrow, long lastrow, long firstcol, long lastcol) diff --git a/splash2/codes/apps/ocean/contiguous_partitions/jacobcalc2.C b/splash2/codes/apps/ocean/contiguous_partitions/jacobcalc2.C index a834cb724..e074b1539 100644 --- a/splash2/codes/apps/ocean/contiguous_partitions/jacobcalc2.C +++ b/splash2/codes/apps/ocean/contiguous_partitions/jacobcalc2.C @@ -19,10 +19,9 @@ EXTERN_ENV -#include -#include -#include - +#include +#include +#include #include "decs.h" void jacobcalc2(double ****x, double ****y, double ****z, long psiindex, long pid, long firstrow, long lastrow, long firstcol, long lastcol) diff --git a/splash2/codes/apps/ocean/contiguous_partitions/laplacalc.C b/splash2/codes/apps/ocean/contiguous_partitions/laplacalc.C index 88b03e466..797e22d80 100644 --- a/splash2/codes/apps/ocean/contiguous_partitions/laplacalc.C +++ b/splash2/codes/apps/ocean/contiguous_partitions/laplacalc.C @@ -18,10 +18,9 @@ EXTERN_ENV -#include -#include -#include - +#include +#include +#include #include "decs.h" void laplacalc(long procid, double ****x, double ****z, long psiindex, long firstrow, long lastrow, long firstcol, long lastcol) @@ -85,7 +84,7 @@ void laplacalc(long procid, double ****x, double ****z, long psiindex, long firs indexp1 = iindex+1; indexm1 = iindex-1; t1b[iindex] = factlap*(t1c[iindex]+ - t1d[iindex]+t1a[indexp1]+ + t1d[iindex]+t1a[indexp1]+ t1a[indexm1]-4.*t1a[iindex]); } } diff --git a/splash2/codes/apps/ocean/contiguous_partitions/main.C b/splash2/codes/apps/ocean/contiguous_partitions/main.C index fee9fe5eb..12e06e4ca 100644 --- a/splash2/codes/apps/ocean/contiguous_partitions/main.C +++ b/splash2/codes/apps/ocean/contiguous_partitions/main.C @@ -56,11 +56,10 @@ MAIN_ENV #define DOWNRIGHT 7 #define PAGE_SIZE 4096 -#include -#include -#include -#include - +#include +#include +#include +#include #include "decs.h" struct multi_struct *multi; diff --git a/splash2/codes/apps/ocean/contiguous_partitions/multi.C b/splash2/codes/apps/ocean/contiguous_partitions/multi.C index f0e276f4c..b7120330d 100644 --- a/splash2/codes/apps/ocean/contiguous_partitions/multi.C +++ b/splash2/codes/apps/ocean/contiguous_partitions/multi.C @@ -21,11 +21,10 @@ EXTERN_ENV -#include -#include -#include -#include - +#include +#include +#include +#include #include "decs.h" /* perform multigrid (w cycles) */ @@ -124,12 +123,12 @@ void multig(long my_id) if (wu > wmax) { /* max work exceeded */ flag1 = 1; - fprintf(stderr,"ERROR: Maximum work limit %0.5f exceeded\n",wmax); - exit(-1); + fprintf(stderr,"ERROR: Maximum work limit %0.5f exceeded\n",wmax); + exit(-1); } else { /* if we have not converged */ if ((k != 0) && (g_error/errp >= 0.6) && - (k > minlevel)) { + (k > minlevel)) { /* if need to go to coarser grid */ copy_borders(k,my_num); @@ -141,9 +140,9 @@ void multig(long my_id) rescal values */ #if defined(MULTIPLE_BARRIERS) - BARRIER(bars->error_barrier,nprocs) + BARRIER(bars->error_barrier,nprocs) #else - BARRIER(bars->barrier,nprocs) + BARRIER(bars->barrier,nprocs) #endif rescal(k,my_num); @@ -235,8 +234,8 @@ void relax(long k, double *err, long color, long my_num) t1d = (double *) t2a[i+1]; for (j=evenjstart;j -#include -#include -#include - +#include +#include +#include +#include #include "decs.h" void slave() @@ -223,30 +222,30 @@ eof(double) + } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = 0.0; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = 0.0; } } @@ -265,29 +264,29 @@ eof(double) + } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = 0.0; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = 0.0; } } @@ -307,29 +306,29 @@ eof(double) + } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 1.0; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 1.0; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = 1.0; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = 1.0; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = 0.0; } } @@ -366,10 +365,10 @@ eof(double) + t2a = (double **) rhs_multi[procid][numlev-1]; t2b = (double **) psib[procid]; - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1a[j] = t1b[j] * ressqr; } } @@ -377,24 +376,24 @@ eof(double) + if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; t1b = (double *) t2b[0]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1a[j] = t1b[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; t1b = (double *) t2b[im-1]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1a[j] = t1b[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t2a[i][0] = t2b[i][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t2a[i][jm-1] = t2b[i][jm-1]; } } @@ -438,12 +437,12 @@ eof(double) + t2a = (double **) q_multi[procid][numlev-1]; t2b = (double **) psib[procid]; fac = 1.0 / (4.0 - ressqr*eig2); - for (i=ist;i<=ien;i++) { + for(i=ist;i<=ien;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; t1c = (double *) t2b[i-1]; t1d = (double *) t2b[i+1]; - for (j=jst;j<=jen;j++) { + for(j=jst;j<=jen;j++) { t1a[j] = fac * (t1d[j]+t1c[j]+t1b[j+1]+t1b[j-1] - ressqr*t1b[j]); } @@ -451,10 +450,10 @@ eof(double) + multig(procid); - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1b[j] = t1a[j]; } } @@ -482,29 +481,29 @@ eof(double) + } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { psibipriv = psibipriv + 0.5*t1a[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { psibipriv = psibipriv + 0.5*t1a[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { psibipriv = psibipriv + 0.5*t2a[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { psibipriv = psibipriv + 0.5*t2a[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { psibipriv = psibipriv + t1a[iindex]; } } @@ -524,7 +523,7 @@ eof(double) + between the two psim matrices; otherwise, let the single process work on one first and then the other */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { t2a = (double **) psim[procid][psiindex]; if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[0][0] = 0.0; @@ -540,29 +539,29 @@ eof(double) + } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = 0.0; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = 0.0; } } @@ -570,7 +569,7 @@ eof(double) + /* initialize psi matrices the same way */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { t2a = (double **) psi[procid][psiindex]; if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[0][0] = 0.0; @@ -586,29 +585,29 @@ eof(double) + } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = 0.0; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = 0.0; } } @@ -637,7 +636,7 @@ eof(double) + } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { sintemp = pi*((double) j+j_off)*res/ysca1; sintemp = sin(sintemp); curlt = factor*sintemp; @@ -646,7 +645,7 @@ eof(double) + } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { sintemp = pi*((double) j+j_off)*res/ysca1; sintemp = sin(sintemp); curlt = factor*sintemp; @@ -654,7 +653,7 @@ eof(double) + } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = 0.0; } } @@ -662,13 +661,13 @@ eof(double) + sintemp = pi*((double) jm-1+j_off)*res/ysca1; sintemp = sin(sintemp); curlt = factor*sintemp; - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = curlt; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { sintemp = pi*((double) iindex+j_off)*res/ysca1; sintemp = sin(sintemp); curlt = factor*sintemp; @@ -693,11 +692,11 @@ eof(double) + if (procid == MASTER) { CLOCK(global->trackstart) } - if ((procid == MASTER) || (do_stats)) { - CLOCK(t1); + if ((procid == MASTER) || (do_stats)) { + CLOCK(t1); gp[procid].total_time = t1; gp[procid].multi_time = 0; - } + } /* POSSIBLE ENHANCEMENT: Here is where one might reset the statistics that one is measuring about the parallel execution */ } @@ -717,7 +716,7 @@ eof(double) + iday = (long) day; dhour = dhour+dtau; if (dhour >= 86400.0) { - dhourflag = 1; + dhourflag = 1; } } } @@ -736,37 +735,37 @@ eof(double) + } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[im-1][jm-1] = t2a[im-1][jm-1] + - t2b[im-1][jm-1]; + t2b[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; t1b = (double *) t2b[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j]+t1b[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; t1b = (double *) t2b[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j] + t1b[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2a[j][0]+t2b[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2a[j][jm-1] + - t2b[j][jm-1]; + t2b[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1a[iindex] + t1b[iindex]; } } @@ -786,36 +785,36 @@ eof(double) + } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[im-1][jm-1] = t2a[im-1][jm-1] + - t2b[im-1][jm-1]; + t2b[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; t1b = (double *) t2b[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j]+t1b[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; t1b = (double *) t2b[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j]+t1b[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2a[j][0]+t2b[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2a[j][jm-1] + t2b[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1a[iindex] + t1b[iindex]; } } diff --git a/splash2/codes/apps/ocean/contiguous_partitions/slave2.C b/splash2/codes/apps/ocean/contiguous_partitions/slave2.C index 5f85baec6..222a57e02 100644 --- a/splash2/codes/apps/ocean/contiguous_partitions/slave2.C +++ b/splash2/codes/apps/ocean/contiguous_partitions/slave2.C @@ -20,11 +20,10 @@ EXTERN_ENV -#include -#include -#include -#include - +#include +#include +#include +#include #include "decs.h" void slave2(long procid, long firstrow, long lastrow, long numrows, long firstcol, long lastcol, long numcols) @@ -96,29 +95,29 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = 0.0; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = 0.0; } } @@ -138,29 +137,29 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = 0.0; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = 0.0; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = 0.0; } } @@ -169,7 +168,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco note that psi(i,j,2) represents the psi3 array in the original equations */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { t2a = (double **) work1[procid][psiindex]; if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[0][0] = 0; @@ -184,7 +183,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t2a[im-1][jm-1] = 0; } laplacalc(procid,psi,work1,psiindex, - firstrow,lastrow,firstcol,lastcol); + firstrow,lastrow,firstcol,lastcol); } /* set values of work2 array to psi1 - psi3 */ @@ -203,13 +202,13 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[im-1][jm-1] = t2b[im-1][jm-1] - - t2c[im-1][jm-1]; + t2c[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; t1b = (double *) t2b[0]; t1c = (double *) t2c[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1b[j]-t1c[j]; } } @@ -217,25 +216,25 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t1a = (double *) t2a[im-1]; t1b = (double *) t2b[im-1]; t1c = (double *) t2c[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1b[j]-t1c[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2b[j][0]-t2c[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2b[j][jm-1]-t2c[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; t1c = (double *) t2c[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1b[iindex] - t1c[iindex]; } } @@ -250,49 +249,49 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[im-1][0] = hh3*t2a[im-1][0] + - hh1*t2c[im-1][0]; + hh1*t2c[im-1][0]; } if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[0][jm-1] = hh3*t2a[0][jm-1] + - hh1*t2c[0][jm-1]; + hh1*t2c[0][jm-1]; } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[im-1][jm-1] = hh3*t2a[im-1][jm-1] + - hh1*t2c[im-1][jm-1]; + hh1*t2c[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t2a[0][j] = hh3*t2a[0][j]+hh1*t2c[0][j]; } } if (gp[procid].neighbors[DOWN] == -1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t2a[im-1][j] = hh3*t2a[im-1][j] + - hh1*t2c[im-1][j]; + hh1*t2c[im-1][j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = hh3*t2a[j][0]+hh1*t2c[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = hh3*t2a[j][jm-1] + - hh1*t2c[j][jm-1]; + hh1*t2c[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1c = (double *) t2c[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = hh3*t1a[iindex] + hh1*t1c[iindex]; } } /* set values of temparray{1,3} to psim{1,3} */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { t2a = (double **) temparray[procid][psiindex]; t2b = (double **) psi[procid][psiindex]; if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[LEFT] == -1)) { @@ -308,30 +307,30 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t2a[im-1][jm-1] = t2b[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t2a[0][j] = t2b[0][j]; } } if (gp[procid].neighbors[DOWN] == -1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t2a[im-1][j] = t2b[im-1][j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2b[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2b[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1b[iindex]; } } @@ -349,7 +348,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco set values of psi{1,3} to psim{1,3} */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { t2a = (double **) psi[procid][psiindex]; t2b = (double **) psim[procid][psiindex]; if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[LEFT] == -1)) { @@ -365,30 +364,30 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t2a[im-1][jm-1] = t2b[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t2a[0][j] = t2b[0][j]; } } if (gp[procid].neighbors[DOWN] == -1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t2a[im-1][j] = t2b[im-1][j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2b[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2b[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1b[iindex]; } } @@ -398,7 +397,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco into the work7 array; first part of a three-laplacian calculation to compute the friction terms */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { t2a = (double **) work7[procid][psiindex]; if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[0][0] = 0; @@ -413,7 +412,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t2a[im-1][jm-1] = 0; } laplacalc(procid,psim,work7,psiindex, - firstrow,lastrow,firstcol,lastcol); + firstrow,lastrow,firstcol,lastcol); } /* to the values of the work1{1,2} arrays obtained from the @@ -421,7 +420,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco elements of every column the corresponding value in the one-dimenional f array */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { t2a = (double **) work1[procid][psiindex]; if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[0][0] = t2a[0][0] + f[0]; @@ -436,28 +435,28 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t2a[im-1][jm-1]=t2a[im-1][jm-1] + f[jmx[numlev-1]-1]; } if (gp[procid].neighbors[UP] == -1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t2a[0][j] = t2a[0][j] + f[j+j_off]; } } if (gp[procid].neighbors[DOWN] == -1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t2a[im-1][j] = t2a[im-1][j] + f[j+j_off]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2a[j][0] + f[j+i_off]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2a[j][jm-1] + f[j+i_off]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex]=t1a[iindex] + f[iindex+j_off]; } } @@ -471,19 +470,19 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t h i r d p h a s e - ******************************************************* + ******************************************************* put the jacobian of the work1{1,2} and psi{1,3} arrays (the latter currently in temparray) in the work5{1,2} arrays */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { jacobcalc2(work1,temparray,work5,psiindex,procid,firstrow,lastrow, - firstcol,lastcol); + firstcol,lastcol); } /* set values of psim{1,3} to temparray{1,3} */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { t2a = (double **) psim[procid][psiindex]; t2b = (double **) temparray[procid][psiindex]; if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[LEFT] == -1)) { @@ -501,31 +500,31 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; t1b = (double *) t2b[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1b[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; t1b = (double *) t2b[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1b[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2b[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2b[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1b[iindex]; } } @@ -534,9 +533,9 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco /* put the laplacian of the work7{1,2} arrays in the work4{1,2} arrays; second step in the three-laplacian friction calculation */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { laplacalc(procid,work7,work4,psiindex, - firstrow,lastrow,firstcol,lastcol); + firstrow,lastrow,firstcol,lastcol); } #if defined(MULTIPLE_BARRIERS) BARRIER(bars->sl_phase_3,nprocs) @@ -557,9 +556,9 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco /* put the laplacian of the work4{1,2} arrays in the work7{1,2} arrays; third step in the three-laplacian friction calculation */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { laplacalc(procid,work4,work7,psiindex, - firstrow,lastrow,firstcol,lastcol); + firstrow,lastrow,firstcol,lastcol); } #if defined(MULTIPLE_BARRIERS) BARRIER(bars->sl_phase_4,nprocs) @@ -589,37 +588,37 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t2h = (double **) tauz[procid]; if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[0][0] = t2c[0][0]-t2d[0][0] + - eig2*t2g[0][0]+h1inv*t2h[0][0] + - lf*t2e[0][0]-lf*t2f[0][0]; + eig2*t2g[0][0]+h1inv*t2h[0][0] + + lf*t2e[0][0]-lf*t2f[0][0]; t2b[0][0] = hh1*t2c[0][0]+hh3*t2d[0][0] + - hinv*t2h[0][0]+lf*hh1*t2e[0][0] + - lf*hh3*t2f[0][0]; + hinv*t2h[0][0]+lf*hh1*t2e[0][0] + + lf*hh3*t2f[0][0]; } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[im-1][0] = t2c[im-1][0]-t2d[im-1][0] + - eig2*t2g[im-1][0] + h1inv*t2h[im-1][0] + - lf*t2e[im-1][0] - lf*t2f[im-1][0]; + eig2*t2g[im-1][0] + h1inv*t2h[im-1][0] + + lf*t2e[im-1][0] - lf*t2f[im-1][0]; t2b[im-1][0] = hh1*t2c[im-1][0] + - hh3*t2d[im-1][0] + hinv*t2h[im-1][0] + - lf*hh1*t2e[im-1][0] + lf*hh3*t2f[im-1][0]; + hh3*t2d[im-1][0] + hinv*t2h[im-1][0] + + lf*hh1*t2e[im-1][0] + lf*hh3*t2f[im-1][0]; } if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[0][jm-1] = t2c[0][jm-1]-t2d[0][jm-1]+ - eig2*t2g[0][jm-1]+h1inv*t2h[0][jm-1] + - lf*t2e[0][jm-1]-lf*t2f[0][jm-1]; + eig2*t2g[0][jm-1]+h1inv*t2h[0][jm-1] + + lf*t2e[0][jm-1]-lf*t2f[0][jm-1]; t2b[0][jm-1] = hh1*t2c[0][jm-1] + - hh3*t2d[0][jm-1]+hinv*t2h[0][jm-1] + - lf*hh1*t2e[0][jm-1]+lf*hh3*t2f[0][jm-1]; + hh3*t2d[0][jm-1]+hinv*t2h[0][jm-1] + + lf*hh1*t2e[0][jm-1]+lf*hh3*t2f[0][jm-1]; } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[im-1][jm-1] = t2c[im-1][jm-1] - - t2d[im-1][jm-1]+eig2*t2g[im-1][jm-1] + - h1inv*t2h[im-1][jm-1]+lf*t2e[im-1][jm-1] - - lf*t2f[im-1][jm-1]; + t2d[im-1][jm-1]+eig2*t2g[im-1][jm-1] + + h1inv*t2h[im-1][jm-1]+lf*t2e[im-1][jm-1] - + lf*t2f[im-1][jm-1]; t2b[im-1][jm-1] = hh1*t2c[im-1][jm-1] + - hh3*t2d[im-1][jm-1]+hinv*t2h[im-1][jm-1] + - lf*hh1*t2e[im-1][jm-1] + - lf*hh3*t2f[im-1][jm-1]; + hh3*t2d[im-1][jm-1]+hinv*t2h[im-1][jm-1] + + lf*hh1*t2e[im-1][jm-1] + + lf*hh3*t2f[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; @@ -630,13 +629,13 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t1f = (double *) t2f[0]; t1g = (double *) t2g[0]; t1h = (double *) t2h[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1c[j]-t1d[j] + - eig2*t1g[j]+h1inv*t1h[j] + - lf*t1e[j]-lf*t1f[j]; + eig2*t1g[j]+h1inv*t1h[j] + + lf*t1e[j]-lf*t1f[j]; t1b[j] = hh1*t1c[j] + - hh3*t1d[j]+hinv*t1h[j] + - lf*hh1*t1e[j]+lf*hh3*t1f[j]; + hh3*t1d[j]+hinv*t1h[j] + + lf*hh1*t1e[j]+lf*hh3*t1f[j]; } } if (gp[procid].neighbors[DOWN] == -1) { @@ -648,39 +647,39 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t1f = (double *) t2f[im-1]; t1g = (double *) t2g[im-1]; t1h = (double *) t2h[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1c[j] - - t1d[j]+eig2*t1g[j] + - h1inv*t1h[j]+lf*t1e[j] - - lf*t1f[j]; + t1d[j]+eig2*t1g[j] + + h1inv*t1h[j]+lf*t1e[j] - + lf*t1f[j]; t1b[j] = hh1*t1c[j] + - hh3*t1d[j]+hinv*t1h[j] + - lf*hh1*t1e[j]+lf*hh3*t1f[j]; + hh3*t1d[j]+hinv*t1h[j] + + lf*hh1*t1e[j]+lf*hh3*t1f[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2c[j][0]-t2d[j][0] + - eig2*t2g[j][0]+h1inv*t2h[j][0] + - lf*t2e[j][0]-lf*t2f[j][0]; + eig2*t2g[j][0]+h1inv*t2h[j][0] + + lf*t2e[j][0]-lf*t2f[j][0]; t2b[j][0] = hh1*t2c[j][0] + - hh3*t2d[j][0]+hinv*t2h[j][0] + - lf*hh1*t2e[j][0]+lf*hh3*t2f[j][0]; + hh3*t2d[j][0]+hinv*t2h[j][0] + + lf*hh1*t2e[j][0]+lf*hh3*t2f[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2c[j][jm-1] - - t2d[j][jm-1]+eig2*t2g[j][jm-1] + - h1inv*t2h[j][jm-1]+lf*t2e[j][jm-1] - - lf*t2f[j][jm-1]; + t2d[j][jm-1]+eig2*t2g[j][jm-1] + + h1inv*t2h[j][jm-1]+lf*t2e[j][jm-1] - + lf*t2f[j][jm-1]; t2b[j][jm-1] = hh1*t2c[j][jm-1] + - hh3*t2d[j][jm-1]+hinv*t2h[j][jm-1] + - lf*hh1*t2e[j][jm-1]+lf*hh3*t2f[j][jm-1]; + hh3*t2d[j][jm-1]+hinv*t2h[j][jm-1] + + lf*hh1*t2e[j][jm-1]+lf*hh3*t2f[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; t1c = (double *) t2c[i]; @@ -689,15 +688,15 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t1f = (double *) t2f[i]; t1g = (double *) t2g[i]; t1h = (double *) t2h[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1c[iindex] - - t1d[iindex]+eig2*t1g[iindex] + - h1inv*t1h[iindex]+lf*t1e[iindex] - - lf*t1f[iindex]; + t1d[iindex]+eig2*t1g[iindex] + + h1inv*t1h[iindex]+lf*t1e[iindex] - + lf*t1f[iindex]; t1b[iindex] = hh1*t1c[iindex] + - hh3*t1d[iindex]+hinv*t1h[iindex] + - lf*hh1*t1e[iindex] + - lf*hh3*t1f[iindex]; + hh3*t1d[iindex]+hinv*t1h[iindex] + + lf*hh1*t1e[iindex] + + lf*hh3*t1f[iindex]; } } #if defined(MULTIPLE_BARRIERS) @@ -736,10 +735,10 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t2b = (double **) ga[procid]; t2c = (double **) oldga[procid]; t2d = (double **) q_multi[procid][numlev-1]; - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1a[j] = t1b[j] * ressqr; } } @@ -747,33 +746,33 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco if (gp[procid].neighbors[UP] == -1) { t1d = (double *) t2d[0]; t1b = (double *) t2b[0]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1d[j] = t1b[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1d = (double *) t2d[im-1]; t1b = (double *) t2b[im-1]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1d[j] = t1b[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t2d[i][0] = t2b[i][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t2d[i][jm-1] = t2b[i][jm-1]; } } fac = 1.0 / (4.0 - ressqr*eig2); - for (i=ist;i<=ien;i++) { + for(i=ist;i<=ien;i++) { t1d = (double *) t2d[i]; t1c = (double *) t2c[i]; - for (j=jst;j<=jen;j++) { + for(j=jst;j<=jen;j++) { t1d[j] = t1c[j]; } } @@ -798,11 +797,11 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco /* copy the solution for use as initial guess in next time-step */ - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t1b = (double *) t2b[i]; t1c = (double *) t2c[i]; t1d = (double *) t2d[i]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1b[j] = t1d[j]; t1c[j] = t1d[j]; } @@ -837,29 +836,29 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { psiaipriv = psiaipriv + 0.5*t1a[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { psiaipriv = psiaipriv + 0.5*t1a[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { psiaipriv = psiaipriv + 0.5*t2a[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { psiaipriv = psiaipriv + 0.5*t2a[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { psiaipriv = psiaipriv + t1a[iindex]; } } @@ -898,36 +897,36 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[im-1][jm-1] = t2a[im-1][jm-1] + - f4*t2b[im-1][jm-1]; + f4*t2b[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; t1b = (double *) t2b[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j]+f4*t1b[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; t1b = (double *) t2b[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j]+f4*t1b[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2a[j][0]+f4*t2b[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2a[j][jm-1]+f4*t2b[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1a[iindex]+f4*t1b[iindex]; } } @@ -936,43 +935,43 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t2b = (double **) gb[procid]; t2c = (double **) oldgb[procid]; t2d = (double **) q_multi[procid][numlev-1]; - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1a[j] = t1b[j] * ressqr; } } if (gp[procid].neighbors[UP] == -1) { t1d = (double *) t2d[0]; t1b = (double *) t2b[0]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1d[j] = t1b[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1d = (double *) t2d[im-1]; t1b = (double *) t2b[im-1]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1d[j] = t1b[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t2d[i][0] = t2b[i][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t2d[i][jm-1] = t2b[i][jm-1]; } } fac = 1.0 / (4.0 - ressqr*eig2); - for (i=ist;i<=ien;i++) { + for(i=ist;i<=ien;i++) { t1d = (double *) t2d[i]; t1c = (double *) t2c[i]; - for (j=jst;j<=jen;j++) { + for(j=jst;j<=jen;j++) { t1d[j] = t1c[j]; } } @@ -988,11 +987,11 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco gp[procid].multi_time += (multi_end - multi_start); } - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { t1b = (double *) t2b[i]; t1c = (double *) t2c[i]; t1d = (double *) t2d[i]; - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { t1b[j] = t1d[j]; t1c[j] = t1d[j]; } @@ -1035,16 +1034,16 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2c[im-1][jm-1] = t2b[im-1][jm-1] - - hh1*t2a[im-1][jm-1]; + hh1*t2a[im-1][jm-1]; t2d[im-1][jm-1] = t2b[im-1][jm-1] + - hh3*t2a[im-1][jm-1]; + hh3*t2a[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; t1b = (double *) t2b[0]; t1c = (double *) t2c[0]; t1d = (double *) t2d[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1d[j] = t1b[j]+hh3*t1a[j]; t1c[j] = t1b[j]-hh1*t1a[j]; } @@ -1054,30 +1053,30 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t1b = (double *) t2b[im-1]; t1c = (double *) t2c[im-1]; t1d = (double *) t2d[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1d[j] = t1b[j]+hh3*t1a[j]; t1c[j] = t1b[j]-hh1*t1a[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2d[j][0] = t2b[j][0]+hh3*t2a[j][0]; t2c[j][0] = t2b[j][0]-hh1*t2a[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2d[j][jm-1] = t2b[j][jm-1]+hh3*t2a[j][jm-1]; t2c[j][jm-1] = t2b[j][jm-1]-hh1*t2a[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; t1c = (double *) t2c[i]; t1d = (double *) t2d[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1d[iindex] = t1b[iindex] + hh3*t1a[iindex]; t1c[iindex] = t1b[iindex] - hh1*t1a[iindex]; } @@ -1105,45 +1104,45 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[im-1][0] = t2a[im-1][0] + - timst*t2b[im-1][0]; + timst*t2b[im-1][0]; } if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[0][jm-1] = t2a[0][jm-1] + - timst*t2b[0][jm-1]; + timst*t2b[0][jm-1]; } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[im-1][jm-1] = t2a[im-1][jm-1] + - timst*t2b[im-1][jm-1]; + timst*t2b[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; t1b = (double *) t2b[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j] + timst*t1b[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; t1b = (double *) t2b[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j] + timst*t1b[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2a[j][0] + timst*t2b[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2a[j][jm-1] + - timst*t2b[j][jm-1]; + timst*t2b[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1a[iindex] + timst*t1b[iindex]; } } @@ -1155,46 +1154,46 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[LEFT] == -1)) { t2a[im-1][0] = t2a[im-1][0] + - timst*t2b[im-1][0]; + timst*t2b[im-1][0]; } if ((gp[procid].neighbors[UP] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[0][jm-1] = t2a[0][jm-1] + - timst*t2b[0][jm-1]; + timst*t2b[0][jm-1]; } if ((gp[procid].neighbors[DOWN] == -1) && (gp[procid].neighbors[RIGHT] == -1)) { t2a[im-1][jm-1] = t2a[im-1][jm-1] + - timst*t2b[im-1][jm-1]; + timst*t2b[im-1][jm-1]; } if (gp[procid].neighbors[UP] == -1) { t1a = (double *) t2a[0]; t1b = (double *) t2b[0]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j] + timst*t1b[j]; } } if (gp[procid].neighbors[DOWN] == -1) { t1a = (double *) t2a[im-1]; t1b = (double *) t2b[im-1]; - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { t1a[j] = t1a[j] + timst*t1b[j]; } } if (gp[procid].neighbors[LEFT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][0] = t2a[j][0] + timst*t2b[j][0]; } } if (gp[procid].neighbors[RIGHT] == -1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { t2a[j][jm-1] = t2a[j][jm-1] + - timst*t2b[j][jm-1]; + timst*t2b[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { t1a = (double *) t2a[i]; t1b = (double *) t2b[i]; - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { t1a[iindex] = t1a[iindex] + timst*t1b[iindex]; } } diff --git a/splash2/codes/apps/ocean/contiguous_partitions/subblock.C b/splash2/codes/apps/ocean/contiguous_partitions/subblock.C index a40a8f865..0e1d65d7d 100644 --- a/splash2/codes/apps/ocean/contiguous_partitions/subblock.C +++ b/splash2/codes/apps/ocean/contiguous_partitions/subblock.C @@ -16,9 +16,8 @@ EXTERN_ENV -#include -#include - +#include +#include #include "decs.h" void subblock() diff --git a/splash2/codes/apps/ocean/non_contiguous_partitions/jacobcalc.C b/splash2/codes/apps/ocean/non_contiguous_partitions/jacobcalc.C index d8c25d9da..e2d1b4a51 100644 --- a/splash2/codes/apps/ocean/non_contiguous_partitions/jacobcalc.C +++ b/splash2/codes/apps/ocean/non_contiguous_partitions/jacobcalc.C @@ -17,10 +17,9 @@ /* does the arakawa jacobian calculation (of the x and y matrices, putting the results in the z matrix) for a subblock. */ -#include -#include -#include - +#include +#include +#include #include "decs.h" void jacobcalc(double x[IMAX][JMAX], double y[IMAX][JMAX], double z[IMAX][JMAX], long pid, long firstrow, long lastrow, long firstcol, long lastcol, long numrows, long numcols) diff --git a/splash2/codes/apps/ocean/non_contiguous_partitions/laplacalc.C b/splash2/codes/apps/ocean/non_contiguous_partitions/laplacalc.C index bf9205af6..a2fb87ea6 100644 --- a/splash2/codes/apps/ocean/non_contiguous_partitions/laplacalc.C +++ b/splash2/codes/apps/ocean/non_contiguous_partitions/laplacalc.C @@ -20,10 +20,9 @@ performs the laplacian calculation for a subblock. */ -#include -#include -#include - +#include +#include +#include #include "decs.h" void laplacalc(double x[IMAX][JMAX], double z[IMAX][JMAX], long firstrow, long lastrow, long firstcol, long lastcol, long numrows, long numcols) diff --git a/splash2/codes/apps/ocean/non_contiguous_partitions/main.C b/splash2/codes/apps/ocean/non_contiguous_partitions/main.C index 73a77740a..c29e91c23 100644 --- a/splash2/codes/apps/ocean/non_contiguous_partitions/main.C +++ b/splash2/codes/apps/ocean/non_contiguous_partitions/main.C @@ -23,11 +23,10 @@ /* */ /*************************************************************************/ -#include -#include -#include -#include - +#include +#include +#include +#include #include "decs.h" MAIN_ENV diff --git a/splash2/codes/apps/ocean/non_contiguous_partitions/multi.C b/splash2/codes/apps/ocean/non_contiguous_partitions/multi.C index aada1241b..76b750213 100644 --- a/splash2/codes/apps/ocean/non_contiguous_partitions/multi.C +++ b/splash2/codes/apps/ocean/non_contiguous_partitions/multi.C @@ -19,11 +19,10 @@ iterations, w cycles, and the method of half-injection for residual computation */ -#include -#include -#include -#include - +#include +#include +#include +#include #include "decs.h" /* perform multigrid (w cycles) */ @@ -208,8 +207,8 @@ void relax(long k, double *err, long color, long my_num) for (i=evenistart;iq_multi[k][i][j+1] + multi->q_multi[k][i][j-1] + - multi->q_multi[k][i-1][j] + multi->q_multi[k][i+1][j] - - multi->rhs_multi[k][i][j] ; + multi->q_multi[k][i-1][j] + multi->q_multi[k][i+1][j] - + multi->rhs_multi[k][i][j] ; oldval = multi->q_multi[k][i][j]; newval = a / factor; newerr = oldval - newval; @@ -222,8 +221,8 @@ void relax(long k, double *err, long color, long my_num) for (i=oddistart;iq_multi[k][i][j+1] + multi->q_multi[k][i][j-1] + - multi->q_multi[k][i-1][j] + multi->q_multi[k][i+1][j] - - multi->rhs_multi[k][i][j] ; + multi->q_multi[k][i-1][j] + multi->q_multi[k][i+1][j] - + multi->rhs_multi[k][i][j] ; oldval = multi->q_multi[k][i][j]; newval = a / factor; newerr = oldval - newval; @@ -237,8 +236,8 @@ void relax(long k, double *err, long color, long my_num) for (i=evenistart;iq_multi[k][i][j+1] + multi->q_multi[k][i][j-1] + - multi->q_multi[k][i-1][j] + multi->q_multi[k][i+1][j] - - multi->rhs_multi[k][i][j] ; + multi->q_multi[k][i-1][j] + multi->q_multi[k][i+1][j] - + multi->rhs_multi[k][i][j] ; oldval = multi->q_multi[k][i][j]; newval = a / factor; newerr = oldval - newval; @@ -251,8 +250,8 @@ void relax(long k, double *err, long color, long my_num) for (i=oddistart;iq_multi[k][i][j+1] + multi->q_multi[k][i][j-1] + - multi->q_multi[k][i-1][j] + multi->q_multi[k][i+1][j] - - multi->rhs_multi[k][i][j] ; + multi->q_multi[k][i-1][j] + multi->q_multi[k][i+1][j] - + multi->rhs_multi[k][i][j] ; oldval = multi->q_multi[k][i][j]; newval = a / factor; newerr = oldval - newval; @@ -306,25 +305,25 @@ void rescal(long kf, long my_num) factor = 4.0 - eig2 * hf * hf; if17=2*(istart-1); - for (ic=istart;ic<=iend;ic++) { + for(ic=istart;ic<=iend;ic++) { if17+=2; i_int_factor = ic * i_int_coeff[krc] * 0.5; jf = 2 * (jstart - 1); - for (jc=jstart;jc<=jend;jc++) { + for(jc=jstart;jc<=jend;jc++) { jf+=2; j_int_factor = jc*j_int_coeff[krc] * 0.5; /* method of half-injection uses 2.0 instead of 4.0 */ s = multi->q_multi[kf][if17][jf+1] + multi->q_multi[kf][if17][jf-1] + multi->q_multi[kf][if17-1][jf] + multi->q_multi[kf][if17+1][jf]; s1 = 2.0 * (multi->rhs_multi[kf][if17][jf] - s + - factor * multi->q_multi[kf][if17][jf]); + factor * multi->q_multi[kf][if17][jf]); if ((if17 == 2) || (jf ==2)) { s2 = 0; } else { s = multi->q_multi[kf][if17][jf-1] + multi->q_multi[kf][if17][jf-3] + multi->q_multi[kf][if17-1][jf-2] + multi->q_multi[kf][if17+1][jf-2]; s2 = 2.0 * (multi->rhs_multi[kf][if17][jf-2] - s + - factor * multi->q_multi[kf][if17][jf-2]); + factor * multi->q_multi[kf][if17][jf-2]); } if ((if17 == 2) || (jf ==2)) { s3 = 0; @@ -332,7 +331,7 @@ void rescal(long kf, long my_num) s = multi->q_multi[kf][if17-2][jf+1] + multi->q_multi[kf][if17-2][jf-1] + multi->q_multi[kf][if17-3][jf] + multi->q_multi[kf][if17-1][jf]; s3 = 2.0 * (multi->rhs_multi[kf][if17-2][jf] - s + - factor * multi->q_multi[kf][if17-2][jf]); + factor * multi->q_multi[kf][if17-2][jf]); } if ((if17 == 2) || (jf ==2)) { s4 = 0; @@ -340,7 +339,7 @@ void rescal(long kf, long my_num) s = multi->q_multi[kf][if17-2][jf-1] + multi->q_multi[kf][if17-2][jf-3] + multi->q_multi[kf][if17-3][jf-2] + multi->q_multi[kf][if17-1][jf-2]; s4 = 2.0 * (multi->rhs_multi[kf][if17-2][jf-2] - s + - factor * multi->q_multi[kf][if17-2][jf-2]); + factor * multi->q_multi[kf][if17-2][jf-2]); } int1 = j_int_factor*s4 + (1.0-j_int_factor)*s3; int2 = j_int_factor*s2 + (1.0-j_int_factor)*s1; @@ -389,7 +388,7 @@ void intadd(long kc, long my_num) iend = gp[my_num].rel_start_y[kc] + gp[my_num].rel_num_y[kc] - 1; jend = gp[my_num].rel_start_x[kc] + gp[my_num].rel_num_x[kc] - 1; if17 = 2*(istart-1); - for (ic=istart;ic<=iend;ic++) { + for(ic=istart;ic<=iend;ic++) { if17+=2; ifine1 = if17-1; @@ -399,7 +398,7 @@ void intadd(long kc, long my_num) jf = 2*(jstart-1); - for (jc=jstart;jc<=jend;jc++) { + for(jc=jstart;jc<=jend;jc++) { jf+=2; jfine1 = jf-1; jfine2 = jf; @@ -407,25 +406,25 @@ void intadd(long kc, long my_num) j_int_factor2= jc * j_int_coeff[kf]; int1 = j_int_factor1*multi->q_multi[kc][ic][jc-1] + - (1.0-j_int_factor1)*multi->q_multi[kc][ic][jc]; + (1.0-j_int_factor1)*multi->q_multi[kc][ic][jc]; int2 = j_int_factor1*multi->q_multi[kc][ic-1][jc-1] + - (1.0-j_int_factor1)*multi->q_multi[kc][ic-1][jc]; + (1.0-j_int_factor1)*multi->q_multi[kc][ic-1][jc]; multi->q_multi[kf][if17-1][jf-1] += i_int_factor1*int2 + - (1.0-i_int_factor1)*int1; + (1.0-i_int_factor1)*int1; int2 = j_int_factor1*multi->q_multi[kc][ic+1][jc-1] + - (1.0-j_int_factor1)*multi->q_multi[kc][ic+1][jc]; + (1.0-j_int_factor1)*multi->q_multi[kc][ic+1][jc]; multi->q_multi[kf][if17][jf-1] += i_int_factor2*int2 + - (1.0-i_int_factor2)*int1; + (1.0-i_int_factor2)*int1; int1 = j_int_factor2*multi->q_multi[kc][ic][jc+1] + - (1.0-j_int_factor2)*multi->q_multi[kc][ic][jc]; + (1.0-j_int_factor2)*multi->q_multi[kc][ic][jc]; int2 = j_int_factor2*multi->q_multi[kc][ic-1][jc+1] + - (1.0-j_int_factor2)*multi->q_multi[kc][ic-1][jc]; + (1.0-j_int_factor2)*multi->q_multi[kc][ic-1][jc]; multi->q_multi[kf][if17-1][jf] += i_int_factor1*int2 + - (1.0-i_int_factor1)*int1; + (1.0-i_int_factor1)*int1; int2 = j_int_factor2*multi->q_multi[kc][ic+1][jc+1] + - (1.0-j_int_factor2)*multi->q_multi[kc][ic+1][jc]; + (1.0-j_int_factor2)*multi->q_multi[kc][ic+1][jc]; multi->q_multi[kf][if17][jf] += i_int_factor2*int2 + - (1.0-i_int_factor2)*int1; + (1.0-i_int_factor2)*int1; } } } diff --git a/splash2/codes/apps/ocean/non_contiguous_partitions/slave1.C b/splash2/codes/apps/ocean/non_contiguous_partitions/slave1.C index ed921ab2f..52dc19f5f 100644 --- a/splash2/codes/apps/ocean/non_contiguous_partitions/slave1.C +++ b/splash2/codes/apps/ocean/non_contiguous_partitions/slave1.C @@ -18,10 +18,10 @@ subroutine slave **************** */ -#include -#include -#include -#include +#include +#include +#include +#include #include "decs.h" @@ -103,7 +103,7 @@ void slave() ysca1 = 0.5*ysca; if (procid == MASTER) { - for (iindex = 0;iindex<=jm-1;iindex++) { + for(iindex = 0;iindex<=jm-1;iindex++) { y = ((double) iindex)*res; wrk2->f[iindex] = f0+beta*(y-ysca1); } @@ -122,28 +122,28 @@ void slave() fields2->psium[im-1][jm-1]=0.0; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields2->psium[0][j] = 0.0; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields2->psium[im-1][j] = 0.0; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields2->psium[j][0] = 0.0; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields2->psium[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields2->psium[i][iindex] = 0.0; } } @@ -160,27 +160,27 @@ void slave() fields2->psilm[im-1][jm-1]=0.0; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields2->psilm[0][j] = 0.0; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields2->psilm[im-1][j] = 0.0; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields2->psilm[j][0] = 0.0; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields2->psilm[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields2->psilm[i][iindex] = 0.0; } } @@ -198,27 +198,27 @@ void slave() wrk1->psib[im-1][jm-1]=1.0; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->psib[0][j] = 1.0; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->psib[im-1][j] = 1.0; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->psib[j][0] = 1.0; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->psib[j][jm-1] = 1.0; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk1->psib[i][iindex] = 0.0; } } @@ -249,35 +249,35 @@ BARRIER(bars->barrier,nprocs) if (jend == jm-2) { jend = jm-1; } - for (i=istart;i<=iend;i++) { - for (j=jstart;j<=jend;j++) { + for(i=istart;i<=iend;i++) { + for(j=jstart;j<=jend;j++) { multi->rhs_multi[numlev-1][i][j] = wrk1->psib[i][j] * ressqr; } } if (istart == 0) { - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { multi->q_multi[numlev-1][0][j] = wrk1->psib[0][j]; } } if (iend == im-1) { - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { multi->q_multi[numlev-1][im-1][j] = wrk1->psib[im-1][j]; } } if (jstart == 0) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { multi->q_multi[numlev-1][i][0] = wrk1->psib[i][0]; } } if (jend == jm-1) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { multi->q_multi[numlev-1][i][jm-1] = wrk1->psib[i][jm-1]; } } fac = 1.0 / (4.0 - ressqr*eig2); - for (i=ist;i<=ien;i++) { - for (j=jst;j<=jen;j++) { + for(i=ist;i<=ien;i++) { + for(j=jst;j<=jen;j++) { multi->q_multi[numlev-1][i][j] = fac * (wrk1->psib[i+1][j] + wrk1->psib[i-1][j] + wrk1->psib[i][j+1] + wrk1->psib[i][j-1] - ressqr*wrk1->psib[i][j]); @@ -290,8 +290,8 @@ BARRIER(bars->barrier,nprocs) #endif multig(procid); - for (i=istart;i<=iend;i++) { - for (j=jstart;j<=jend;j++) { + for(i=istart;i<=iend;i++) { + for(j=jstart;j<=jend;j++) { wrk1->psib[i][j] = multi->q_multi[numlev-1][i][j]; } } @@ -317,27 +317,27 @@ BARRIER(bars->barrier,nprocs) psibipriv=psibipriv+0.25*(wrk1->psib[im-1][jm-1]); } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { psibipriv = psibipriv + 0.5*wrk1->psib[0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { psibipriv = psibipriv + 0.5*wrk1->psib[im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { psibipriv = psibipriv + 0.5*wrk1->psib[j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { psibipriv = psibipriv + 0.5*wrk1->psib[j][jm-1]; } } - for (iindex=firstcol;iindex<=lastcol;iindex++) { - for (i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { psibipriv = psibipriv + wrk1->psib[i][iindex]; } } @@ -351,7 +351,7 @@ BARRIER(bars->barrier,nprocs) global->psibi = global->psibi + psibipriv; UNLOCK(locks->psibilock) - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { if (procid == MASTER) { fields->psim[psiindex][0][0] = 0.0; } @@ -365,27 +365,27 @@ BARRIER(bars->barrier,nprocs) fields->psim[psiindex][im-1][jm-1] = 0.0; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psim[psiindex][0][j] = 0.0; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psim[psiindex][im-1][j] = 0.0; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psim[psiindex][j][0] = 0.0; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psim[psiindex][j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields->psim[psiindex][i][iindex] = 0.0; } } @@ -393,7 +393,7 @@ BARRIER(bars->barrier,nprocs) /* initialize psi matrices the same way */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { if (procid == MASTER) { fields->psi[psiindex][0][0] = 0.0; } @@ -407,27 +407,27 @@ BARRIER(bars->barrier,nprocs) fields->psi[psiindex][im-1][jm-1] = 0.0; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psi[psiindex][0][j] = 0.0; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psi[psiindex][im-1][j] = 0.0; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psi[psiindex][j][0] = 0.0; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psi[psiindex][j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields->psi[psiindex][i][iindex] = 0.0; } } @@ -454,7 +454,7 @@ BARRIER(bars->barrier,nprocs) frcng->tauz[im-1][jm-1] = frcng->tauz[0][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { sintemp = pi*((double) j)*res/ysca1; sintemp = sin(sintemp); curlt = factor*sintemp; @@ -462,7 +462,7 @@ BARRIER(bars->barrier,nprocs) } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { sintemp = pi*((double) j)*res/ysca1; sintemp = sin(sintemp); curlt = factor*sintemp; @@ -470,7 +470,7 @@ BARRIER(bars->barrier,nprocs) } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { frcng->tauz[j][0] = 0.0; } } @@ -478,15 +478,15 @@ BARRIER(bars->barrier,nprocs) sintemp = pi*((double) jmm1)*res/ysca1; sintemp = sin(sintemp); curlt = factor*sintemp; - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { frcng->tauz[j][jm-1] = curlt; } } - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { sintemp = pi*((double) iindex)*res/ysca1; sintemp = sin(sintemp); curlt = factor*sintemp; - for (i=firstrow;i<=lastrow;i++) { + for(i=firstrow;i<=lastrow;i++) { frcng->tauz[i][iindex] = curlt; } } @@ -531,7 +531,7 @@ BARRIER(bars->barrier,nprocs) iday = (long) day; dhour = dhour+dtau; if (dhour >= 86400.0) { - dhourflag = 1; + dhourflag = 1; } } } @@ -552,27 +552,27 @@ BARRIER(bars->barrier,nprocs) fields2->psium[im-1][jm-1] = fields2->psium[im-1][jm-1]+fields->psim[0][im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields2->psium[0][j] = fields2->psium[0][j]+fields->psim[0][0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields2->psium[im-1][j] = fields2->psium[im-1][j]+fields->psim[0][im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields2->psium[j][0] = fields2->psium[j][0]+fields->psim[0][j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields2->psium[j][jm-1] = fields2->psium[j][jm-1]+fields->psim[0][j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields2->psium[i][iindex] = fields2->psium[i][iindex]+fields->psim[0][i][iindex]; } } @@ -592,27 +592,27 @@ BARRIER(bars->barrier,nprocs) fields2->psilm[im-1][jm-1] = fields2->psilm[im-1][jm-1]+fields->psim[1][im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields2->psilm[0][j] = fields2->psilm[0][j]+fields->psim[1][0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields2->psilm[im-1][j] = fields2->psilm[im-1][j]+fields->psim[1][im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields2->psilm[j][0] = fields2->psilm[j][0]+fields->psim[1][j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields2->psilm[j][jm-1] = fields2->psilm[j][jm-1]+fields->psim[1][j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields2->psilm[i][iindex] = fields2->psilm[i][iindex]+fields->psim[1][i][iindex]; } } diff --git a/splash2/codes/apps/ocean/non_contiguous_partitions/slave2.C b/splash2/codes/apps/ocean/non_contiguous_partitions/slave2.C index 83fda925b..a855eec77 100644 --- a/splash2/codes/apps/ocean/non_contiguous_partitions/slave2.C +++ b/splash2/codes/apps/ocean/non_contiguous_partitions/slave2.C @@ -18,11 +18,10 @@ subroutine slave2 **************** */ -#include -#include -#include -#include - +#include +#include +#include +#include #include "decs.h" void slave2(long procid, long firstrow, long lastrow, long numrows, long firstcol, long lastcol, long numcols) @@ -72,27 +71,27 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk1->ga[im-1][jm-1]=0.0; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->ga[0][j] = 0.0; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->ga[im-1][j] = 0.0; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->ga[j][0] = 0.0; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->ga[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk1->ga[i][iindex] = 0.0; } } @@ -110,27 +109,27 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk1->gb[im-1][jm-1]=0.0; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->gb[0][j] = 0.0; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->gb[im-1][j] = 0.0; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->gb[j][0] = 0.0; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->gb[j][jm-1] = 0.0; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk1->gb[i][iindex] = 0.0; } } @@ -139,7 +138,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco note that psi(i,j,2) represents the psi3 array in the original equations */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { if (procid == MASTER) { wrk3->work1[psiindex][0][0] = 0; } @@ -153,8 +152,8 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk3->work1[psiindex][im-1][jm-1] = 0; } laplacalc(fields->psi[psiindex], - wrk3->work1[psiindex], - firstrow,lastrow,firstcol,lastcol,numrows,numcols); + wrk3->work1[psiindex], + firstrow,lastrow,firstcol,lastcol,numrows,numcols); } @@ -172,27 +171,27 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk3->work2[im-1][jm-1] = fields->psi[0][im-1][jm-1]-fields->psi[1][im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk3->work2[0][j] = fields->psi[0][0][j]-fields->psi[1][0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk3->work2[im-1][j] = fields->psi[0][im-1][j]-fields->psi[1][im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk3->work2[j][0] = fields->psi[0][j][0]-fields->psi[1][j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk3->work2[j][jm-1] = fields->psi[0][j][jm-1]-fields->psi[1][j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk3->work2[i][iindex] = fields->psi[0][i][iindex]-fields->psi[1][i][iindex]; } } @@ -214,34 +213,34 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk2->work3[im-1][jm-1] = hh3*fields->psi[0][im-1][jm-1]+hh1*fields->psi[1][im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk2->work3[0][j] = hh3*fields->psi[0][0][j]+hh1*fields->psi[1][0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk2->work3[im-1][j] = hh3*fields->psi[0][im-1][j]+hh1*fields->psi[1][im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk2->work3[j][0] = hh3*fields->psi[0][j][0]+hh1*fields->psi[1][j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk2->work3[j][jm-1] = hh3*fields->psi[0][j][jm-1]+hh1*fields->psi[1][j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk2->work3[i][iindex] = hh3*fields->psi[0][i][iindex]+hh1*fields->psi[1][i][iindex]; } } /* set values of temparray{1,3} to psim{1,3} */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { if (procid == MASTER) { wrk5->temparray[psiindex][0][0] = fields->psi[psiindex][0][0]; } @@ -255,28 +254,28 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk5->temparray[psiindex][im-1][jm-1] = fields->psi[psiindex][im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk5->temparray[psiindex][0][j] = fields->psi[psiindex][0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk5->temparray[psiindex][im-1][j] = fields->psi[psiindex][im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk5->temparray[psiindex][j][0] = fields->psi[psiindex][j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk5->temparray[psiindex][j][jm-1] = fields->psi[psiindex][j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk5->temparray[psiindex][i][iindex] = fields->psi[psiindex][i][iindex]; } } @@ -294,7 +293,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco set values of psi{1,3} to psim{1,3} */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { if (procid == MASTER) { fields->psi[psiindex][0][0] = fields->psim[psiindex][0][0]; } @@ -308,28 +307,28 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco fields->psi[psiindex][im-1][jm-1] = fields->psim[psiindex][im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psi[psiindex][0][j] = fields->psim[psiindex][0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psi[psiindex][im-1][j] = fields->psim[psiindex][im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psi[psiindex][j][0] = fields->psim[psiindex][j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psi[psiindex][j][jm-1] = fields->psim[psiindex][j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields->psi[psiindex][i][iindex] = fields->psim[psiindex][i][iindex]; } } @@ -339,7 +338,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco into the work7 array; first part of a three-laplacian calculation to compute the friction terms */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { if (procid == MASTER) { wrk5->work7[psiindex][0][0] = 0; } @@ -360,7 +359,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco elements of every column the corresponding value in the one-dimenional f array */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { if (procid == MASTER) { wrk3->work1[psiindex][0][0] = wrk3->work1[psiindex][0][0] + wrk2->f[0]; } @@ -374,29 +373,29 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk3->work1[psiindex][im-1][jm-1] = wrk3->work1[psiindex][im-1][jm-1] + wrk2->f[jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk3->work1[psiindex][0][j] = wrk3->work1[psiindex][0][j] + wrk2->f[j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk3->work1[psiindex][im-1][j] = wrk3->work1[psiindex][im-1][j] + wrk2->f[j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk3->work1[psiindex][j][0] = wrk3->work1[psiindex][j][0] + wrk2->f[j]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk3->work1[psiindex][j][jm-1] = wrk3->work1[psiindex][j][jm-1] + wrk2->f[j]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk3->work1[psiindex][i][iindex] = wrk3->work1[psiindex][i][iindex] + - wrk2->f[iindex]; + wrk2->f[iindex]; } } } @@ -409,12 +408,12 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco t h i r d p h a s e - ******************************************************* + ******************************************************* put the jacobian of the work1{1,2} and psi{1,3} arrays (the latter currently in temparray) in the work5{1,2} arrays */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { jacobcalc(wrk3->work1[psiindex],wrk5->temparray[psiindex], wrk4->work5[psiindex],procid,firstrow,lastrow,firstcol,lastcol,numrows,numcols); } @@ -422,7 +421,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco /* set values of psim{1,3} to temparray{1,3} */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { if (procid == MASTER) { fields->psim[psiindex][0][0] = wrk5->temparray[psiindex][0][0]; } @@ -436,27 +435,27 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco fields->psim[psiindex][im-1][jm-1] = wrk5->temparray[psiindex][im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psim[psiindex][0][j] = wrk5->temparray[psiindex][0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psim[psiindex][im-1][j] = wrk5->temparray[psiindex][im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psim[psiindex][j][0] = wrk5->temparray[psiindex][j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psim[psiindex][j][jm-1] = wrk5->temparray[psiindex][j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields->psim[psiindex][i][iindex] = wrk5->temparray[psiindex][i][iindex]; } } @@ -465,9 +464,9 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco /* put the laplacian of the work7{1,2} arrays in the work4{1,2} arrays; second step in the three-laplacian friction calculation */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { laplacalc(wrk5->work7[psiindex], - wrk4->work4[psiindex], + wrk4->work4[psiindex], firstrow,lastrow,firstcol,lastcol,numrows,numcols); } #if defined(MULTIPLE_BARRIERS) @@ -490,7 +489,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco /* put the laplacian of the work4{1,2} arrays in the work7{1,2} arrays; third step in the three-laplacian friction calculation */ - for (psiindex=0;psiindex<=1;psiindex++) { + for(psiindex=0;psiindex<=1;psiindex++) { laplacalc(wrk4->work4[psiindex], wrk5->work7[psiindex], firstrow,lastrow,firstcol,lastcol,numrows,numcols); @@ -535,10 +534,10 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk1->ga[im-1][jm-1] = wrk4->work5[0][im-1][jm-1]-wrk4->work5[1][im-1][jm-1]+eig2*wrk6->work6[im-1][jm-1]+ h1inv*frcng->tauz[im-1][jm-1]+lf*wrk5->work7[0][im-1][jm-1]-lf*wrk5->work7[1][im-1][jm-1]; wrk1->gb[im-1][jm-1] = hh1*wrk4->work5[0][im-1][jm-1]+hh3*wrk4->work5[1][im-1][jm-1]+hinv* - frcng->tauz[im-1][jm-1]+lf*hh1*wrk5->work7[0][im-1][jm-1]+lf*hh3*wrk5->work7[1][im-1][jm-1]; + frcng->tauz[im-1][jm-1]+lf*hh1*wrk5->work7[0][im-1][jm-1]+lf*hh3*wrk5->work7[1][im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->ga[0][j] = wrk4->work5[0][0][j]-wrk4->work5[1][0][j]+eig2* wrk6->work6[0][j]+h1inv*frcng->tauz[0][j]+lf*wrk5->work7[0][0][j]-lf*wrk5->work7[0][0][j]; wrk1->gb[0][j] = hh1*wrk4->work5[0][0][j]+hh3*wrk4->work5[1][0][j]+hinv* @@ -546,7 +545,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->ga[im-1][j] = wrk4->work5[0][im-1][j]-wrk4->work5[1][im-1][j]+eig2* wrk6->work6[im-1][j]+h1inv*frcng->tauz[im-1][j]+ lf*wrk5->work7[0][im-1][j]-lf*wrk5->work7[1][im-1][j]; @@ -556,7 +555,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->ga[j][0] = wrk4->work5[0][j][0]-wrk4->work5[1][j][0]+eig2* wrk6->work6[j][0]+h1inv*frcng->tauz[j][0]+lf*wrk5->work7[0][j][0]-lf*wrk5->work7[1][j][0]; wrk1->gb[j][0] = hh1*wrk4->work5[0][j][0]+hh3*wrk4->work5[1][j][0]+hinv* @@ -564,7 +563,7 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->ga[j][jm-1] = wrk4->work5[0][j][jm-1]-wrk4->work5[1][j][jm-1]+eig2* wrk6->work6[j][jm-1]+h1inv*frcng->tauz[j][jm-1]+ lf*wrk5->work7[0][j][jm-1]-lf*wrk5->work7[1][j][jm-1]; @@ -573,8 +572,8 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco lf*hh3*wrk5->work7[1][j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk1->ga[i][iindex] = wrk4->work5[0][i][iindex]-wrk4->work5[1][i][iindex]+eig2* wrk6->work6[i][iindex]+h1inv*frcng->tauz[i][iindex]+ lf*wrk5->work7[0][i][iindex]-lf*wrk5->work7[1][i][iindex]; @@ -614,35 +613,35 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco if (jend == jm-2) { jend = jm-1; } - for (i=istart;i<=iend;i++) { - for (j=jstart;j<=jend;j++) { + for(i=istart;i<=iend;i++) { + for(j=jstart;j<=jend;j++) { multi->rhs_multi[numlev-1][i][j] = wrk1->ga[i][j] * ressqr; } } if (istart == 0) { - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { multi->q_multi[numlev-1][0][j] = wrk1->ga[0][j]; } } if (iend == im-1) { - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { multi->q_multi[numlev-1][im-1][j] = wrk1->ga[im-1][j]; } } if (jstart == 0) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { multi->q_multi[numlev-1][i][0] = wrk1->ga[i][0]; } } if (jend == jm-1) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { multi->q_multi[numlev-1][i][jm-1] = wrk1->ga[i][jm-1]; } } fac = 1.0 / (4.0 - ressqr*eig2); - for (i=ist;i<=ien;i++) { - for (j=jst;j<=jen;j++) { + for(i=ist;i<=ien;i++) { + for(j=jst;j<=jen;j++) { multi->q_multi[numlev-1][i][j] = guess->oldga[i][j]; } } @@ -664,8 +663,8 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco /* copy the solution for use as initial guess in next time-step */ - for (i=istart;i<=iend;i++) { - for (j=jstart;j<=jend;j++) { + for(i=istart;i<=iend;i++) { + for(j=jstart;j<=jend;j++) { wrk1->ga[i][j] = multi->q_multi[numlev-1][i][j]; guess->oldga[i][j] = multi->q_multi[numlev-1][i][j]; } @@ -700,27 +699,27 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco psiaipriv=psiaipriv+0.25*(wrk1->ga[im-1][jm-1]); } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { psiaipriv = psiaipriv + 0.5*wrk1->ga[0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { psiaipriv = psiaipriv + 0.5*wrk1->ga[im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { psiaipriv = psiaipriv + 0.5*wrk1->ga[j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { psiaipriv = psiaipriv + 0.5*wrk1->ga[j][jm-1]; } } - for (iindex=firstcol;iindex<=lastcol;iindex++) { - for (i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { psiaipriv = psiaipriv + wrk1->ga[i][iindex]; } } @@ -761,27 +760,27 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk1->ga[im-1][jm-1] = wrk1->ga[im-1][jm-1]+f4*wrk1->psib[im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->ga[0][j] = wrk1->ga[0][j]+f4*wrk1->psib[0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk1->ga[im-1][j] = wrk1->ga[im-1][j]+f4*wrk1->psib[im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->ga[j][0] = wrk1->ga[j][0]+f4*wrk1->psib[j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk1->ga[j][jm-1] = wrk1->ga[j][jm-1]+f4*wrk1->psib[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk1->ga[i][iindex] = wrk1->ga[i][iindex]+f4*wrk1->psib[i][iindex]; } } @@ -790,35 +789,35 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco #else BARRIER(bars->barrier,nprocs) #endif - for (i=istart;i<=iend;i++) { - for (j=jstart;j<=jend;j++) { + for(i=istart;i<=iend;i++) { + for(j=jstart;j<=jend;j++) { multi->rhs_multi[numlev-1][i][j] = wrk1->gb[i][j] * ressqr; } } if (istart == 0) { - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { multi->q_multi[numlev-1][0][j] = wrk1->gb[0][j]; } } if (iend == im-1) { - for (j=jstart;j<=jend;j++) { + for(j=jstart;j<=jend;j++) { multi->q_multi[numlev-1][im-1][j] = wrk1->gb[im-1][j]; } } if (jstart == 0) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { multi->q_multi[numlev-1][i][0] = wrk1->gb[i][0]; } } if (jend == jm-1) { - for (i=istart;i<=iend;i++) { + for(i=istart;i<=iend;i++) { multi->q_multi[numlev-1][i][jm-1] = wrk1->gb[i][jm-1]; } } fac = 1.0 / (4.0 - ressqr*eig2); - for (i=ist;i<=ien;i++) { - for (j=jst;j<=jen;j++) { + for(i=ist;i<=ien;i++) { + for(j=jst;j<=jen;j++) { multi->q_multi[numlev-1][i][j] = guess->oldgb[i][j]; } } @@ -834,8 +833,8 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco gp[procid].multi_time += (multi_end - multi_start); } - for (i=istart;i<=iend;i++) { - for (j=jstart;j<=jend;j++) { + for(i=istart;i<=iend;i++) { + for(j=jstart;j<=jend;j++) { wrk1->gb[i][j] = multi->q_multi[numlev-1][i][j]; guess->oldgb[i][j] = multi->q_multi[numlev-1][i][j]; } @@ -877,32 +876,32 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco wrk2->work3[im-1][jm-1] = wrk1->gb[im-1][jm-1]+hh3*wrk1->ga[im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk2->work3[0][j] = wrk1->gb[0][j]+hh3*wrk1->ga[0][j]; wrk3->work2[0][j] = wrk1->gb[0][j]-hh1*wrk1->ga[0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { wrk2->work3[im-1][j] = wrk1->gb[im-1][j]+hh3*wrk1->ga[im-1][j]; wrk3->work2[im-1][j] = wrk1->gb[im-1][j]-hh1*wrk1->ga[im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk2->work3[j][0] = wrk1->gb[j][0]+hh3*wrk1->ga[j][0]; wrk3->work2[j][0] = wrk1->gb[j][0]-hh1*wrk1->ga[j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { wrk2->work3[j][jm-1] = wrk1->gb[j][jm-1]+hh3*wrk1->ga[j][jm-1]; wrk3->work2[j][jm-1] = wrk1->gb[j][jm-1]-hh1*wrk1->ga[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { wrk2->work3[i][iindex] = wrk1->gb[i][iindex]+hh3*wrk1->ga[i][iindex]; wrk3->work2[i][iindex] = wrk1->gb[i][iindex]-hh1*wrk1->ga[i][iindex]; } @@ -936,27 +935,27 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco fields->psi[0][im-1][jm-1] = fields->psi[0][im-1][jm-1] + timst*wrk2->work3[im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psi[0][0][j] = fields->psi[0][0][j] + timst*wrk2->work3[0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psi[0][im-1][j] = fields->psi[0][im-1][j] + timst*wrk2->work3[im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psi[0][j][0] = fields->psi[0][j][0] + timst*wrk2->work3[j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psi[0][j][jm-1] = fields->psi[0][j][jm-1] + timst*wrk2->work3[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields->psi[0][i][iindex] = fields->psi[0][i][iindex] + timst*wrk2->work3[i][iindex]; } } @@ -974,28 +973,28 @@ void slave2(long procid, long firstrow, long lastrow, long numrows, long firstco fields->psi[1][im-1][jm-1] = fields->psi[1][im-1][jm-1] + timst*wrk3->work2[im-1][jm-1]; } if (firstrow == 1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psi[1][0][j] = fields->psi[1][0][j] + timst*wrk3->work2[0][j]; } } if ((firstrow+numrows) == im-1) { - for (j=firstcol;j<=lastcol;j++) { + for(j=firstcol;j<=lastcol;j++) { fields->psi[1][im-1][j] = fields->psi[1][im-1][j] + timst*wrk3->work2[im-1][j]; } } if (firstcol == 1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psi[1][j][0] = fields->psi[1][j][0] + timst*wrk3->work2[j][0]; } } if ((firstcol+numcols) == jm-1) { - for (j=firstrow;j<=lastrow;j++) { + for(j=firstrow;j<=lastrow;j++) { fields->psi[1][j][jm-1] = fields->psi[1][j][jm-1] + timst*wrk3->work2[j][jm-1]; } } - for (i=firstrow;i<=lastrow;i++) { - for (iindex=firstcol;iindex<=lastcol;iindex++) { + for(i=firstrow;i<=lastrow;i++) { + for(iindex=firstcol;iindex<=lastcol;iindex++) { fields->psi[1][i][iindex] = fields->psi[1][i][iindex] + timst*wrk3->work2[i][iindex]; } } diff --git a/splash2/codes/apps/radiosity/display.C b/splash2/codes/apps/radiosity/display.C index 46806d197..eca0050cc 100644 --- a/splash2/codes/apps/radiosity/display.C +++ b/splash2/codes/apps/radiosity/display.C @@ -14,7 +14,7 @@ /* */ /*************************************************************************/ -#include +#include EXTERN_ENV; @@ -37,7 +37,7 @@ void radiosity_averaging(Element *elem, long mode, long process_id) Vertex pc ; long reverse ; - if ( ! LEAF_ELEMENT(elem) ) + if( ! LEAF_ELEMENT(elem) ) { create_radavg_task( elem->center, mode, process_id ) ; create_radavg_task( elem->top, mode, process_id ) ; @@ -46,7 +46,7 @@ void radiosity_averaging(Element *elem, long mode, long process_id) return ; } - else if ( mode == RAD_AVERAGING_MODE ) + else if( mode == RAD_AVERAGING_MODE ) { /* Compute center point */ center_point( &elem->ev1->p, &elem->ev2->p, &elem->ev3->p, &pc ) ; @@ -62,7 +62,7 @@ void radiosity_averaging(Element *elem, long mode, long process_id) { /* Normalize it */ LOCK(elem->ev1->ev_lock->lock); - if ( elem->ev1->weight != 1.0 ) + if( elem->ev1->weight != 1.0 ) { inv_weight = (float)1.0 / elem->ev1->weight ; elem->ev1->col.r *= inv_weight ; @@ -73,7 +73,7 @@ void radiosity_averaging(Element *elem, long mode, long process_id) UNLOCK(elem->ev1->ev_lock->lock); LOCK(elem->ev2->ev_lock->lock); - if ( elem->ev2->weight != 1.0 ) + if( elem->ev2->weight != 1.0 ) { inv_weight = (float)1.0 / elem->ev2->weight ; elem->ev2->col.r *= inv_weight ; @@ -84,7 +84,7 @@ void radiosity_averaging(Element *elem, long mode, long process_id) UNLOCK(elem->ev2->ev_lock->lock); LOCK(elem->ev3->ev_lock->lock); - if ( elem->ev3->weight != 1.0 ) + if( elem->ev3->weight != 1.0 ) { inv_weight = (float)1.0 / elem->ev3->weight ; elem->ev3->col.r *= inv_weight ; @@ -101,7 +101,7 @@ static void add_radiosity_to_vertex(Edge *edge, long reverse, Element *elem, Ver ElemVertex *ev ; float weight ; - if ( reverse ) + if( reverse ) ev = edge->pb ; else ev = edge->pa ; @@ -176,28 +176,28 @@ void display_scene(long fill_sw, long patch_sw, long mesh_sw, long interaction_s /* Set matrix */ g_setup_view( view_rot_x, view_rot_y, view_dist, view_zoom ) ; - if ( fill_sw == 2 ) + if( fill_sw == 2 ) { /* Fill surfaces */ display_elements_in_bsp_tree( DISPLAY_SHADED, process_id ) ; } - if ( fill_sw == 1 ) + if( fill_sw == 1 ) { /* Fill surfaces */ display_elements_in_bsp_tree( DISPLAY_FILLED, process_id ) ; } - if ( mesh_sw ) + if( mesh_sw ) { /* Draw mesh */ g_color( G_BLUE ) ; display_elements_in_bsp_tree( DISPLAY_EDGEONLY, process_id ) ; } - if ( patch_sw ) + if( patch_sw ) { g_color( G_RED ) ; display_patches_in_bsp_tree( DISPLAY_EDGEONLY, process_id ) ; } - if ( interaction_sw ) + if( interaction_sw ) { g_color( G_GREEN ) ; display_interactions_in_bsp_tree(process_id) ; @@ -218,9 +218,9 @@ void display_patch(Patch *patch, long mode, long process_id) Vertex p_buf[4] ; Rgb c_buf[4] ; - if ( mode == DISPLAY_SHADED ) + if( mode == DISPLAY_SHADED ) { - if ( inner_product( &patch->plane_equ.n, &view_vec ) < F_ZERO ) + if( inner_product( &patch->plane_equ.n, &view_vec ) < F_ZERO ) return ; p_buf[0] = patch->p1 ; @@ -232,9 +232,9 @@ void display_patch(Patch *patch, long mode, long process_id) g_spolygon( 3, p_buf, c_buf ) ; } - else if ( mode == DISPLAY_FILLED ) + else if( mode == DISPLAY_FILLED ) { - if ( inner_product( &patch->plane_equ.n, &view_vec ) < F_ZERO ) + if( inner_product( &patch->plane_equ.n, &view_vec ) < F_ZERO ) return ; p_buf[0] = patch->p1 ; @@ -275,16 +275,16 @@ void display_element(Element *element, long mode, long process_id) { Vertex p_buf[4] ; - if ( inner_product( &element->patch->plane_equ.n, &view_vec ) < F_ZERO ) + if( inner_product( &element->patch->plane_equ.n, &view_vec ) < F_ZERO ) return ; - if ( mode == DISPLAY_SHADED ) + if( mode == DISPLAY_SHADED ) { _display_shaded_triangle( element->ev1, element->ev2, element->ev3, element->e12, element->e23, element->e31, process_id ) ; } - else if ( mode == DISPLAY_FILLED ) + else if( mode == DISPLAY_FILLED ) { g_rgb( element->rad ) ; p_buf[0] = element->ev1->p ; @@ -361,7 +361,7 @@ static void _disp_interactions(Element *elem, Interaction *inter, long mode, lon /* Display interactions only with a particular patch */ - if ( (mode == DISPLAY_HALF_INTERACTIONS) + if( (mode == DISPLAY_HALF_INTERACTIONS) && (inter->destination->patch->seq_no >= elem->patch->seq_no ) ) return ; @@ -417,24 +417,24 @@ void display_interactions_in_bsp_tree(long process_id) void ps_display_scene(long fill_sw, long patch_sw, long mesh_sw, long interaction_sw, long process_id) { - if ( fill_sw ) + if( fill_sw ) { /* Fill surfaces */ ps_display_elements_in_bsp_tree( DISPLAY_SHADED, process_id ) ; } - if ( mesh_sw ) + if( mesh_sw ) { /* Draw mesh */ ps_linewidth( 0.5 ) ; ps_display_elements_in_bsp_tree( DISPLAY_EDGEONLY, process_id ) ; } - if ( patch_sw ) + if( patch_sw ) { /* Draw patches */ ps_linewidth( 1.2 ) ; ps_display_patches_in_bsp_tree( DISPLAY_EDGEONLY, process_id ) ; } - if ( interaction_sw ) + if( interaction_sw ) { /* Draw interactions */ ps_linewidth( 0.2 ) ; @@ -454,9 +454,9 @@ void ps_display_patch(Patch *patch, long mode, long process_id) Vertex p_buf[4] ; Rgb c_buf[4] ; - if ( mode == DISPLAY_SHADED ) + if( mode == DISPLAY_SHADED ) { - if ( inner_product( &patch->plane_equ.n, &view_vec ) < F_ZERO ) + if( inner_product( &patch->plane_equ.n, &view_vec ) < F_ZERO ) return ; p_buf[0] = patch->p1 ; p_buf[1] = patch->p2 ; @@ -467,9 +467,9 @@ void ps_display_patch(Patch *patch, long mode, long process_id) ps_spolygon( 3, p_buf, c_buf ) ; } - else if ( mode == DISPLAY_FILLED ) + else if( mode == DISPLAY_FILLED ) { - if ( inner_product( &patch->plane_equ.n, &view_vec ) < F_ZERO ) + if( inner_product( &patch->plane_equ.n, &view_vec ) < F_ZERO ) return ; p_buf[0] = patch->p1 ; p_buf[1] = patch->p2 ; @@ -512,9 +512,9 @@ void ps_display_element(Element *element, long mode, long process_id) Vertex p_buf[4] ; Rgb c_buf[4] ; - if ( mode == DISPLAY_SHADED ) + if( mode == DISPLAY_SHADED ) { - if ( inner_product( &element->patch->plane_equ.n, &view_vec ) + if( inner_product( &element->patch->plane_equ.n, &view_vec ) < F_ZERO ) return ; p_buf[0] = element->ev1->p ; @@ -526,9 +526,9 @@ void ps_display_element(Element *element, long mode, long process_id) ps_spolygon( 3, p_buf, c_buf ) ; } - else if ( mode == DISPLAY_FILLED ) + else if( mode == DISPLAY_FILLED ) { - if ( inner_product( &element->patch->plane_equ.n, &view_vec ) + if( inner_product( &element->patch->plane_equ.n, &view_vec ) < F_ZERO ) return ; p_buf[0] = element->ev1->p ; @@ -589,7 +589,7 @@ static void _ps_disp_interactions(Element *elem, Interaction *inter, long mode, Element *edst ; /* Display interactions only with a particular patch */ - if ( (mode == DISPLAY_HALF_INTERACTIONS) + if( (mode == DISPLAY_HALF_INTERACTIONS) && (inter->destination->patch->seq_no >= elem->patch->seq_no ) ) return ; diff --git a/splash2/codes/apps/radiosity/elemman.C b/splash2/codes/apps/radiosity/elemman.C index d060e4592..5cc9b42f0 100644 --- a/splash2/codes/apps/radiosity/elemman.C +++ b/splash2/codes/apps/radiosity/elemman.C @@ -23,7 +23,7 @@ */ -#include +#include EXTERN_ENV; @@ -65,11 +65,11 @@ void foreach_element_in_patch(Patch *patch, void (*func)(), long arg1, long pro static void _foreach_element(Element *elem, void (*func)(), long arg1, long process_id) { - if ( elem == 0 ) + if( elem == 0 ) return ; /* Process children */ - if ( ! LEAF_ELEMENT( elem ) ) + if( ! LEAF_ELEMENT( elem ) ) { _foreach_element( elem->center, func, arg1, process_id ) ; _foreach_element( elem->top, func, arg1, process_id ) ; @@ -90,11 +90,11 @@ void foreach_leaf_element_in_patch(Patch *patch, void (*func)(), long arg1, lon static void _foreach_leaf_element(Element *elem, void (*func)(), long arg1, long process_id ) { - if ( elem == 0 ) + if( elem == 0 ) return ; /* Process children */ - if ( LEAF_ELEMENT( elem ) ) + if( LEAF_ELEMENT( elem ) ) func( elem, arg1, process_id ) ; else { @@ -141,11 +141,11 @@ void ff_refine_elements(Element *e1, Element *e2, long level, long process_id) subdiv_advice = error_analysis( e1, e2, &i12, &i21, process_id ) ; /* Execute subdivision procedure */ - if ( NO_INTERACTION(subdiv_advice) ) + if( NO_INTERACTION(subdiv_advice) ) /* Two elements are mutually invisible. Do nothing */ return ; - else if ( NO_REFINEMENT_NECESSARY(subdiv_advice) ) + else if( NO_REFINEMENT_NECESSARY(subdiv_advice) ) { /* Create links and finish the job */ inter = get_interaction(process_id) ; @@ -162,12 +162,12 @@ void ff_refine_elements(Element *e1, Element *e2, long level, long process_id) /* Update cost variable */ pc1 = &global->patch_cost[ e1->patch->seq_no ] ; pc2 = &global->patch_cost[ e2->patch->seq_no ] ; - if ( pc1->n_total_inter <= 13 ) + if( pc1->n_total_inter <= 13 ) cost1 = (long)ceil(e1->area / Area_epsilon) ; else cost1 = 1 ; - if ( pc2->n_total_inter <= 13 ) + if( pc2->n_total_inter <= 13 ) cost2 = (long)ceil(e2->area / Area_epsilon) ; else cost2 = 1 ; @@ -183,7 +183,7 @@ void ff_refine_elements(Element *e1, Element *e2, long level, long process_id) #endif } - else if ( REFINE_PATCH_1(subdiv_advice) ) + else if( REFINE_PATCH_1(subdiv_advice) ) { /* Refine patch 1 */ subdivide_element( e1, process_id ) ; @@ -224,13 +224,13 @@ long error_analysis(Element *e1, Element *e2, Interaction *inter12, Interaction /* Check visibility */ cc = patch_intersection( &e1->patch->plane_equ, &e2->ev1->p, &e2->ev2->p, &e2->ev3->p, process_id ) ; - if ( NEGATIVE_SIDE(cc) ) + if( NEGATIVE_SIDE(cc) ) /* If negative or on the plane, then do nothing */ return( _NO_INTERACTION ) ; cc = patch_intersection( &e2->patch->plane_equ, &e1->ev1->p, &e1->ev2->p, &e1->ev3->p, process_id ) ; - if ( NEGATIVE_SIDE(cc) ) + if( NEGATIVE_SIDE(cc) ) /* If negative or on the plane, then do nothing */ return( _NO_INTERACTION ) ; @@ -261,14 +261,14 @@ static long bf_refine_element(long subdiv, Element *elem, Interaction *inter, l visibility_val = NO_VISIBILITY_NECESSARY(subdiv)? (float)1.0 : VISIBILITY_UNDEF ; - if ( REFINE_PATCH_1(subdiv) ) + if( REFINE_PATCH_1(subdiv) ) { /* Refine this element */ /* (1) Make sure it has children */ subdivide_element( elem, process_id ) ; /* (2) For each of the patch, create an interaction */ - if ( element_completely_invisible( elem->center, e_dst, process_id ) == 0 ) + if( element_completely_invisible( elem->center, e_dst, process_id ) == 0 ) { pi = get_interaction(process_id) ; compute_formfactor( elem->center, e_dst, pi, process_id ) ; @@ -276,7 +276,7 @@ static long bf_refine_element(long subdiv, Element *elem, Interaction *inter, l insert_vis_undef_interaction( elem->center, pi, process_id ) ; new_inter++ ; } - if ( element_completely_invisible( elem->top, e_dst, process_id ) == 0 ) + if( element_completely_invisible( elem->top, e_dst, process_id ) == 0 ) { pi = get_interaction(process_id) ; compute_formfactor( elem->top, e_dst, pi, process_id ) ; @@ -284,7 +284,7 @@ static long bf_refine_element(long subdiv, Element *elem, Interaction *inter, l insert_vis_undef_interaction( elem->top, pi, process_id ) ; new_inter++ ; } - if ( element_completely_invisible( elem->left, e_dst, process_id ) == 0 ) + if( element_completely_invisible( elem->left, e_dst, process_id ) == 0 ) { pi = get_interaction(process_id) ; compute_formfactor( elem->left, e_dst, pi, process_id ) ; @@ -292,7 +292,7 @@ static long bf_refine_element(long subdiv, Element *elem, Interaction *inter, l insert_vis_undef_interaction( elem->left, pi, process_id ) ; new_inter++ ; } - if ( element_completely_invisible( elem->right, e_dst, process_id ) == 0 ) + if( element_completely_invisible( elem->right, e_dst, process_id ) == 0 ) { pi = get_interaction(process_id) ; compute_formfactor( elem->right, e_dst, pi, process_id ) ; @@ -311,7 +311,7 @@ static long bf_refine_element(long subdiv, Element *elem, Interaction *inter, l NOTE: Use *inter as a place holder to link 4 new interactions since *prev may be NULL */ - if ( element_completely_invisible( elem, e_dst->center, process_id ) == 0 ) + if( element_completely_invisible( elem, e_dst->center, process_id ) == 0 ) { pi = get_interaction(process_id) ; compute_formfactor( elem, e_dst->center, pi, process_id ) ; @@ -319,7 +319,7 @@ static long bf_refine_element(long subdiv, Element *elem, Interaction *inter, l insert_vis_undef_interaction( elem, pi, process_id ) ; new_inter++ ; } - if ( element_completely_invisible( elem, e_dst->top, process_id ) == 0 ) + if( element_completely_invisible( elem, e_dst->top, process_id ) == 0 ) { pi = get_interaction(process_id) ; compute_formfactor( elem, e_dst->top, pi, process_id ) ; @@ -327,7 +327,7 @@ static long bf_refine_element(long subdiv, Element *elem, Interaction *inter, l insert_vis_undef_interaction( elem, pi, process_id ) ; new_inter++ ; } - if ( element_completely_invisible( elem, e_dst->left, process_id ) == 0 ) + if( element_completely_invisible( elem, e_dst->left, process_id ) == 0 ) { pi = get_interaction(process_id) ; compute_formfactor( elem, e_dst->left, pi, process_id ) ; @@ -335,7 +335,7 @@ static long bf_refine_element(long subdiv, Element *elem, Interaction *inter, l insert_vis_undef_interaction( elem, pi, process_id ) ; new_inter++ ; } - if ( element_completely_invisible( elem, e_dst->right, process_id ) == 0 ) + if( element_completely_invisible( elem, e_dst->right, process_id ) == 0 ) { pi = get_interaction(process_id) ; compute_formfactor( elem, e_dst->right, pi, process_id ) ; @@ -372,12 +372,12 @@ void bf_error_analysis_list(Element *elem, Interaction *i_list, long process_id) long delta_n_inter = 0 ; - while ( inter ) + while( inter ) { /* Analyze error */ subdiv_advice = bf_error_analysis( elem, inter, process_id ) ; - if ( NO_REFINEMENT_NECESSARY(subdiv_advice) ) + if( NO_REFINEMENT_NECESSARY(subdiv_advice) ) { /* Go on to the next interaction */ prev = inter ; @@ -389,7 +389,7 @@ void bf_error_analysis_list(Element *elem, Interaction *i_list, long process_id) /* Remove this interaction from the list */ refine_inter = inter ; inter = inter->next ; - if ( prev == 0 ) + if( prev == 0 ) i_list = inter ; else prev->next = inter ; @@ -405,7 +405,7 @@ void bf_error_analysis_list(Element *elem, Interaction *i_list, long process_id) } /* Link good interactions to elem->intearctions */ - if ( i_len > 0 ) + if( i_len > 0 ) { LOCK(elem->elem_lock->lock); prev->next = elem->interactions ; @@ -416,7 +416,7 @@ void bf_error_analysis_list(Element *elem, Interaction *i_list, long process_id) #if PATCH_ASSIGNMENT == PATCH_ASSIGNMENT_COSTBASED /* Update patch interaction count */ - if ( delta_n_inter != 0 ) + if( delta_n_inter != 0 ) { Patch_Cost *pc ; @@ -453,7 +453,7 @@ long bf_error_analysis(Element *elem, Interaction *inter, long process_id) = B FV + B (Ferr V + F Verr + Ferr Verr) */ - if ( (0.0 < inter->visibility) && (inter->visibility < 1.0) ) + if( (0.0 < inter->visibility) && (inter->visibility < 1.0) ) visibility_error = 1.0 ; else visibility_error = FF_VISIBILITY_ERROR ; @@ -467,21 +467,21 @@ long bf_error_analysis(Element *elem, Interaction *inter, long process_id) + visibility_error * inter->formfactor_err) * rad_avg ; /* If BF is smaller than the threshold, then not subdivide */ - if ( (total_error <= BFepsilon) && (elem->n_interactions <= 10) ) + if( (total_error <= BFepsilon) && (elem->n_interactions <= 10) ) return( _NO_REFINEMENT_NECESSARY ) ; - else if ( total_error <= BFepsilon * 0.5 ) + else if( total_error <= BFepsilon * 0.5 ) return( _NO_REFINEMENT_NECESSARY ) ; /* Subdivide light source or receiver whichever is larger */ - if ( elem->area > inter->destination->area ) + if( elem->area > inter->destination->area ) { - if ( elem->area > Area_epsilon ) + if( elem->area > Area_epsilon ) /* Subdivide this element (receiver) */ return( _REFINE_PATCH_1 | vis_code ) ; } else { - if ( inter->destination->area > Area_epsilon ) + if( inter->destination->area > Area_epsilon ) /* Subdivide source element */ return( _REFINE_PATCH_2 | vis_code ) ; @@ -518,7 +518,7 @@ long radiosity_converged(long process_id) prev_total += 1.0e-4 ; difference = fabs( (current_total / prev_total) - (float)1.0 ) ; - if ( verbose_mode ) + if( verbose_mode ) { rad = global->total_energy ; rad.r /= global->total_patch_area ; @@ -531,7 +531,7 @@ long radiosity_converged(long process_id) printf( "Difference %.2f%%\n", difference * 100.0 ) ; } - if ( difference <= Energy_epsilon ) + if( difference <= Energy_epsilon ) return( 1 ) ; else return( 0 ) ; @@ -558,7 +558,7 @@ void subdivide_element(Element *e, long process_id) LOCK(e->elem_lock->lock); /* Check if the element already has children */ - if ( ! _LEAF_ELEMENT(e) ) + if( ! _LEAF_ELEMENT(e) ) { UNLOCK(e->elem_lock->lock); return ; @@ -710,7 +710,7 @@ void process_rays(Element *e, long process_id) /* For each interaction, do BF-error-analysis */ bf_error_analysis_list( e, i_list, process_id ) ; - if ( e->n_vis_undef_inter == 0 ) + if( e->n_vis_undef_inter == 0 ) process_rays3( e, process_id ) ; else /* Some interactions were refined. @@ -736,7 +736,7 @@ static void process_rays2(Element *e, long process_id) /* For each interaction, do BF-error-analysis */ bf_error_analysis_list( e, i_list, process_id ) ; - if ( e->n_vis_undef_inter == 0 ) + if( e->n_vis_undef_inter == 0 ) process_rays3( e, process_id ) ; else /* Some interactions were refined. @@ -755,7 +755,7 @@ static void process_rays3(Element *e, long process_id) gather_rays( e, process_id ) ; /* Now visit children */ - if ( ! LEAF_ELEMENT(e) ) + if( ! LEAF_ELEMENT(e) ) { /* Compute radiosity that is pushed to descendents */ rad_push.r = e->rad_in.r + e->rad_subtree.r ; @@ -822,7 +822,7 @@ static void elem_join_operation(Element *e, Element *ec, long process_id) #endif - while ( e != 0 ) + while( e != 0 ) { /* Get radiosity of the child and add to my radiosity */ LOCK(e->elem_lock->lock); @@ -833,7 +833,7 @@ static void elem_join_operation(Element *e, Element *ec, long process_id) join_flag = (e->join_counter == 0) ; UNLOCK(e->elem_lock->lock); - if ( join_flag == 0 ) + if( join_flag == 0 ) /* Other children are not finished. Return. */ return ; @@ -892,7 +892,7 @@ static void gather_rays(Element *elem, long process_id) /* Return immediately if there is no interaction */ - if ( (inter = elem->interactions) == 0 ) + if( (inter = elem->interactions) == 0 ) { elem->rad_subtree.r = 0.0 ; elem->rad_subtree.g = 0.0 ; @@ -907,7 +907,7 @@ static void gather_rays(Element *elem, long process_id) rad_elem.g = 0.0 ; rad_elem.b = 0.0 ; - while ( inter ) + while( inter ) { /* Be careful ! Use FF(out) to compute incoming energy */ @@ -951,13 +951,13 @@ long element_completely_invisible(Element *e1, Element *e2, long process_id) /* Check visibility */ cc = patch_intersection( &e1->patch->plane_equ, &e2->ev1->p, &e2->ev2->p, &e2->ev3->p, process_id ) ; - if ( NEGATIVE_SIDE(cc) ) + if( NEGATIVE_SIDE(cc) ) /* If negative or on the plane, then do nothing */ return( 1 ) ; cc = patch_intersection( &e2->patch->plane_equ, &e1->ev1->p, &e1->ev2->p, &e1->ev3->p, process_id ) ; - if ( NEGATIVE_SIDE(cc) ) + if( NEGATIVE_SIDE(cc) ) /* If negative or on the plane, then do nothing */ return( 1 ) ; @@ -981,7 +981,7 @@ Element *get_element(long process_id) LOCK(global->free_element_lock); /* Test pointer */ - if ( global->free_element == 0 ) + if( global->free_element == 0 ) { printf( "Fatal: Ran out of element buffer\n" ) ; UNLOCK(global->free_element_lock); @@ -1049,7 +1049,7 @@ void init_elemlist(long process_id) long i ; /* Initialize Element free list */ - for ( i = 0 ; i < MAX_ELEMENTS-1 ; i++ ) + for( i = 0 ; i < MAX_ELEMENTS-1 ; i++ ) { global->element_buf[i].center = &global->element_buf[i+1] ; /* Initialize lock variable */ @@ -1110,10 +1110,10 @@ void foreach_interaction_in_element(Element *elem, void (*func)(), long arg1, lo { Interaction *inter ; - if ( elem == 0 ) + if( elem == 0 ) return ; - for ( inter = elem->interactions ; inter ; inter = inter->next ) + for( inter = elem->interactions ; inter ; inter = inter->next ) func( elem, inter, arg1, process_id ) ; } @@ -1147,18 +1147,18 @@ void compute_formfactor(Element *e_src, Element *e_dst, Interaction *inter, long ff_c1 = compute_diff_disc_formfactor( &pc1_src, e_src, &pc_dst, e_dst, process_id ) ; ff_c2 = compute_diff_disc_formfactor( &pc2_src, e_src, &pc_dst, e_dst, process_id ) ; ff_c3 = compute_diff_disc_formfactor( &pc3_src, e_src, &pc_dst, e_dst, process_id ) ; - if ( ff_c < 0 ) ff_c = 0 ; - if ( ff_c1 < 0 ) ff_c1 = 0 ; - if ( ff_c2 < 0 ) ff_c2 = 0 ; - if ( ff_c3 < 0 ) ff_c3 = 0 ; + if( ff_c < 0 ) ff_c = 0 ; + if( ff_c1 < 0 ) ff_c1 = 0 ; + if( ff_c2 < 0 ) ff_c2 = 0 ; + if( ff_c3 < 0 ) ff_c3 = 0 ; ff_avg = (ff_c + ff_c1 + ff_c2 + ff_c3) * (float)0.25 ; ff_min = ff_max = ff_c ; - if ( ff_min > ff_c1 ) ff_min = ff_c1 ; - if ( ff_min > ff_c2 ) ff_min = ff_c2 ; - if ( ff_min > ff_c3 ) ff_min = ff_c3 ; - if ( ff_max < ff_c1 ) ff_max = ff_c1 ; - if ( ff_max < ff_c2 ) ff_max = ff_c2 ; - if ( ff_max < ff_c3 ) ff_max = ff_c3 ; + if( ff_min > ff_c1 ) ff_min = ff_c1 ; + if( ff_min > ff_c2 ) ff_min = ff_c2 ; + if( ff_min > ff_c3 ) ff_min = ff_c3 ; + if( ff_max < ff_c1 ) ff_max = ff_c1 ; + if( ff_max < ff_c2 ) ff_max = ff_c2 ; + if( ff_max < ff_c3 ) ff_max = ff_c3 ; /* (2) Compute FF(diff-disc) from the 3 vertices of the source */ ff_1 = compute_diff_disc_formfactor( &e_src->ev1->p, e_src, @@ -1170,26 +1170,26 @@ void compute_formfactor(Element *e_src, Element *e_dst, Interaction *inter, long /* (3) Find FF min and max */ ff_min = ff_max = ff_c ; - if ( ff_min > ff_1 ) ff_min = ff_1 ; - if ( ff_min > ff_2 ) ff_min = ff_2 ; - if ( ff_min > ff_3 ) ff_min = ff_3 ; - if ( ff_max < ff_1 ) ff_max = ff_1 ; - if ( ff_max < ff_2 ) ff_max = ff_2 ; - if ( ff_max < ff_3 ) ff_max = ff_3 ; + if( ff_min > ff_1 ) ff_min = ff_1 ; + if( ff_min > ff_2 ) ff_min = ff_2 ; + if( ff_min > ff_3 ) ff_min = ff_3 ; + if( ff_max < ff_1 ) ff_max = ff_1 ; + if( ff_max < ff_2 ) ff_max = ff_2 ; + if( ff_max < ff_3 ) ff_max = ff_3 ; /* (4) Clip FF(diff-disc) if it is negative */ - if ( ff_avg < 0 ) + if( ff_avg < 0 ) ff_avg = 0 ; inter->formfactor_out = ff_avg ; /* (5) Then find maximum difference from the FF at the center */ ff_err = (ff_max - ff_avg) ; - if ( ff_err < (ff_avg - ff_min) ) + if( ff_err < (ff_avg - ff_min) ) ff_err = ff_avg - ff_min ; inter->formfactor_err = ff_err ; /* (6) Correct visibility if partially visible */ - if ( (ff_avg < 0) && (inter->visibility == 0) ) + if( (ff_avg < 0) && (inter->visibility == 0) ) /* All ray missed the visible portion of the elements. Set visibility to a non-zero value manually */ /** inter->visibility = FF_VISIBILITY_ERROR **/ ; @@ -1244,10 +1244,10 @@ static float compute_diff_disc_formfactor(Vertex *p, Element *e_src, Vertex *p_d ff_c3= _diff_disc_formfactor( p, e_src, &p_c3, quarter_area, &e_dst->patch->plane_equ.n, process_id ) ; - if ( ff_c < 0 ) ff_c = 0 ; - if ( ff_c1 < 0 ) ff_c1 = 0 ; - if ( ff_c2 < 0 ) ff_c2 = 0 ; - if ( ff_c3 < 0 ) ff_c3 = 0 ; + if( ff_c < 0 ) ff_c = 0 ; + if( ff_c1 < 0 ) ff_c1 = 0 ; + if( ff_c2 < 0 ) ff_c2 = 0 ; + if( ff_c3 < 0 ) ff_c3 = 0 ; return( ff_c + ff_c1 + ff_c2 + ff_c3 ) ; } @@ -1256,7 +1256,7 @@ static float compute_diff_disc_formfactor(Vertex *p, Element *e_src, Vertex *p_d void compute_interaction(Element *e_src, Element *e_dst, Interaction *inter, long subdiv, long process_id) { /* (1) Check visibility. */ - if ( NO_VISIBILITY_NECESSARY(subdiv) ) + if( NO_VISIBILITY_NECESSARY(subdiv) ) inter->visibility = 1.0 ; else inter->visibility = VISIBILITY_UNDEF ; @@ -1296,7 +1296,7 @@ void delete_interaction(Element *elem, Interaction *prev, Interaction *inter, lo { /* Remove from the list */ LOCK(elem->elem_lock->lock); - if ( prev == 0 ) + if( prev == 0 ) elem->interactions = inter->next ; else prev->next = inter->next ; @@ -1323,7 +1323,7 @@ void delete_vis_undef_interaction(Element *elem, Interaction *prev, Interaction { /* Remove from the list */ LOCK(elem->elem_lock->lock); - if ( prev == 0 ) + if( prev == 0 ) elem->vis_undef_inter = inter->next ; else prev->next = inter->next ; @@ -1349,7 +1349,7 @@ Interaction *get_interaction(long process_id) LOCK(global->free_interaction_lock); /* Test pointer */ - if ( global->free_interaction == 0 ) + if( global->free_interaction == 0 ) { printf( "Fatal: Ran out of interaction buffer\n" ) ; UNLOCK(global->free_interaction_lock); @@ -1402,7 +1402,7 @@ void init_interactionlist(long process_id) long i ; /* Initialize Interaction free list */ - for ( i = 0 ; i < MAX_INTERACTIONS-1 ; i++ ) + for( i = 0 ; i < MAX_INTERACTIONS-1 ; i++ ) global->interaction_buf[i].next = &global->interaction_buf[i+1] ; global->interaction_buf[ MAX_INTERACTIONS-1 ].next = 0 ; global->free_interaction = global->interaction_buf ; diff --git a/splash2/codes/apps/radiosity/glibps/glibps.c b/splash2/codes/apps/radiosity/glibps/glibps.c index 526288f29..690e63992 100644 --- a/splash2/codes/apps/radiosity/glibps/glibps.c +++ b/splash2/codes/apps/radiosity/glibps/glibps.c @@ -8,9 +8,8 @@ * ***************************************************************/ -#include #include - +#include #include "pslib.h" #define SCREEN_WIDTH (6.0*72) @@ -70,10 +69,10 @@ static double cdet(Matrix *m, long r0, long r1, long r2, long c0, long c1, long long ps_open(char *file) { - if ( (ps_fd = fopen( file, "w" )) == 0 ) + if( (ps_fd = fopen( file, "w" )) == 0 ) { - perror( file ) ; - return( 0 ) ; + perror( file ) ; + return( 0 ) ; } /* Print out preamble */ @@ -97,8 +96,8 @@ long ps_open(char *file) void ps_close() { - if ( ps_fd == 0 ) - return ; + if( ps_fd == 0 ) + return ; fprintf( ps_fd, "showpage\n" ) ; @@ -118,8 +117,8 @@ void ps_close() void ps_linewidth(float w) { - if ( ps_fd == 0 ) - return ; + if( ps_fd == 0 ) + return ; fprintf( ps_fd, "%f setlinewidth\n", w ) ; } @@ -137,8 +136,8 @@ void ps_line(Vertex *p1, Vertex *p2) Vertex2 v1, v2 ; float x1, y1, x2, y2 ; - if ( ps_fd == 0 ) - return ; + if( ps_fd == 0 ) + return ; v1.v[0] = p1->x ; v1.v[1] = p1->y ; v1.v[2] = p1->z ; v1.v[3] = 1.0 ; v2.v[0] = p2->x ; v2.v[1] = p2->y ; v2.v[2] = p2->z ; v2.v[3] = 1.0 ; @@ -167,8 +166,8 @@ void ps_polygonedge(long n, Vertex *p_list) Vertex2 v ; long i ; - if ( ps_fd == 0 ) - return ; + if( ps_fd == 0 ) + return ; /* Transform */ v.v[0] = p_list[0].x ; @@ -180,18 +179,18 @@ void ps_polygonedge(long n, Vertex *p_list) dcy = v.v[1] / v.v[3] ; fprintf( ps_fd, "newpath\n%f %f moveto\n", dcx, dcy ) ; - for ( i = 1 ; i < n ; i++ ) + for( i = 1 ; i < n ; i++ ) { - /* Transform */ - v.v[0] = p_list[i].x ; - v.v[1] = p_list[i].y ; - v.v[2] = p_list[i].z ; - v.v[3] = 1.0 ; - gtransform( &v, &v, &trans_mtx ) ; - dcx = v.v[0] / v.v[3] ; - dcy = v.v[1] / v.v[3] ; + /* Transform */ + v.v[0] = p_list[i].x ; + v.v[1] = p_list[i].y ; + v.v[2] = p_list[i].z ; + v.v[3] = 1.0 ; + gtransform( &v, &v, &trans_mtx ) ; + dcx = v.v[0] / v.v[3] ; + dcy = v.v[1] / v.v[3] ; - fprintf( ps_fd, "%f %f lineto\n", dcx, dcy ) ; + fprintf( ps_fd, "%f %f lineto\n", dcx, dcy ) ; } fprintf( ps_fd, "closepath stroke\n" ) ; @@ -210,8 +209,8 @@ void ps_polygon(long n, Vertex *p_list) Vertex2 v ; long i ; - if ( ps_fd == 0 ) - return ; + if( ps_fd == 0 ) + return ; /* Transform */ v.v[0] = p_list[0].x ; @@ -223,18 +222,18 @@ void ps_polygon(long n, Vertex *p_list) dcy = v.v[1] / v.v[3] ; fprintf( ps_fd, "newpath\n%f %f moveto\n", dcx, dcy ) ; - for ( i = 1 ; i < n ; i++ ) + for( i = 1 ; i < n ; i++ ) { - /* Transform */ - v.v[0] = p_list[i].x ; - v.v[1] = p_list[i].y ; - v.v[2] = p_list[i].z ; - v.v[3] = 1.0 ; - gtransform( &v, &v, &trans_mtx ) ; - dcx = v.v[0] / v.v[3] ; - dcy = v.v[1] / v.v[3] ; + /* Transform */ + v.v[0] = p_list[i].x ; + v.v[1] = p_list[i].y ; + v.v[2] = p_list[i].z ; + v.v[3] = 1.0 ; + gtransform( &v, &v, &trans_mtx ) ; + dcx = v.v[0] / v.v[3] ; + dcy = v.v[1] / v.v[3] ; - fprintf( ps_fd, "%f %f lineto\n", dcx, dcy ) ; + fprintf( ps_fd, "%f %f lineto\n", dcx, dcy ) ; } fprintf( ps_fd, "closepath fill\n" ) ; @@ -254,8 +253,8 @@ void ps_spolygon(long n, Vertex *p_list, Rgb *c_list) long i ; float gray_scale ; - if ( ps_fd == 0 ) - return ; + if( ps_fd == 0 ) + return ; /* Transform */ v.v[0] = p_list[0].x ; @@ -267,25 +266,25 @@ void ps_spolygon(long n, Vertex *p_list, Rgb *c_list) dcy = v.v[1] / v.v[3] ; fprintf( ps_fd, "newpath\n%f %f moveto\n", dcx, dcy ) ; - for ( i = 1 ; i < n ; i++ ) + for( i = 1 ; i < n ; i++ ) { - /* Transform */ - v.v[0] = p_list[i].x ; - v.v[1] = p_list[i].y ; - v.v[2] = p_list[i].z ; - v.v[3] = 1.0 ; - gtransform( &v, &v, &trans_mtx ) ; - dcx = v.v[0] / v.v[3] ; - dcy = v.v[1] / v.v[3] ; + /* Transform */ + v.v[0] = p_list[i].x ; + v.v[1] = p_list[i].y ; + v.v[2] = p_list[i].z ; + v.v[3] = 1.0 ; + gtransform( &v, &v, &trans_mtx ) ; + dcx = v.v[0] / v.v[3] ; + dcy = v.v[1] / v.v[3] ; - fprintf( ps_fd, "%f %f lineto\n", dcx, dcy ) ; + fprintf( ps_fd, "%f %f lineto\n", dcx, dcy ) ; } gray_scale = c_list[0].g ; - if ( gray_scale > 1.0 ) - gray_scale = 1.0 ; - else if ( gray_scale < 0.0 ) - gray_scale = 0.0 ; + if( gray_scale > 1.0 ) + gray_scale = 1.0 ; + else if( gray_scale < 0.0 ) + gray_scale = 0.0 ; fprintf( ps_fd, "closepath %f setgray fill\n", gray_scale ) ; } @@ -356,17 +355,17 @@ static void setup_transformation() /* Window-Viewport */ gscale_matrix( POST_CAT, &trans_mtx, - (float)SCREEN_WIDTH / (clip_right - clip_left), - (float)SCREEN_HEIGHT / (clip_top - clip_bottom), - (float)SCREEN_DEPTH / (cf_z - cb_z) ) ; + (float)SCREEN_WIDTH / (clip_right - clip_left), + (float)SCREEN_HEIGHT / (clip_top - clip_bottom), + (float)SCREEN_DEPTH / (cf_z - cb_z) ) ; gtranslate_matrix( POST_CAT, &trans_mtx, - -(float)SCREEN_WIDTH * clip_left / (clip_right - clip_left), - -(float)SCREEN_HEIGHT* clip_top / (clip_bottom - clip_top), - -(float)SCREEN_DEPTH * cb_z / (cf_z - cb_z) ) ; + -(float)SCREEN_WIDTH * clip_left / (clip_right - clip_left), + -(float)SCREEN_HEIGHT* clip_top / (clip_bottom - clip_top), + -(float)SCREEN_DEPTH * cb_z / (cf_z - cb_z) ) ; gtranslate_matrix( POST_CAT, &trans_mtx, - (float)(1.0*72), (float)(0.5*72), 0 ) ; + (float)(1.0*72), (float)(0.5*72), 0 ) ; } @@ -414,13 +413,13 @@ static void gset_unit_matrix(Matrix *mtx) long row, col ; /* Clear the matrix */ - for ( row = 0 ; row < 4 ; row++ ) - for ( col = 0 ; col < 4 ; col++ ) - mtx->m[row][col] = 0.0 ; + for( row = 0 ; row < 4 ; row++ ) + for( col = 0 ; col < 4 ; col++ ) + mtx->m[row][col] = 0.0 ; /* Set 1.0s along diagonal line */ - for ( row = 0 ; row < 4 ; row++ ) - mtx->m[row][row] = 1.0 ; + for( row = 0 ; row < 4 ; row++ ) + mtx->m[row][row] = 1.0 ; } @@ -444,21 +443,21 @@ static void gconcatenate_matrix(long precat, Matrix *m1, Matrix *m2) /* Swap pointer according to the concatenation mode */ dest = m1 ; - if ( precat == 1 ) + if( precat == 1 ) { - m1 = m2 ; - m2 = dest ; + m1 = m2 ; + m2 = dest ; } /* concatenate it */ - for ( row = 0 ; row < 4 ; row++ ) - for ( col = 0 ; col < 4 ; col++ ) - { - temp.m[row][col] = 0.0 ; - for ( scan = 0 ; scan < 4 ; scan++ ) - temp.m[row][col] += - m1->m[row][scan] * m2->m[scan][col]; - } + for( row = 0 ; row < 4 ; row++ ) + for( col = 0 ; col < 4 ; col++ ) + { + temp.m[row][col] = 0.0 ; + for( scan = 0 ; scan < 4 ; scan++ ) + temp.m[row][col] += + m1->m[row][scan] * m2->m[scan][col]; + } *dest = temp ; } @@ -660,14 +659,14 @@ static double det(Matrix *m) /* Expand with respect to column 4 */ det_sum = 0.0 ; - if ( m->m[0][3] != 0.0 ) - det_sum -= m->m[0][3] * cdet( m, 1, 2, 3, 0, 1, 2 ) ; - if ( m->m[1][3] != 0.0 ) - det_sum += m->m[1][3] * cdet( m, 0, 2, 3, 0, 1, 2 ) ; - if ( m->m[2][3] != 0.0 ) - det_sum -= m->m[2][3] * cdet( m, 0, 1, 3, 0, 1, 2 ) ; - if ( m->m[3][3] != 0.0 ) - det_sum += m->m[3][3] * cdet( m, 0, 1, 2, 0, 1, 2 ) ; + if( m->m[0][3] != 0.0 ) + det_sum -= m->m[0][3] * cdet( m, 1, 2, 3, 0, 1, 2 ) ; + if( m->m[1][3] != 0.0 ) + det_sum += m->m[1][3] * cdet( m, 0, 2, 3, 0, 1, 2 ) ; + if( m->m[2][3] != 0.0 ) + det_sum -= m->m[2][3] * cdet( m, 0, 1, 3, 0, 1, 2 ) ; + if( m->m[3][3] != 0.0 ) + det_sum += m->m[3][3] * cdet( m, 0, 1, 2, 0, 1, 2 ) ; return( det_sum ) ; } diff --git a/splash2/codes/apps/radiosity/glibps/pslib.h b/splash2/codes/apps/radiosity/glibps/pslib.h index 7bb97f290..6d31326ee 100644 --- a/splash2/codes/apps/radiosity/glibps/pslib.h +++ b/splash2/codes/apps/radiosity/glibps/pslib.h @@ -20,12 +20,12 @@ typedef struct { - float v[4] ; /* x, y, z, and w */ + float v[4] ; /* x, y, z, and w */ } Vertex2; typedef struct { - float m[4][4] ; /* m[row][column], row vector assumed */ + float m[4][4] ; /* m[row][column], row vector assumed */ } Matrix; /**************************************** diff --git a/splash2/codes/apps/radiosity/modelman.C b/splash2/codes/apps/radiosity/modelman.C index 93833f3c6..36d97c515 100644 --- a/splash2/codes/apps/radiosity/modelman.C +++ b/splash2/codes/apps/radiosity/modelman.C @@ -24,7 +24,7 @@ * *************************************************************************/ -#include +#include EXTERN_ENV; @@ -124,7 +124,7 @@ void init_modeling_tasks(long process_id) extern ModelDataBase room_model[] ; extern ModelDataBase largeroom_model[] ; - if ( ! check_task_counter() ) + if( ! check_task_counter() ) return ; switch( model_selector ) @@ -161,7 +161,7 @@ static void init_room_model_tasks(ModelDataBase *model, long process_id) { ModelDataBase *pm ; - for ( pm = model ; pm->type != MODEL_NULL ; pm++ ) + for( pm = model ; pm->type != MODEL_NULL ; pm++ ) create_modeling_task( &pm->model, pm->type, process_id ) ; } diff --git a/splash2/codes/apps/radiosity/patchman.C b/splash2/codes/apps/radiosity/patchman.C index 7d556d6a3..6fccd2040 100644 --- a/splash2/codes/apps/radiosity/patchman.C +++ b/splash2/codes/apps/radiosity/patchman.C @@ -24,7 +24,7 @@ * *************************************************************************/ -#include +#include EXTERN_ENV; @@ -60,18 +60,18 @@ void foreach_patch_in_bsp(void (*func)(), long arg1, long process_id) static void _foreach_patch(Patch *node, void (*func)(), long arg1, long process_id) { - if ( node == 0 ) + if( node == 0 ) return ; /* Process subtree(-) */ - if ( node->bsp_negative ) + if( node->bsp_negative ) _foreach_patch( node->bsp_negative, func, arg1, process_id ) ; /* Apply function to this node */ func( node, arg1, process_id ) ; /* Process subtree(+) */ - if ( node->bsp_positive ) + if( node->bsp_positive ) _foreach_patch( node->bsp_positive, func, arg1, process_id ) ; } @@ -99,38 +99,38 @@ static void _foreach_d_s_patch(Vertex *svec, Patch *node, void (*func)(), long a { float sign ; - if ( node == 0 ) + if( node == 0 ) return ; /* Compute inner product */ sign = inner_product( svec, &node->plane_equ.n ) ; - if ( sign >= 0.0 ) + if( sign >= 0.0 ) { /* The vector is approaching from the negative side of the patch */ /* Process subtree(-) */ - if ( node->bsp_negative ) + if( node->bsp_negative ) _foreach_d_s_patch( svec, node->bsp_negative, func, arg1, process_id ) ; /* Apply function to this node */ func( node, arg1, process_id ) ; /* Process subtree(+) */ - if ( node->bsp_positive ) + if( node->bsp_positive ) _foreach_d_s_patch( svec, node->bsp_positive, func, arg1, process_id ) ; } else { /* Process subtree(+) */ - if ( node->bsp_positive ) + if( node->bsp_positive ) _foreach_d_s_patch( svec, node->bsp_positive, func, arg1, process_id ) ; /* Apply function to this node */ func( node, arg1, process_id ) ; /* Process subtree(-) */ - if ( node->bsp_negative ) + if( node->bsp_negative ) _foreach_d_s_patch( svec, node->bsp_negative, func, arg1, process_id ) ; } } @@ -155,9 +155,9 @@ void define_patch(Patch *patch, Patch *root, long process_id) LOCK(global->bsp_tree_lock); /* If this is the first patch, link directly */ - if ( parent == 0 ) + if( parent == 0 ) { - if ( global->bsp_root == 0 ) + if( global->bsp_root == 0 ) { /* This is really the first patch */ global->bsp_root = patch ; @@ -176,16 +176,16 @@ void define_patch(Patch *patch, Patch *root, long process_id) } /* Traverse the BSP tree and get to the leaf node */ - while ( 1 ) + while( 1 ) { /* Check the sign */ xing_code = patch_intersection( &parent->plane_equ, &patch->p1, &patch->p2, &patch->p3, process_id ) ; /* Traverse down the tree according to the sign */ - if ( POSITIVE_SIDE( xing_code ) ) + if( POSITIVE_SIDE( xing_code ) ) { - if ( parent->bsp_positive == 0 ) + if( parent->bsp_positive == 0 ) { /* Insert the patch */ parent->bsp_positive = patch ; @@ -200,9 +200,9 @@ void define_patch(Patch *patch, Patch *root, long process_id) /* Traverse down to the subtree(+) */ parent = parent->bsp_positive ; } - else if ( NEGATIVE_SIDE( xing_code ) ) + else if( NEGATIVE_SIDE( xing_code ) ) { - if ( parent->bsp_negative == 0 ) + if( parent->bsp_negative == 0 ) { /* Insert the patch */ parent->bsp_negative = patch ; @@ -255,23 +255,23 @@ void split_patch(Patch *patch, Patch *node, long xing_code, long process_id) c3 = P3_CODE( xing_code ) ; /* Classify intersection type */ - if ( c1 == c2 ) + if( c1 == c2 ) /* P3 is on the oposite side */ split_into_3( patch, patch->ev3, patch->ev1, patch->ev2, patch->e31, patch->e12, patch->e23, node, process_id) ; - else if ( c1 == c3 ) + else if( c1 == c3 ) /* P2 is on the oposite side */ split_into_3( patch, patch->ev2, patch->ev3, patch->ev1, patch->e23, patch->e31, patch->e12, node, process_id ) ; - else if ( c2 == c3 ) + else if( c2 == c3 ) /* P1 is on the oposite side */ split_into_3( patch, patch->ev1, patch->ev2, patch->ev3, patch->e12, patch->e23, patch->e31, node, process_id ) ; - else if ( c1 == POINT_ON_PLANE ) + else if( c1 == POINT_ON_PLANE ) /* P1 is on the plane. P2 and P3 are on the oposite side */ split_into_2( patch, patch->ev1, patch->ev2, patch->ev3, patch->e12, patch->e23, patch->e31, node, process_id ) ; - else if ( c2 == POINT_ON_PLANE ) + else if( c2 == POINT_ON_PLANE ) /* P2 is on the plane. P3 and P1 are on the oposite side */ split_into_2( patch, patch->ev2, patch->ev3, patch->ev1, patch->e23, patch->e31, patch->e12, node, process_id ) ; @@ -302,14 +302,14 @@ static void split_into_3(Patch *patch, ElemVertex *ev1, ElemVertex *ev2, ElemVer /* NOTE: Length of P1-P2 and P1-P3 are at least 2*F_COPLANAR. So, no check is necessary before division */ u2 = h1 / (h1 - h2) ; - if ( (rev_e12 = EDGE_REVERSE( e12, ev1, ev2 )) ) + if( (rev_e12 = EDGE_REVERSE( e12, ev1, ev2 )) ) subdivide_edge( e12, u2, process_id ) ; else subdivide_edge( e12, (float)1.0 - u2, process_id ) ; ev_a = e12->ea->pb ; u3 = h1 / (h1 - h3) ; - if ( (rev_e31 = EDGE_REVERSE( e31, ev3, ev1 )) ) + if( (rev_e31 = EDGE_REVERSE( e31, ev3, ev1 )) ) subdivide_edge( e31, (float)1.0 - u3, process_id ) ; else subdivide_edge( e31, u3, process_id ) ; @@ -391,7 +391,7 @@ static void split_into_2(Patch *patch, ElemVertex *ev1, ElemVertex *ev2, ElemVer /* NOTE: Length of P2-P3 is at least 2*F_COPLANAR. So, no check is necessary before division */ u2 = h2 / (h2 - h3) ; - if ( (rev_e23 = EDGE_REVERSE( e23, ev2, ev3 )) ) + if( (rev_e23 = EDGE_REVERSE( e23, ev2, ev3 )) ) subdivide_edge( e23, u2, process_id ) ; else subdivide_edge( e23, (float)1.0 - u2, process_id ) ; @@ -488,20 +488,20 @@ void refine_newpatch(Patch *patch, long newpatch, long process_id) Patch *new_patch = (Patch *)newpatch ; /* Check sequence number */ - if ( patch->seq_no >= new_patch->seq_no ) + if( patch->seq_no >= new_patch->seq_no ) /* Racing condition due to multiprocessing */ return ; /* Check visibility */ cc = patch_intersection( &patch->plane_equ, &new_patch->p1, &new_patch->p2, &new_patch->p3, process_id ) ; - if ( NEGATIVE_SIDE(cc) ) + if( NEGATIVE_SIDE(cc) ) /* If negative or on the plane, then do nothing */ return ; cc = patch_intersection( &new_patch->plane_equ, &patch->p1, &patch->p2, &patch->p3, process_id ) ; - if ( NEGATIVE_SIDE(cc) ) + if( NEGATIVE_SIDE(cc) ) /* If negative or on the plane, then do nothing */ return ; @@ -526,7 +526,7 @@ Patch *get_patch(long process_id) LOCK(global->free_patch_lock); /* Test pointer */ - if ( global->free_patch == 0 ) + if( global->free_patch == 0 ) { printf( "Fatal: Ran out of patch buffer\n" ) ; UNLOCK(global->free_patch_lock); @@ -566,7 +566,7 @@ void init_patchlist(long process_id) long i ; /* Initialize Patch free list */ - for ( i = 0 ; i < MAX_PATCHES-1 ; i++ ) + for( i = 0 ; i < MAX_PATCHES-1 ; i++ ) { global->patch_buf[i].bsp_positive = &global->patch_buf[i+1] ; global->patch_buf[i].seq_no = i ; @@ -581,7 +581,7 @@ void init_patchlist(long process_id) #if PATCH_ASSIGNMENT == PATCH_ASSIGNMENT_COSTBASED /* Initialize Patch_Cost structure */ - for ( i = 0 ; i < MAX_PATCHES ; i++ ) + for( i = 0 ; i < MAX_PATCHES ; i++ ) { global->patch_cost[i].patch = &global->patch_buf[i] ; global->patch_cost[i].cost_lock @@ -710,9 +710,9 @@ long point_intersection(PlaneEqu *plane, Vertex *point, long process_id) long result_code = 0 ; /* Compare H(x,y,z) against allowance */ - if ( (h = plane_equ( plane, point, process_id )) < -F_COPLANAR ) + if( (h = plane_equ( plane, point, process_id )) < -F_COPLANAR ) result_code |= POINT_NEGATIVE_SIDE ; - if ( h > F_COPLANAR ) + if( h > F_COPLANAR ) result_code |= POINT_POSITIVE_SIDE ; return( result_code ) ; diff --git a/splash2/codes/apps/radiosity/rad_main.C b/splash2/codes/apps/radiosity/rad_main.C index dc00bc3c4..b44d7e593 100644 --- a/splash2/codes/apps/radiosity/rad_main.C +++ b/splash2/codes/apps/radiosity/rad_main.C @@ -22,15 +22,12 @@ * ***************************************************************/ -#include -#include - +#include +#include #if defined(SGI_GL) #include - #if defined(GL_NASA) #include - #endif #endif @@ -160,7 +157,7 @@ int main(int argc, char *argv[]) choices[2].init_value = model_selector ; /* Initialize graphic device */ - if ( batch_mode == 0 ) + if( batch_mode == 0 ) { g_init(argc, argv) ; setup_view( DFLT_VIEW_ROT_X, DFLT_VIEW_ROT_Y, @@ -172,7 +169,7 @@ int main(int argc, char *argv[]) /* Allocate global shared memory and initialize */ global = (Global *) G_MALLOC(sizeof(Global)) ; - if ( global == 0 ) + if( global == 0 ) { printf( "Can't allocate memory\n" ) ; exit(1) ; @@ -208,7 +205,7 @@ int main(int argc, char *argv[]) */ - if ( batch_mode ) + if( batch_mode ) { /* In batch mode, create child processes and start immediately */ @@ -216,7 +213,7 @@ int main(int argc, char *argv[]) CLOCK( time_rad_start ); global->index = 0; - for ( i = 0 ; i < n_processors ; i++ ) + for( i = 0 ; i < n_processors ; i++ ) { taskqueue_id[i] = assign_taskq(0) ; } @@ -283,16 +280,9 @@ int main(int argc, char *argv[]) min_vertex_time = timing[i]->vertex_time; } - printf("\n\n%8s%20lu%20lu%12lu%12lu\n","Max", max_rad_time, max_refine_time, - max_wait_time, max_vertex_time); - printf("\n%8s%20lu%20lu%12lu%12lu\n","Min", min_rad_time, min_refine_time, - min_wait_time, min_vertex_time); - printf("\n%8s%20lu%20lu%12lu%12lu\n","Avg", - (long) (((double) total_rad_time) / - ((double) (1.0 * n_processors))), - (long) (((double) total_refine_time) / ((double) (1.0 * n_processors))), - (long) (((double) total_wait_time) / ((double) (1.0 * n_processors))), - (long) (((double) total_vertex_time) / ((double) (1.0 * n_processors)))); + printf("\n\n%8s%20lu%20lu%12lu%12lu\n","Max", max_rad_time, max_refine_time, max_wait_time, max_vertex_time); + printf("\n%8s%20lu%20lu%12lu%12lu\n","Min", min_rad_time, min_refine_time, min_wait_time, min_vertex_time); + printf("\n%8s%20lu%20lu%12lu%12lu\n","Avg", (long) (((double) total_rad_time) / ((double) (1.0 * n_processors))), (long) (((double) total_refine_time) / ((double) (1.0 * n_processors))), (long) (((double) total_wait_time) / ((double) (1.0 * n_processors))), (long) (((double) total_vertex_time) / ((double) (1.0 * n_processors)))); printf("\n\n"); } @@ -354,9 +344,9 @@ void start_radiosity(long val) val = g_get_choice_val( ap, &choices[0] ) ; #endif - if ( val == CHOICE_RAD_RUN ) + if( val == CHOICE_RAD_RUN ) { - if ( state == -1 ) + if( state == -1 ) { printf( "Please reset first\007\n" ) ; return ; @@ -456,9 +446,9 @@ void start_radiosity(long val) state = -1 ; } - else if ( val == CHOICE_RAD_STEP ) + else if( val == CHOICE_RAD_STEP ) { - if ( state == -1 ) + if( state == -1 ) { printf( "Please reset first\007\n" ) ; return ; @@ -488,7 +478,7 @@ void start_radiosity(long val) break ; case 1: - if ( init_ray_tasks(0) ) + if( init_ray_tasks(0) ) { BARRIER(global->barrier, n_processors); process_tasks(0) ; @@ -512,7 +502,7 @@ void start_radiosity(long val) disp_mesh_switch, disp_interaction_switch, 0) ; } - else if ( val == CHOICE_RAD_RESET ) + else if( val == CHOICE_RAD_RESET ) { /* Initialize global variables again */ init_global(0) ; @@ -566,11 +556,11 @@ void change_display(long val) return ; } - if ( disp_fill_switch == 0 ) + if( disp_fill_switch == 0 ) disp_fill_mode = 0 ; else { - if ( disp_shade_switch == 0 ) + if( disp_shade_switch == 0 ) disp_fill_mode = 1 ; else disp_fill_mode = 2 ; @@ -753,7 +743,7 @@ void utility_tools(long val) print_statistics( stdout, 0 ) ; break ; case CHOICE_UTIL_STAT_FILE: - if ( (fd = fopen( "radiosity_stat", "w" )) == 0 ) + if( (fd = fopen( "radiosity_stat", "w" )) == 0 ) { perror( "radiosity_stat" ) ; break ; @@ -814,7 +804,7 @@ void radiosity() process_tasks(process_id) ; /* Gather rays & do BF refinement */ - while ( init_ray_tasks(process_id) ) + while( init_ray_tasks(process_id) ) { /* Wait till tasks are put in the queue */ BARRIER(global->barrier, n_processors); @@ -886,7 +876,7 @@ long init_ray_tasks(long process_id) /* If this is not the first process to initialize, then return */ LOCK(global->avg_radiosity_lock); - if ( ! check_task_counter() ) + if( ! check_task_counter() ) { conv = global->converged ; UNLOCK(global->avg_radiosity_lock); @@ -909,7 +899,7 @@ long init_ray_tasks(long process_id) UNLOCK(global->avg_radiosity_lock); /* If radiosity converged, then return 0 */ - if ( conv ) + if( conv ) return( 0 ) ; @@ -918,7 +908,7 @@ long init_ray_tasks(long process_id) The 'cost_sum' is not locked since no one is processing rays at this moment */ - for ( crnt_qid = 0 ; crnt_qid < n_taskqueues ; crnt_qid++ ) + for( crnt_qid = 0 ; crnt_qid < n_taskqueues ; crnt_qid++ ) queue_cost[ crnt_qid ] = 0 ; avg_cost_of_q = global->cost_estimate_sum / n_taskqueues ; @@ -964,29 +954,29 @@ static void _init_ray_tasks_cost2(Patch *p, long layer, long process_id) pc = &global->patch_cost[ p->seq_no ] ; c_est = pc->cost_estimate ; - if ( c_est < 0 ) + if( c_est < 0 ) /* Already processed */ return ; - if ( c_est < avg_cost_of_patch * layer ) + if( c_est < avg_cost_of_patch * layer ) return ; /* Find the first available queue */ min_cost_q = 0 ; min_cost = queue_cost[ 0 ] ; - for ( qid = 0 ; qid < n_taskqueues ; qid++ ) + for( qid = 0 ; qid < n_taskqueues ; qid++ ) { - if ( (c_est + queue_cost[ qid ]) <= avg_cost_of_q ) + if( (c_est + queue_cost[ qid ]) <= avg_cost_of_q ) break ; - if ( min_cost > queue_cost[ qid ] ) + if( min_cost > queue_cost[ qid ] ) { min_cost_q = qid ; min_cost = queue_cost[ qid ] ; } } - if ( qid >= n_taskqueues ) + if( qid >= n_taskqueues ) { /* All queues are nearly full. Put to min-cost queue */ qid = min_cost_q ; @@ -1025,7 +1015,7 @@ void init_radavg_tasks(long mode, long process_id) { /* If this is not the first process to initialize, then return */ - if ( ! check_task_counter() ) + if( ! check_task_counter() ) return ; /* Create RadAvg tasks */ @@ -1108,36 +1098,36 @@ static void parse_args(int argc, char *argv[]) long cnt ; /* Parse arguments */ - for ( cnt = 1 ; cnt < argc ; cnt++ ) + for( cnt = 1 ; cnt < argc ; cnt++ ) { - if ( strcmp( argv[cnt], "-p" ) == 0 ) { + if( strcmp( argv[cnt], "-p" ) == 0 ) { sscanf( argv[++cnt], "%ld", &n_processors ) ; n_taskqueues = n_processors; } - else if ( strcmp( argv[cnt], "-tq" ) == 0 ) + else if( strcmp( argv[cnt], "-tq" ) == 0 ) sscanf( argv[++cnt], "%ld", &n_tasks_per_queue ) ; - else if ( strcmp( argv[cnt], "-ae" ) == 0 ) + else if( strcmp( argv[cnt], "-ae" ) == 0 ) sscanf( argv[++cnt], "%f", &Area_epsilon ) ; - else if ( strcmp( argv[cnt], "-pr" ) == 0 ) + else if( strcmp( argv[cnt], "-pr" ) == 0 ) sscanf( argv[++cnt], "%ld", &N_inter_parallel_bf_refine ) ; - else if ( strcmp( argv[cnt], "-pv" ) == 0 ) + else if( strcmp( argv[cnt], "-pv" ) == 0 ) sscanf( argv[++cnt], "%ld", &N_visibility_per_task ) ; - else if ( strcmp( argv[cnt], "-bf" ) == 0 ) + else if( strcmp( argv[cnt], "-bf" ) == 0 ) sscanf( argv[++cnt], "%f", &BFepsilon ) ; - else if ( strcmp( argv[cnt], "-en" ) == 0 ) + else if( strcmp( argv[cnt], "-en" ) == 0 ) sscanf( argv[++cnt], "%f", &Energy_epsilon ) ; - else if ( strcmp( argv[cnt], "-batch" ) == 0 ) + else if( strcmp( argv[cnt], "-batch" ) == 0 ) batch_mode = 1 ; - else if ( strcmp( argv[cnt], "-verbose" ) == 0 ) + else if( strcmp( argv[cnt], "-verbose" ) == 0 ) verbose_mode = 1 ; - else if ( strcmp( argv[cnt], "-s" ) == 0 ) + else if( strcmp( argv[cnt], "-s" ) == 0 ) dostats = 1 ; - else if ( strcmp( argv[cnt], "-room" ) == 0 ) + else if( strcmp( argv[cnt], "-room" ) == 0 ) model_selector = MODEL_ROOM_DATA ; - else if ( strcmp( argv[cnt], "-largeroom" ) == 0 ) + else if( strcmp( argv[cnt], "-largeroom" ) == 0 ) model_selector = MODEL_LARGEROOM_DATA ; - else if (( strcmp( argv[cnt], "-help" ) == 0 ) || ( strcmp( argv[cnt], "-h" ) == 0 ) || ( strcmp( argv[cnt], "-H" ) == 0 )) { + else if(( strcmp( argv[cnt], "-help" ) == 0 ) || ( strcmp( argv[cnt], "-h" ) == 0 ) || ( strcmp( argv[cnt], "-H" ) == 0 )) { print_usage() ; exit(0) ; } @@ -1145,25 +1135,25 @@ static void parse_args(int argc, char *argv[]) /* Then check the arguments */ - if ( (n_processors < 1) || (MAX_PROCESSORS < n_processors) ) + if( (n_processors < 1) || (MAX_PROCESSORS < n_processors) ) { fprintf( stderr, "Bad number of processors: %ld\n", n_processors ) ; exit(1) ; } - if ( (n_taskqueues < 1) || (MAX_TASKQUEUES < n_taskqueues) ) + if( (n_taskqueues < 1) || (MAX_TASKQUEUES < n_taskqueues) ) { fprintf( stderr, "Bad number of task queues: %ld\n", n_taskqueues ) ; exit(1) ; } /* Check epsilon values */ - if ( Area_epsilon < 0.0 ) + if( Area_epsilon < 0.0 ) { fprintf( stderr, "Area epsilon must be positive\n" ) ; exit(1) ; } - if ( BFepsilon < 0.0 ) + if( BFepsilon < 0.0 ) { fprintf( stderr, "BFepsilon must be within [0,1]\n" ) ; exit(1) ; diff --git a/splash2/codes/apps/radiosity/rad_tools.C b/splash2/codes/apps/radiosity/rad_tools.C index 04491b650..4a0a8d25a 100644 --- a/splash2/codes/apps/radiosity/rad_tools.C +++ b/splash2/codes/apps/radiosity/rad_tools.C @@ -20,7 +20,7 @@ * ***************************************************************/ -#include +#include EXTERN_ENV; @@ -77,7 +77,7 @@ void print_statistics(FILE *fd, long process_id) total_match1 = 0 ; total_match0 = 0 ; - for ( i = 0 ; i < MAX_INTERACTION_PER_ELEMENT ; i++ ) + for( i = 0 ; i < MAX_INTERACTION_PER_ELEMENT ; i++ ) { elem_interaction[i].count = 0 ; elem_interaction[i].area = 0 ; @@ -92,21 +92,21 @@ void print_statistics(FILE *fd, long process_id) fprintf( fd, " Histogram of interactions/elem\n" ) ; fprintf( fd, "\t Interactions Occurrence\n" ) ; fprintf( fd, "\t -------------------------------\n" ) ; - if ( many_interaction.count > 0 ) + if( many_interaction.count > 0 ) { fprintf( fd, "\t (Over %d) %ld (%f)\n", MAX_INTERACTION_PER_ELEMENT, many_interaction.count, many_interaction.area / many_interaction.count ) ; } - for ( i = MAX_INTERACTION_PER_ELEMENT ; + for( i = MAX_INTERACTION_PER_ELEMENT ; elem_interaction[i].count == 0 ; i-- ) ; - for ( ; i >= 0 ; i-- ) + for( ; i >= 0 ; i-- ) { - if ( elem_interaction[i].count == 0 ) + if( elem_interaction[i].count == 0 ) continue ; - if ( elem_interaction[i].count == 0 ) + if( elem_interaction[i].count == 0 ) fprintf( fd, "\t %ld %ld (---)\n", i, elem_interaction[i].count ) ; @@ -213,7 +213,7 @@ void print_per_process_info(FILE *fd, long process) fprintf( fd, "\t\tPatch cache hit ratio: %.2f%%\n", ps->total_patch_cache_hit * 100 / (ps->total_patch_cache_check + 0.01) ) ; - for ( cache_line = 0 ; cache_line < PATCH_CACHE_SIZE ; cache_line++ ) + for( cache_line = 0 ; cache_line < PATCH_CACHE_SIZE ; cache_line++ ) fprintf( fd, "\t\t (level %ld): %.2f%%\n", cache_line, ps->patch_cache_hit[cache_line] * 100 / @@ -221,7 +221,7 @@ void print_per_process_info(FILE *fd, long process) /* Per iteration info */ fprintf( fd, "\t\tPer iteration info.\n" ) ; - for ( iteration = 0 ; iteration < global->iteration_count ; iteration++ ) + for( iteration = 0 ; iteration < global->iteration_count ; iteration++ ) { fprintf( fd, "\t\t [%ld] Interaction comp: %ld\n", iteration, ps->per_iteration[iteration].visibility_comp ) ; @@ -234,9 +234,9 @@ void print_per_process_info(FILE *fd, long process) fprintf( fd, "\t\t Process_task wait count: %ld\n", ps->per_iteration[iteration].process_tasks_wait ) ; e = ps->per_iteration[iteration].last_pr_task ; - if ( e == 0 ) + if( e == 0 ) continue ; - if ( e->parent == 0 ) + if( e->parent == 0 ) { fprintf( fd, "\t\t Last task: Patch level\n" ) ; fprintf( fd, "\t\t (%ld root inter)\n", @@ -289,7 +289,7 @@ void get_patch_stat(Patch *patch, long dummy, long process_id) total_invisible_interactions += n_invisible_interactions ; #if PATCH_ASSIGNMENT == PATCH_ASSIGNMENT_COSTBASED - if ( n_interactions_in_patch + if( n_interactions_in_patch != global->patch_cost[patch->seq_no].n_total_inter ) { printf( "Error: patch(%d) Inter counted: %d (n_total_inter %d)\n", @@ -310,7 +310,7 @@ void get_elem_stat(Element *elem, long dummy, long process_id) n_elements_in_patch++ ; - while ( elem->area < min_elem_area ) + while( elem->area < min_elem_area ) { min_elem_area *= 0.25 ; n_equiv_elem_in_patch *= 4 ; @@ -318,21 +318,21 @@ void get_elem_stat(Element *elem, long dummy, long process_id) /* Classify visibility */ n_interactions_in_patch += elem->n_interactions ; - for ( pi = elem->interactions ; pi ; pi = pi->next ) + for( pi = elem->interactions ; pi ; pi = pi->next ) { - if ( pi->visibility == 0.0 ) + if( pi->visibility == 0.0 ) i_visible++ ; - else if ( pi->visibility == 1.0 ) + else if( pi->visibility == 1.0 ) c_visible++ ; else p_visible++ ; } - if ( i_visible + c_visible + p_visible != elem->n_interactions ) + if( i_visible + c_visible + p_visible != elem->n_interactions ) printf( "Fatal: Interactions count miss match\n" ) ; - if ( elem->n_vis_undef_inter != 0 ) + if( elem->n_vis_undef_inter != 0 ) printf( "Fatal: Visibility undef list count non zero(%ld)\n", elem->n_vis_undef_inter ) ; - if ( elem->vis_undef_inter != 0 ) + if( elem->vis_undef_inter != 0 ) printf( "Fatal: Visibility undef list not empty\n" ) ; n_comp_visible_interactions += c_visible ; @@ -340,7 +340,7 @@ void get_elem_stat(Element *elem, long dummy, long process_id) /* Count interactions / element */ - if ( elem->n_interactions > MAX_INTERACTION_PER_ELEMENT ) + if( elem->n_interactions > MAX_INTERACTION_PER_ELEMENT ) { many_interaction.count++ ; many_interaction.area += elem->area ; @@ -352,7 +352,7 @@ void get_elem_stat(Element *elem, long dummy, long process_id) } /* Analyze object coherence */ - if ( ! LEAF_ELEMENT( elem ) ) + if( ! LEAF_ELEMENT( elem ) ) { match0 = match1 = match2 = match3 = 0 ; @@ -379,7 +379,7 @@ void count_interaction(Element *es, Element *e1, Element *e2, Element *e3, long Interaction *pi ; long occurrence ; - for ( pi = es->interactions ; pi ; pi = pi->next ) + for( pi = es->interactions ; pi ; pi = pi->next ) { occurrence = search_intearction( e1->interactions, pi, process_id ) ; occurrence += search_intearction( e2->interactions, pi, process_id ) ; @@ -396,9 +396,9 @@ void count_interaction(Element *es, Element *e1, Element *e2, Element *e3, long long search_intearction(Interaction *int_list, Interaction *inter, long process_id) { - while ( int_list ) + while( int_list ) { - if ( int_list->destination == inter->destination ) + if( int_list->destination == inter->destination ) return( 1 ) ; int_list = int_list->next ; @@ -419,9 +419,9 @@ void print_running_time(long process_id) time_diff = time_rad_end - time_rad_start ; time_diff1 = time_rad_end - timing[0]->rad_start; - if ( time_diff < 0 ) + if( time_diff < 0 ) time_diff += CLOCK_MAX_VAL ; - if ( time_diff1 < 0 ) + if( time_diff1 < 0 ) time_diff1 += CLOCK_MAX_VAL ; printf( "\tOverall start time\t%20lu\n", time_rad_start); @@ -441,11 +441,11 @@ void print_fork_time(long process_id) { long pid ; - if ( n_processors <= 1 ) + if( n_processors <= 1 ) return ; printf( "\tProcess fork overhead\n" ) ; - for ( pid = 0 ; pid < n_processors-1 ; pid++ ) + for( pid = 0 ; pid < n_processors-1 ; pid++ ) { printf( "\t Process %ld %.2f mS\n", pid, @@ -469,7 +469,7 @@ void init_stat_info(long process_id) long i ; StatisticalInfo *ps ; - for ( pid = 0 ; pid < MAX_PROCESSORS ; pid++ ) + for( pid = 0 ; pid < MAX_PROCESSORS ; pid++ ) { ps = &global->stat_info[ pid ] ; ps->total_modeling_tasks = 0 ; @@ -484,10 +484,10 @@ void init_stat_info(long process_id) ps->total_patch_cache_check = 0 ; ps->total_patch_cache_hit = 0 ; - for ( i = 0 ; i < PATCH_CACHE_SIZE ; i++ ) + for( i = 0 ; i < PATCH_CACHE_SIZE ; i++ ) ps->patch_cache_hit[i] = 0 ; - for ( i = 0 ; i < MAX_ITERATION_INFO ; i++ ) + for( i = 0 ; i < MAX_ITERATION_INFO ; i++ ) { ps->per_iteration[ i ].visibility_comp = 0 ; ps->per_iteration[ i ].ray_intersect_test = 0 ; diff --git a/splash2/codes/apps/radiosity/radiosity.H b/splash2/codes/apps/radiosity/radiosity.H index 08b12a6ba..b6379ec1c 100644 --- a/splash2/codes/apps/radiosity/radiosity.H +++ b/splash2/codes/apps/radiosity/radiosity.H @@ -21,8 +21,7 @@ of the program, as well as lobal data structure declarations */ #ifndef _RADIOSITY_H #define _RADIOSITY_H -#include - +#include include(parallel.h) include(patch.h) include(model.h) @@ -30,6 +29,7 @@ include(task.h) #include "glib.h" #include "pslib.h" + /**************************************** * * Configuration Parameters diff --git a/splash2/codes/apps/radiosity/room_model.C b/splash2/codes/apps/radiosity/room_model.C index 0162e6e19..ca8ab1fb2 100644 --- a/splash2/codes/apps/radiosity/room_model.C +++ b/splash2/codes/apps/radiosity/room_model.C @@ -28,7 +28,7 @@ EXTERN_ENV; -#include +#include include(radiosity.h) diff --git a/splash2/codes/apps/radiosity/smallobj.C b/splash2/codes/apps/radiosity/smallobj.C index c18b60ea7..75204ed8a 100644 --- a/splash2/codes/apps/radiosity/smallobj.C +++ b/splash2/codes/apps/radiosity/smallobj.C @@ -21,7 +21,7 @@ * *************************************************************************/ -#include +#include EXTERN_ENV; @@ -305,7 +305,7 @@ ElemVertex *get_elemvertex(long process_id) { ElemVertex *ev ; - if ( sobj_struct[process_id].n_local_free_elemvertex == 0 ) + if( sobj_struct[process_id].n_local_free_elemvertex == 0 ) { LOCK(global->free_elemvertex_lock); if ( MAX_ELEMVERTICES - global->free_elemvertex @@ -355,7 +355,7 @@ void init_elemvertex(long process_id) global->free_elemvertex = 0 ; /* Allocate locks */ - for ( ev_cnt = 0 ; ev_cnt < MAX_ELEMVERTICES ; ev_cnt++ ) + for( ev_cnt = 0 ; ev_cnt < MAX_ELEMVERTICES ; ev_cnt++ ) global->elemvertex_buf[ ev_cnt ].ev_lock = get_sharedlock( SHARED_LOCK_SEGANY, process_id ) ; @@ -390,14 +390,14 @@ void foreach_leaf_edge(Edge *edge, long reverse, void (*func)(), long arg1, long { Edge *first, *second ; - if ( edge == 0 ) + if( edge == 0 ) return ; - if ( (edge->ea == 0) && (edge->eb == 0) ) + if( (edge->ea == 0) && (edge->eb == 0) ) func( edge, reverse, arg1, arg2, process_id ) ; else { - if ( reverse ) + if( reverse ) { first = edge->eb ; second = edge->ea ; @@ -407,9 +407,9 @@ void foreach_leaf_edge(Edge *edge, long reverse, void (*func)(), long arg1, long first = edge->ea ; second = edge->eb ; } - if ( first ) + if( first ) foreach_leaf_edge( first, reverse, func, arg1, arg2, process_id ) ; - if ( second ) + if( second ) foreach_leaf_edge( second, reverse, func, arg1, arg2, process_id ) ; } } @@ -452,7 +452,7 @@ void subdivide_edge(Edge *e, float a_ratio, long process_id) LOCK(e->edge_lock->lock); /* Check if the element already has children */ - if ( ! _LEAF_EDGE(e) ) + if( ! _LEAF_EDGE(e) ) { UNLOCK(e->edge_lock->lock); return ; @@ -499,7 +499,7 @@ Edge *get_edge(long process_id) { Edge *edge ; - if ( sobj_struct[process_id].n_local_free_edge == 0 ) + if( sobj_struct[process_id].n_local_free_edge == 0 ) { LOCK(global->free_edge_lock); if ( MAX_EDGES - global->free_edge < N_EDGE_ALLOCATE ) @@ -548,7 +548,7 @@ void init_edge(long process_id) global->free_edge = 0 ; /* Allocate locks */ - for ( edge_cnt = 0 ; edge_cnt < MAX_EDGES ; edge_cnt++ ) + for( edge_cnt = 0 ; edge_cnt < MAX_EDGES ; edge_cnt++ ) global->edge_buf[ edge_cnt ].edge_lock = get_sharedlock( SHARED_LOCK_SEG0, process_id ) ; @@ -583,7 +583,7 @@ void init_sharedlock(long process_id) { long i ; - for ( i = 0 ; i < MAX_SHARED_LOCK ; i++ ) + for( i = 0 ; i < MAX_SHARED_LOCK ; i++ ) { LOCKINIT(global->sh_lock[i].lock); } @@ -627,7 +627,7 @@ Shared_Lock *get_sharedlock(long segment, long process_id) /* Update the lock counter */ sobj_struct[process_id].lock_alloc_counter++ ; - if ( sobj_struct[process_id].lock_alloc_counter >= MAX_SHARED_LOCK ) + if( sobj_struct[process_id].lock_alloc_counter >= MAX_SHARED_LOCK ) sobj_struct[process_id].lock_alloc_counter = 0 ; return( pshl ) ; diff --git a/splash2/codes/apps/radiosity/structs.H b/splash2/codes/apps/radiosity/structs.H index c1498228f..e9bc9a18f 100644 --- a/splash2/codes/apps/radiosity/structs.H +++ b/splash2/codes/apps/radiosity/structs.H @@ -8,7 +8,7 @@ *************************************************************************/ typedef struct { - float x, y, z ; + float x, y, z ; } Vertex; /************************************************************************ @@ -18,7 +18,7 @@ typedef struct { *************************************************************************/ typedef struct { - float r, g, b ; + float r, g, b ; } Rgb; /************************************************************************ @@ -28,7 +28,7 @@ typedef struct { *************************************************************************/ typedef struct { - float x, y, z; + float x, y, z; } Ray; #endif diff --git a/splash2/codes/apps/radiosity/taskman.C b/splash2/codes/apps/radiosity/taskman.C index c17ce431f..30d1318b5 100644 --- a/splash2/codes/apps/radiosity/taskman.C +++ b/splash2/codes/apps/radiosity/taskman.C @@ -24,7 +24,7 @@ * *************************************************************************/ -#include +#include EXTERN_ENV; @@ -67,7 +67,7 @@ void process_tasks(long process_id) t = DEQUEUE_TASK( taskqueue_id[process_id], QUEUES_VISITED, process_id ) ; retry_entry: - while ( t ) + while( t ) { switch( t->task_type ) { @@ -107,7 +107,7 @@ void process_tasks(long process_id) LOCK(global->pbar_lock); /* Reset the barrier counter if not initialized */ - if ( global->pbar_count >= n_processors ) + if( global->pbar_count >= n_processors ) global->pbar_count = 0 ; /* Increment the counter */ @@ -115,16 +115,16 @@ void process_tasks(long process_id) UNLOCK(global->pbar_lock); /* barrier spin-wait loop */ - while ( global->pbar_count < n_processors ) + while( global->pbar_count < n_processors ) { /* Wait for a while and then retry dequeue */ - if ( _process_task_wait_loop() ) + if( _process_task_wait_loop() ) break ; /* Waited for a while but other processors are still running. Poll the task queue again */ t = DEQUEUE_TASK( taskqueue_id[process_id], QUEUES_VISITED, process_id ) ; - if ( t ) + if( t ) { /* Task found. Exit the barrier and work on it */ LOCK(global->pbar_lock); @@ -145,9 +145,9 @@ long _process_task_wait_loop() long finished = 0 ; /* Wait for a while and then retry */ - for ( i = 0 ; i < 1000 && ! finished ; i++ ) + for( i = 0 ; i < 1000 && ! finished ; i++ ) { - if ( ((i & 0xff) == 0) && ((volatile long)global->pbar_count >= n_processors) ) + if( ((i & 0xff) == 0) && ((volatile long)global->pbar_count >= n_processors) ) finished = 1 ; } @@ -193,7 +193,7 @@ void create_ff_refine_task(Element *e1, Element *e2, long level, long process_id Task *t ; /* Check existing parallelism */ - if ( taskq_too_long(&global->task_queue[ taskqueue_id[process_id] ]) ) + if( taskq_too_long(&global->task_queue[ taskqueue_id[process_id] ]) ) { /* Task queue is too long. Solve it immediately */ ff_refine_elements( e1, e2, level, process_id ) ; @@ -217,7 +217,7 @@ void create_ff_refine_task(Element *e1, Element *e2, long level, long process_id void create_ray_task(Element *e, long process_id) { /* Check existing parallelism */ - if ( ((e->n_interactions + e->n_vis_undef_inter) + if( ((e->n_interactions + e->n_vis_undef_inter) < N_inter_parallel_bf_refine) || taskq_too_long(&global->task_queue[ taskqueue_id[process_id] ]) ) { @@ -257,11 +257,11 @@ void create_visibility_tasks(Element *e, void (*k)(), long process_id) long tasks_created = 0 ; /* Check number of hard problems */ - for ( top = e->vis_undef_inter ; top ; top = top->next ) - if ( top->visibility == VISIBILITY_UNDEF ) + for( top = e->vis_undef_inter ; top ; top = top->next ) + if( top->visibility == VISIBILITY_UNDEF ) total_undefs++ ; - if ( total_undefs == 0 ) + if( total_undefs == 0 ) { /* No process needs to be created. Call the continuation immediately */ @@ -270,7 +270,7 @@ void create_visibility_tasks(Element *e, void (*k)(), long process_id) } /* Check existing parallelism */ - if ( (total_undefs < N_visibility_per_task) + if( (total_undefs < N_visibility_per_task) || taskq_too_long(&global->task_queue[ taskqueue_id[process_id] ]) ) { /* Task size is small, or the queue is too long. @@ -293,24 +293,24 @@ void create_visibility_tasks(Element *e, void (*k)(), long process_id) / N_visibility_per_task ; remainder = 0 ; i_cnt = 0 ; - for ( top = e->vis_undef_inter, tail = top ; tail ; tail = tail->next ) + for( top = e->vis_undef_inter, tail = top ; tail ; tail = tail->next ) { i_cnt++ ; - if ( tail->visibility != VISIBILITY_UNDEF ) + if( tail->visibility != VISIBILITY_UNDEF ) continue ; remainder += n_tasks ; - if ( remainder >= total_undefs ) + if( remainder >= total_undefs ) { /* Create a task */ /* For the last task, append following (easy) interactions if there is any */ tasks_created++ ; - if ( tasks_created >= n_tasks ) - for ( ; tail->next ; tail = tail->next, i_cnt++ ) ; + if( tasks_created >= n_tasks ) + for( ; tail->next ; tail = tail->next, i_cnt++ ) ; /* Set task descriptor */ t = get_task(process_id) ; @@ -337,7 +337,7 @@ void create_visibility_tasks(Element *e, void (*k)(), long process_id) void create_radavg_task(Element *e, long mode, long process_id) { /* Check existing parallelism */ - if ( (e->n_interactions < N_inter_parallel_bf_refine) + if( (e->n_interactions < N_inter_parallel_bf_refine) || taskq_too_long(&global->task_queue[ taskqueue_id[process_id] ]) ) { /* Task size is too small or queue is too long. @@ -384,7 +384,7 @@ void enqueue_task(long qid, Task *task, long mode) /* Lock the task queue */ LOCK(tq->q_lock); - if ( tq->tail == 0 ) + if( tq->tail == 0 ) { /* The first task in the queue */ tq->tail = task ; @@ -394,7 +394,7 @@ void enqueue_task(long qid, Task *task, long mode) else { /* Usual case */ - if ( mode == TASK_APPEND ) + if( mode == TASK_APPEND ) { tq->tail->next = task ; tq->tail = task ; @@ -433,37 +433,37 @@ Task *dequeue_task(long qid, long max_visit, long process_id) long offset ; /* Check number of queues to be visited */ - if ( max_visit > n_taskqueues ) + if( max_visit > n_taskqueues ) max_visit = n_taskqueues ; /* Get next task */ - while ( visit_count < max_visit ) + while( visit_count < max_visit ) { /* Select a task queue */ tq = &global->task_queue[ qid ] ; /* Check the length (test-test&set) */ - if ( tq->n_tasks > 0 ) + if( tq->n_tasks > 0 ) { /* Lock the task queue */ LOCK(tq->q_lock); - if ( tq->top ) + if( tq->top ) { - if ( qid == taskqueue_id[process_id] ) + if( qid == taskqueue_id[process_id] ) { t = tq->top ; tq->top = t->next ; - if ( tq->top == 0 ) + if( tq->top == 0 ) tq->tail = 0 ; tq->n_tasks-- ; } else { /* Get tail */ - for ( prev = 0, t = tq->top ; t->next ; + for( prev = 0, t = tq->top ; t->next ; prev = t, t = t->next ) ; - if ( prev == 0 ) + if( prev == 0 ) tq->top = 0 ; else prev->next = 0 ; @@ -484,9 +484,9 @@ Task *dequeue_task(long qid, long max_visit, long process_id) sign = -sign ; qid += offset ; - if ( qid < 0 ) + if( qid < 0 ) qid += n_taskqueues ; - else if ( qid >= n_taskqueues ) + else if( qid >= n_taskqueues ) qid -= n_taskqueues ; } @@ -511,22 +511,22 @@ Task *get_task(long process_id) long retry_count = 0 ; /* First, check local task queue */ - if ( task_struct[process_id].local_free_task == 0 ) + if( task_struct[process_id].local_free_task == 0 ) { /* If empty, allocate task objects from the shared list */ q_id = taskqueue_id[process_id] ; - while ( task_struct[process_id].local_free_task == 0 ) + while( task_struct[process_id].local_free_task == 0 ) { tq = &global->task_queue[ q_id ] ; - if ( tq->n_free > 0 ) + if( tq->n_free > 0 ) { LOCK(tq->f_lock); - if ( tq->free ) + if( tq->free ) { /* Scan the free list */ - for ( i = 1, p = tq->free ; + for( i = 1, p = tq->free ; (i < N_ALLOCATE_LOCAL_TASK) && p->next ; i++, p = p->next ) ; @@ -542,11 +542,11 @@ Task *get_task(long process_id) } /* Try next task queue */ - if ( ++q_id >= n_taskqueues ) + if( ++q_id >= n_taskqueues ) q_id = 0 ; /* Check retry count */ - if ( ++retry_count > MAX_TASKGET_RETRY ) + if( ++retry_count > MAX_TASKGET_RETRY ) { fprintf( stderr, "Panic(P%ld):No free task\n", process_id ) ; @@ -587,11 +587,11 @@ void free_task(Task *task, long process_id) task_struct[process_id].n_local_free_task++ ; /* If local list is too long, export some tasks */ - if ( task_struct[process_id].n_local_free_task >= (N_ALLOCATE_LOCAL_TASK * 2) ) + if( task_struct[process_id].n_local_free_task >= (N_ALLOCATE_LOCAL_TASK * 2) ) { tq = &global->task_queue[ taskqueue_id[process_id] ] ; - for ( i = 1, p = task_struct[process_id].local_free_task ; + for( i = 1, p = task_struct[process_id].local_free_task ; i < N_ALLOCATE_LOCAL_TASK ; i++, p = p->next ) ; /* Update local list */ @@ -634,7 +634,7 @@ void init_taskq(long process_id) /* Initialize task queues */ task_per_queue = (MAX_TASKS + n_taskqueues - 1) / n_taskqueues ; - for ( qid = 0 ; qid < n_taskqueues ; qid++ ) + for( qid = 0 ; qid < n_taskqueues ; qid++ ) { /* Initialize free list */ if (task_index + task_per_queue > MAX_TASKS ) @@ -642,7 +642,7 @@ void init_taskq(long process_id) else n_tasks = task_per_queue ; - for ( i = task_index ; i < task_index + n_tasks - 1 ; i++ ) + for( i = task_index ; i < task_index + n_tasks - 1 ; i++ ) global->task_buf[i].next = &global->task_buf[i+1] ; global->task_buf[ i ].next = 0 ; @@ -684,12 +684,12 @@ long check_task_counter() LOCK(global->task_counter_lock); - if ( global->task_counter == 0 ) + if( global->task_counter == 0 ) /* First processor */ flag = 1 ; global->task_counter++ ; - if ( global->task_counter >= n_processors ) + if( global->task_counter >= n_processors ) global->task_counter = 0 ; UNLOCK(global->task_counter_lock); @@ -713,7 +713,7 @@ long assign_taskq(long process_id) qid = task_struct[process_id].crnt_taskq_id++ ; - if ( task_struct[process_id].crnt_taskq_id >= n_taskqueues ) + if( task_struct[process_id].crnt_taskq_id >= n_taskqueues ) task_struct[process_id].crnt_taskq_id = 0 ; return( qid ) ; @@ -731,7 +731,7 @@ long assign_taskq(long process_id) void print_task(Task *task) { - if ( task == 0 ) + if( task == 0 ) { printf( "Task (NULL)\n" ) ; return ; @@ -770,7 +770,7 @@ void print_taskq(Task_Queue *tq) Task *t ; printf( "TaskQ: %ld tasks in the queue\n", taskq_length(tq) ) ; - for ( t = taskq_top(tq) ; t ; t = t->next ) + for( t = taskq_top(tq) ; t ; t = t->next ) { printf( " " ) ; print_task( t ) ; diff --git a/splash2/codes/apps/radiosity/visible.C b/splash2/codes/apps/radiosity/visible.C index 916973ebc..e77b42cac 100644 --- a/splash2/codes/apps/radiosity/visible.C +++ b/splash2/codes/apps/radiosity/visible.C @@ -21,8 +21,8 @@ * ***************************************************************/ -#include -#include +#include +#include EXTERN_ENV; @@ -143,7 +143,7 @@ void get_test_rays(Vertex *p_src, Ray *v, long no, long process_id) Vertex p_dst ; float fv1, fv2 ; - if ( no > VISI_RAYS_MAX ) + if( no > VISI_RAYS_MAX ) no = VISI_RAYS_MAX ; for (i = 0, g_index = 0 ; i < no; i++, g_index++) { @@ -330,37 +330,37 @@ long traverse_bsp(Patch *src_node, Vertex *p, Ray *ray, float r_min, float r_max /* (1) Check patch cache */ - if ( check_patch_cache( p, ray, r_min, r_max, process_id ) ) + if( check_patch_cache( p, ray, r_min, r_max, process_id ) ) return( 1 ) ; /* (2) Check S+(src_node) */ - if ( traverse_subtree( src_node->bsp_positive, p, ray, r_min, r_max, process_id ) ) + if( traverse_subtree( src_node->bsp_positive, p, ray, r_min, r_max, process_id ) ) return( 1 ) ; /* (3) Continue in-order traversal till root is encountered */ - for ( parent = src_node->bsp_parent, visited_child = src_node ; + for( parent = src_node->bsp_parent, visited_child = src_node ; parent ; visited_child = parent, parent = parent->bsp_parent ) { /* Check intersection at this node */ advice = intersection_type( parent, p, ray, &t, r_min, r_max ) ; - if ( (advice != POSITIVE_SUBTREE_ONLY) && (advice != NEGATIVE_SUBTREE_ONLY) ) + if( (advice != POSITIVE_SUBTREE_ONLY) && (advice != NEGATIVE_SUBTREE_ONLY) ) { - if ( test_intersection( parent, p, ray, t, process_id ) ) + if( test_intersection( parent, p, ray, t, process_id ) ) return( 1 ) ; r_min = t - VIS_RANGE_MARGIN ; } /* Traverse unvisited subtree of the node */ - if ( (parent->bsp_positive == visited_child) && (advice != POSITIVE_SUBTREE_ONLY) ) + if( (parent->bsp_positive == visited_child) && (advice != POSITIVE_SUBTREE_ONLY) ) { - if ( traverse_subtree( parent->bsp_negative, p, ray, r_min, r_max, process_id ) ) + if( traverse_subtree( parent->bsp_negative, p, ray, r_min, r_max, process_id ) ) return( 1 ) ; } - else if ( (parent->bsp_positive != visited_child) && (advice != NEGATIVE_SUBTREE_ONLY) ) + else if( (parent->bsp_positive != visited_child) && (advice != NEGATIVE_SUBTREE_ONLY) ) { - if ( traverse_subtree( parent->bsp_positive, p, ray, r_min, r_max, process_id ) ) + if( traverse_subtree( parent->bsp_positive, p, ray, r_min, r_max, process_id ) ) return( 1 ) ; } } @@ -389,39 +389,39 @@ long traverse_subtree(Patch *node, Vertex *p, Ray *ray, float r_min, float r_max long advice ; - if ( node == 0 ) + if( node == 0 ) return( 0 ) ; advice = intersection_type( node, p, ray, &t, r_min, r_max ) ; - if ( advice == POSITIVE_SIDE_FIRST ) + if( advice == POSITIVE_SIDE_FIRST ) { /* The ray is approaching from the positive side of the patch */ - if ( traverse_subtree( node->bsp_positive, p, ray, + if( traverse_subtree( node->bsp_positive, p, ray, r_min, t + VIS_RANGE_MARGIN, process_id ) ) return( 1 ) ; - if ( test_intersection( node, p, ray, t, process_id ) ) + if( test_intersection( node, p, ray, t, process_id ) ) return( 1 ) ; return( traverse_subtree( node->bsp_negative, p, ray, t - VIS_RANGE_MARGIN, r_max, process_id ) ) ; } - else if ( advice == NEGATIVE_SIDE_FIRST ) + else if( advice == NEGATIVE_SIDE_FIRST ) { /* The ray is approaching from the negative side of the patch */ - if ( traverse_subtree( node->bsp_negative, p, ray, + if( traverse_subtree( node->bsp_negative, p, ray, r_min, t + VIS_RANGE_MARGIN, process_id ) ) return( 1 ) ; - if ( test_intersection( node, p, ray, t, process_id ) ) + if( test_intersection( node, p, ray, t, process_id ) ) return( 1 ) ; return( traverse_subtree( node->bsp_positive, p, ray, t - VIS_RANGE_MARGIN, r_max, process_id ) ) ; } - else if ( advice == POSITIVE_SUBTREE_ONLY ) + else if( advice == POSITIVE_SUBTREE_ONLY ) return( traverse_subtree( node->bsp_positive, p, ray, r_min, r_max, process_id ) ) ; - else if ( advice == NEGATIVE_SUBTREE_ONLY ) + else if( advice == NEGATIVE_SUBTREE_ONLY ) return( traverse_subtree( node->bsp_negative, p, ray, r_min, r_max, process_id ) ) ; else @@ -469,11 +469,11 @@ long intersection_type(Patch *patch, Vertex *p, Ray *ray, float *tval, float ra r_dot_n = nx * ray->x + ny * ray->y + nz * ray->z ; dist = patch->plane_equ.c + p->x * nx + p->y * ny + p->z * nz ; - if ( (-(float)F_ZERO < r_dot_n) && (r_dot_n < (float)F_ZERO) ) + if( (-(float)F_ZERO < r_dot_n) && (r_dot_n < (float)F_ZERO) ) { - if ( dist > (float)F_COPLANAR ) + if( dist > (float)F_COPLANAR ) return( POSITIVE_SUBTREE_ONLY ) ; - else if ( dist < -F_COPLANAR ) + else if( dist < -F_COPLANAR ) return( NEGATIVE_SUBTREE_ONLY ) ; return( ON_THE_PLANE ) ; @@ -482,23 +482,23 @@ long intersection_type(Patch *patch, Vertex *p, Ray *ray, float *tval, float ra t = -dist / r_dot_n ; *tval = t ; - if ( t < range_min ) + if( t < range_min ) { - if ( r_dot_n >= 0 ) + if( r_dot_n >= 0 ) return( POSITIVE_SUBTREE_ONLY ) ; else return( NEGATIVE_SUBTREE_ONLY ) ; } else if ( t > range_max ) { - if ( r_dot_n >= 0 ) + if( r_dot_n >= 0 ) return( NEGATIVE_SUBTREE_ONLY ) ; else return( POSITIVE_SUBTREE_ONLY ) ; } else { - if ( r_dot_n >= 0 ) + if( r_dot_n >= 0 ) return( NEGATIVE_SIDE_FIRST ) ; else return( POSITIVE_SIDE_FIRST ) ; @@ -517,16 +517,16 @@ long test_intersection(Patch *patch, Vertex *p, Ray *ray, float tval, long proce /* Rays always hit the destination. Note that (R.Ndest) is already checked by visibility() */ - if ( patch == vis_struct[process_id].v_dest_patch ) + if( patch == vis_struct[process_id].v_dest_patch ) { vis_struct[process_id].pool_dst_hits++ ; return( 1 ) ; } - if ( patch_tested( patch, process_id ) ) + if( patch_tested( patch, process_id ) ) return( 0 ) ; - if ( v_intersect( patch, p, ray, tval ) ) + if( v_intersect( patch, p, ray, tval ) ) { /* Store it in the patch-cache */ update_patch_cache( patch, process_id ) ; @@ -563,7 +563,7 @@ void update_patch_cache(Patch *patch, long process_id) long i ; /* Shift current contents */ - for ( i = PATCH_CACHE_SIZE-1 ; i > 0 ; i-- ) + for( i = PATCH_CACHE_SIZE-1 ; i > 0 ; i-- ) vis_struct[process_id].patch_cache[i] = vis_struct[process_id].patch_cache[i-1] ; /* Store the new patch data */ @@ -579,9 +579,9 @@ long check_patch_cache(Vertex *p, Ray *ray, float r_min, float r_max, long proce Patch *temp ; long advice ; - for ( i = 0 ; i < PATCH_CACHE_SIZE ; i++ ) + for( i = 0 ; i < PATCH_CACHE_SIZE ; i++ ) { - if ( (vis_struct[process_id].patch_cache[i] == 0) + if( (vis_struct[process_id].patch_cache[i] == 0) || (vis_struct[process_id].patch_cache[i] == vis_struct[process_id].v_dest_patch) || (vis_struct[process_id].patch_cache[i] == vis_struct[process_id].v_src_patch) ) continue ; @@ -589,14 +589,14 @@ long check_patch_cache(Vertex *p, Ray *ray, float r_min, float r_max, long proce advice = intersection_type( vis_struct[process_id].patch_cache[i], p, ray, &t, r_min, r_max ) ; /* If no intersection, then skip */ - if ( (advice == POSITIVE_SUBTREE_ONLY) + if( (advice == POSITIVE_SUBTREE_ONLY) || (advice == NEGATIVE_SUBTREE_ONLY) ) continue ; - if ( (advice == ON_THE_PLANE) || v_intersect( vis_struct[process_id].patch_cache[i], p, ray, t ) ) + if( (advice == ON_THE_PLANE) || v_intersect( vis_struct[process_id].patch_cache[i], p, ray, t ) ) { /* Change priority */ - if ( i > 0 ) + if( i > 0 ) { temp = vis_struct[process_id].patch_cache[ i-1 ] ; vis_struct[process_id].patch_cache[ i-1 ] = vis_struct[process_id].patch_cache[ i ] ; @@ -617,7 +617,7 @@ void init_patch_cache(long process_id) { long i ; - for ( i = 0 ; i < PATCH_CACHE_SIZE ; i++ ) + for( i = 0 ; i < PATCH_CACHE_SIZE ; i++ ) vis_struct[process_id].patch_cache[ i ] = 0 ; } @@ -626,9 +626,9 @@ long patch_tested(Patch *p, long process_id) { long i ; - for ( i = 0 ; i < PATCH_CACHE_SIZE ; i++ ) + for( i = 0 ; i < PATCH_CACHE_SIZE ; i++ ) { - if ( p == vis_struct[process_id].patch_cache[i] ) + if( p == vis_struct[process_id].patch_cache[i] ) return( 1 ) ; } @@ -714,9 +714,9 @@ float visibility(Element *e1, Element *e2, long n_rays, long process_id) void compute_visibility_values(Element *elem, Interaction *inter, long n_inter, long process_id) { - for ( ; n_inter > 0 ; inter = inter->next, n_inter-- ) + for( ; n_inter > 0 ; inter = inter->next, n_inter-- ) { - if ( inter->visibility != VISIBILITY_UNDEF ) + if( inter->visibility != VISIBILITY_UNDEF ) continue ; vis_struct[process_id].bsp_nodes_visited = 0 ; @@ -764,6 +764,6 @@ void visibility_task(Element *elem, Interaction *inter, long n_inter, void (*k)( #endif /* Call continuation if this is the last task finished. */ - if ( new_vis_undef_count == 0 ) + if( new_vis_undef_count == 0 ) k( elem, process_id ) ; } diff --git a/splash2/codes/apps/raytrace/bbox.C b/splash2/codes/apps/raytrace/bbox.C index 1d766266b..9dc4945f0 100644 --- a/splash2/codes/apps/raytrace/bbox.C +++ b/splash2/codes/apps/raytrace/bbox.C @@ -25,11 +25,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + /* * NAME * InquireBoundBoxValues - return min and max bound values for each coordinate axis @@ -45,14 +46,14 @@ */ VOID InquireBoundBoxValues(BBOX *pbb, REAL *minx, REAL *miny, REAL *minz, REAL *maxx, REAL *maxy, REAL *maxz) - { - *minx = pbb->dnear[0]; - *miny = pbb->dnear[1]; - *minz = pbb->dnear[2]; - *maxx = pbb->dfar[0]; - *maxy = pbb->dfar[1]; - *maxz = pbb->dfar[2]; - } + { + *minx = pbb->dnear[0]; + *miny = pbb->dnear[1]; + *minz = pbb->dnear[2]; + *maxx = pbb->dfar[0]; + *maxy = pbb->dfar[1]; + *maxz = pbb->dfar[2]; + } @@ -70,31 +71,31 @@ VOID InquireBoundBoxValues(BBOX *pbb, REAL *minx, REAL *miny, REAL *minz, REAL * */ VOID NormalizeBoundBox(BBOX *pbb, MATRIX mat) - { - POINT tmp; + { + POINT tmp; - /* dnear and dfar are only vectors of length 3 */ + /* dnear and dfar are only vectors of length 3 */ - tmp[0] = pbb->dnear[0]; - tmp[1] = pbb->dnear[1]; - tmp[2] = pbb->dnear[2]; - tmp[3] = 1.0; + tmp[0] = pbb->dnear[0]; + tmp[1] = pbb->dnear[1]; + tmp[2] = pbb->dnear[2]; + tmp[3] = 1.0; - VecMatMult(tmp, mat, tmp); + VecMatMult(tmp, mat, tmp); - pbb->dnear[0] = tmp[0]; - pbb->dnear[1] = tmp[1]; - pbb->dnear[2] = tmp[2]; + pbb->dnear[0] = tmp[0]; + pbb->dnear[1] = tmp[1]; + pbb->dnear[2] = tmp[2]; - tmp[0] = pbb->dfar[0]; - tmp[1] = pbb->dfar[1]; - tmp[2] = pbb->dfar[2]; - tmp[3] = 1.0; + tmp[0] = pbb->dfar[0]; + tmp[1] = pbb->dfar[1]; + tmp[2] = pbb->dfar[2]; + tmp[3] = 1.0; - VecMatMult(tmp, mat, tmp); + VecMatMult(tmp, mat, tmp); - pbb->dfar[0] = tmp[0]; - pbb->dfar[1] = tmp[1]; - pbb->dfar[2] = tmp[2]; - } + pbb->dfar[0] = tmp[0]; + pbb->dfar[1] = tmp[1]; + pbb->dfar[2] = tmp[2]; + } diff --git a/splash2/codes/apps/raytrace/cr.C b/splash2/codes/apps/raytrace/cr.C index 3c5005cca..31291cae9 100644 --- a/splash2/codes/apps/raytrace/cr.C +++ b/splash2/codes/apps/raytrace/cr.C @@ -26,16 +26,17 @@ */ -#include -#include - +#include +#include #include "rt.h" + + GRID *gridlist = NULL; /* - Note: gridlist doesn't need to be an array since it is only used when - building HUG, which is done before child process creation + Note: gridlist doesn't need to be an array since it is only used when + building HUG, which is done before child process creation */ @@ -52,20 +53,20 @@ GRID *gridlist = NULL; */ VOID prn_gridlist() - { - GRID *g; + { + GRID *g; - fprintf(stderr, " Print Gridlist \n"); - g = gridlist; + fprintf(stderr, " Print Gridlist \n"); + g = gridlist; - while (g != NULL) - { - prn_grid(g); - g = g->next; - } + while (g != NULL) + { + prn_grid(g); + g = g->next; + } - fprintf(stderr, " End Gridlist \n"); - } + fprintf(stderr, " End Gridlist \n"); + } @@ -81,31 +82,31 @@ VOID prn_gridlist() */ VOID prn_ds_stats() - { - INT leafs; - INT voxels; + { + INT leafs; + INT voxels; - printf("\n"); - printf("****** Hierarchical uniform grid data structure statistics ******\n\n"); + printf("\n"); + printf("****** Hierarchical uniform grid data structure statistics ******\n\n"); - printf(" Data structure evaluated as a preprocess.\n"); + printf(" Data structure evaluated as a preprocess.\n"); - printf(" gridsize %3ld \n", hu_gridsize); - printf(" hashtable buckets %3ld \n", hu_numbuckets); - printf(" maximum subdivision level %3ld \n", hu_max_subdiv_level); - printf(" maximum primitives / cell %3ld \n", hu_max_prims_cell); - printf(" grids %3ld \n", grids); + printf(" gridsize %3ld \n", hu_gridsize); + printf(" hashtable buckets %3ld \n", hu_numbuckets); + printf(" maximum subdivision level %3ld \n", hu_max_subdiv_level); + printf(" maximum primitives / cell %3ld \n", hu_max_prims_cell); + printf(" grids %3ld \n", grids); - voxels = empty_voxels + nonempty_voxels; - leafs = empty_voxels + nonempty_leafs; + voxels = empty_voxels + nonempty_voxels; + leafs = empty_voxels + nonempty_leafs; - printf(" empty voxels %8ld %3ld %% \n", empty_voxels, 100*empty_voxels/voxels); - printf(" nonempty voxels %8ld %3ld %% \n", nonempty_voxels, 100*nonempty_voxels/voxels); - printf(" empty leafs %8ld %3ld %% \n", empty_voxels, 100*empty_voxels/leafs); - printf(" nonempty leafs %8ld %3ld %% \n", nonempty_leafs, 100*nonempty_leafs/leafs); - printf(" primitives / leaf %6.1lf \n", (double)prims_in_leafs/leafs); - printf("\n"); - } + printf(" empty voxels %8ld %3ld %% \n", empty_voxels, 100*empty_voxels/voxels); + printf(" nonempty voxels %8ld %3ld %% \n", nonempty_voxels, 100*nonempty_voxels/voxels); + printf(" empty leafs %8ld %3ld %% \n", empty_voxels, 100*empty_voxels/leafs); + printf(" nonempty leafs %8ld %3ld %% \n", nonempty_leafs, 100*nonempty_leafs/leafs); + printf(" primitives / leaf %6.1lf \n", (double)prims_in_leafs/leafs); + printf("\n"); + } @@ -121,18 +122,18 @@ VOID prn_ds_stats() */ VOID init_masks() - { - INT n, i; + { + INT n, i; - n = sizeof(UINT)*8; + n = sizeof(UINT)*8; - for (i = 0; i < n; i++) - { - empty_masks[i] = (MSB >> i); - nonempty_masks[i] = ~empty_masks[i]; - } + for (i = 0; i < n; i++) + { + empty_masks[i] = (MSB >> i); + nonempty_masks[i] = ~empty_masks[i]; + } - } + } /* @@ -151,53 +152,53 @@ VOID init_masks() */ GRID *init_world_grid(VOXEL *v, ELEMENT **pepa, INT num_pe) - { - UINT *ec; - BBOX wbox; - GRID *g; - VOXEL **ht; + { + UINT *ec; + BBOX wbox; + GRID *g; + VOXEL **ht; - g = ObjectMalloc(OT_GRID, 1); - g->id = grids++; + g = ObjectMalloc(OT_GRID, 1); + g->id = grids++; - ht = ObjectMalloc(OT_HASHTABLE, 1); + ht = ObjectMalloc(OT_HASHTABLE, 1); - g->hashtable = ht; - g->hashtable[0] = v; + g->hashtable = ht; + g->hashtable[0] = v; - ec = ObjectMalloc(OT_EMPTYCELLS, 1); + ec = ObjectMalloc(OT_EMPTYCELLS, 1); - g->emptycells = ec; - g->emptycells[0] = 0; /* nonempty */ + g->emptycells = ec; + g->emptycells[0] = 0; /* nonempty */ - g->indx_inc[0] = 1; - g->indx_inc[1] = 1; - g->indx_inc[2] = 1; - g->num_buckets = 1; + g->indx_inc[0] = 1; + g->indx_inc[1] = 1; + g->indx_inc[2] = 1; + g->num_buckets = 1; - wbox.dnear[0] = 0.0; - wbox.dnear[1] = 0.0; - wbox.dnear[2] = 0.0; - wbox.dfar[0] = 1.0; - wbox.dfar[1] = 1.0; - wbox.dfar[2] = 1.0; + wbox.dnear[0] = 0.0; + wbox.dnear[1] = 0.0; + wbox.dnear[2] = 0.0; + wbox.dfar[0] = 1.0; + wbox.dfar[1] = 1.0; + wbox.dfar[2] = 1.0; - g->min[0] = wbox.dnear[0]; - g->min[1] = wbox.dnear[1]; - g->min[2] = wbox.dnear[2]; + g->min[0] = wbox.dnear[0]; + g->min[1] = wbox.dnear[1]; + g->min[2] = wbox.dnear[2]; - g->cellsize[0] = wbox.dfar[0] - wbox.dnear[0]; - g->cellsize[1] = wbox.dfar[1] - wbox.dnear[1]; - g->cellsize[2] = wbox.dfar[2] - wbox.dnear[2]; + g->cellsize[0] = wbox.dfar[0] - wbox.dnear[0]; + g->cellsize[1] = wbox.dfar[1] - wbox.dnear[1]; + g->cellsize[2] = wbox.dfar[2] - wbox.dnear[2]; - g->subdiv_level = - 1; - g->num_prims = num_pe; - g->pepa = pepa; - g->next = NULL; + g->subdiv_level = - 1; + g->num_prims = num_pe; + g->pepa = pepa; + g->next = NULL; - gridlist = g; - return (g); - } + gridlist = g; + return (g); + } @@ -216,21 +217,21 @@ GRID *init_world_grid(VOXEL *v, ELEMENT **pepa, INT num_pe) */ VOXEL *init_world_voxel(ELEMENT **pepa, INT numelements) - { - VOXEL *v; + { + VOXEL *v; - v = ObjectMalloc(OT_VOXEL, 1); + v = ObjectMalloc(OT_VOXEL, 1); - nonempty_voxels++; + nonempty_voxels++; - v->id = 0; - v->cell = (CHAR *)pepa; - v->numelements = numelements; - v->celltype = GSM_VOXEL; - v->next = NULL; + v->id = 0; + v->cell = (CHAR *)pepa; + v->numelements = numelements; + v->celltype = GSM_VOXEL; + v->next = NULL; - return (v); - } + return (v); + } @@ -248,17 +249,17 @@ VOXEL *init_world_voxel(ELEMENT **pepa, INT numelements) */ VOID mark_empty(INT index1D, GRID *g) - { - INT i, r; - UINT w; + { + INT i, r; + UINT w; - i = index1D/(sizeof(UINT)*8); - r = index1D - i*sizeof(UINT)*8; + i = index1D/(sizeof(UINT)*8); + r = index1D - i*sizeof(UINT)*8; - w = g->emptycells[i]; - w = w | empty_masks[r]; - g->emptycells[i] = w; - } + w = g->emptycells[i]; + w = w | empty_masks[r]; + g->emptycells[i] = w; + } @@ -276,17 +277,17 @@ VOID mark_empty(INT index1D, GRID *g) */ VOID mark_nonempty(INT index1D, GRID *g) - { - INT i, r; - UINT w; + { + INT i, r; + UINT w; - i = index1D/(sizeof(UINT)*8); - r = index1D - i*sizeof(UINT)*8; + i = index1D/(sizeof(UINT)*8); + r = index1D - i*sizeof(UINT)*8; - w = g->emptycells[i]; - w = w & nonempty_masks[r]; - g->emptycells[i] = w; - } + w = g->emptycells[i]; + w = w & nonempty_masks[r]; + g->emptycells[i] = w; + } @@ -304,17 +305,17 @@ VOID mark_nonempty(INT index1D, GRID *g) */ VOID insert_in_hashtable(VOXEL *v, GRID *g) - { - INT i, r; - VOXEL *vht; + { + INT i, r; + VOXEL *vht; - i = v->id/hu_numbuckets; - r = v->id - i*hu_numbuckets; + i = v->id/hu_numbuckets; + r = v->id - i*hu_numbuckets; - vht = g->hashtable[r]; - v->next = vht; - g->hashtable[r] = v; - } + vht = g->hashtable[r]; + v->next = vht; + g->hashtable[r] = v; + } /* @@ -334,88 +335,88 @@ VOID insert_in_hashtable(VOXEL *v, GRID *g) */ ELEMENT **prims_in_box2(ELEMENT **pepa, INT n_in, BBOX b, INT *n) - { - INT ovlap, i, j, k; - ELEMENT *pe; - ELEMENT **npepa; - BBOX bb; - REAL max, side, eps; + { + INT ovlap, i, j, k; + ELEMENT *pe; + ELEMENT **npepa; + BBOX bb; + REAL max, side, eps; - max = b.dfar[0] - b.dnear[0]; - side = b.dfar[1] - b.dnear[1]; + max = b.dfar[0] - b.dnear[0]; + side = b.dfar[1] - b.dnear[1]; - max = max > side ? max : side; - side = b.dfar[2] - b.dnear[2]; + max = max > side ? max : side; + side = b.dfar[2] - b.dnear[2]; - max = max > side ? max : side; - eps = max * 1.0E-6; + max = max > side ? max : side; + eps = max * 1.0E-6; - if (n_in > 0) - npepa = ObjectMalloc(OT_PEPARRAY, n_in); - else - { - npepa = NULL; - *n = 0; - return (npepa); - } + if (n_in > 0) + npepa = ObjectMalloc(OT_PEPARRAY, n_in); + else + { + npepa = NULL; + *n = 0; + return (npepa); + } - *n = 0; - k = 0; + *n = 0; + k = 0; - for (j = 0; j < n_in; j++) - { - pe = pepa[j]; - bb = pe->bv; - ovlap = 1; + for (j = 0; j < n_in; j++) + { + pe = pepa[j]; + bb = pe->bv; + ovlap = 1; - for (i = 0; i < 1; i++) - { - if (b.dnear[0] > bb.dfar[0] + eps) - { - ovlap = 0; - break; - } + for (i = 0; i < 1; i++) + { + if (b.dnear[0] > bb.dfar[0] + eps) + { + ovlap = 0; + break; + } - if (b.dnear[1] > bb.dfar[1] + eps) - { - ovlap = 0; - break; - } + if (b.dnear[1] > bb.dfar[1] + eps) + { + ovlap = 0; + break; + } - if (b.dnear[2] > bb.dfar[2] + eps) - { - ovlap = 0; - break; - } + if (b.dnear[2] > bb.dfar[2] + eps) + { + ovlap = 0; + break; + } - if (b.dfar[0] < bb.dnear[0] - eps) - { - ovlap = 0; - break; - } + if (b.dfar[0] < bb.dnear[0] - eps) + { + ovlap = 0; + break; + } - if (b.dfar[1] < bb.dnear[1] - eps) - { - ovlap = 0; - break; - } + if (b.dfar[1] < bb.dnear[1] - eps) + { + ovlap = 0; + break; + } - if (b.dfar[2] < bb.dnear[2] - eps) - { - ovlap = 0; - break; - } - } + if (b.dfar[2] < bb.dnear[2] - eps) + { + ovlap = 0; + break; + } + } - if (ovlap == 1) - { - npepa[k++] = pepa[j]; - (*n)++; - } - } + if (ovlap == 1) + { + npepa[k++] = pepa[j]; + (*n)++; + } + } - return (npepa); - } + return (npepa); + } @@ -433,37 +434,37 @@ ELEMENT **prims_in_box2(ELEMENT **pepa, INT n_in, BBOX b, INT *n) */ BTNODE *init_bintree(GRID *ng) - { - BTNODE *btn; + { + BTNODE *btn; - btn = ObjectMalloc(OT_BINTREE, 1); + btn = ObjectMalloc(OT_BINTREE, 1); - btn->btn[0] = NULL; - btn->btn[1] = NULL; - btn->axis = -1; + btn->btn[0] = NULL; + btn->btn[1] = NULL; + btn->axis = -1; - btn->p[0] = ng->min[0]; - btn->p[1] = ng->min[1]; - btn->p[2] = ng->min[2]; + btn->p[0] = ng->min[0]; + btn->p[1] = ng->min[1]; + btn->p[2] = ng->min[2]; - btn->n[0] = ng->indx_inc[1]; - btn->n[1] = ng->indx_inc[1]; - btn->n[2] = ng->indx_inc[1]; + btn->n[0] = ng->indx_inc[1]; + btn->n[1] = ng->indx_inc[1]; + btn->n[2] = ng->indx_inc[1]; - btn->i[0] = 0; - btn->i[1] = 0; - btn->i[2] = 0; + btn->i[0] = 0; + btn->i[1] = 0; + btn->i[2] = 0; - btn->nprims = ng->num_prims; - btn->totalPrimsAllocated = btn->nprims; + btn->nprims = ng->num_prims; + btn->totalPrimsAllocated = btn->nprims; - if (ng->num_prims > 0) - btn->pe = ng->pepa; - else - btn->pe = NULL; + if (ng->num_prims > 0) + btn->pe = ng->pepa; + else + btn->pe = NULL; - return (btn); - } + return (btn); + } /* @@ -485,113 +486,113 @@ BTNODE *init_bintree(GRID *ng) */ VOID subdiv_bintree(BTNODE *btn, GRID *g) - { - BTNODE *btn1, *btn2; - INT n1, n2, imax, dmax; - BBOX b1, b2; + { + BTNODE *btn1, *btn2; + INT n1, n2, imax, dmax; + BBOX b1, b2; - /* Find largest dimension. */ + /* Find largest dimension. */ - imax = 0; - dmax = btn->n[0]; + imax = 0; + dmax = btn->n[0]; - if (dmax < btn->n[1]) - { - imax = 1; - dmax = btn->n[1]; - } + if (dmax < btn->n[1]) + { + imax = 1; + dmax = btn->n[1]; + } - if (dmax < btn->n[2]) - { - imax = 2; - dmax = btn->n[2]; - } + if (dmax < btn->n[2]) + { + imax = 2; + dmax = btn->n[2]; + } - /* Subdiv largest dimension. */ + /* Subdiv largest dimension. */ - btn->axis = imax; - btn->btn[0] = NULL; - btn->btn[1] = NULL; + btn->axis = imax; + btn->btn[0] = NULL; + btn->btn[1] = NULL; - if (btn->n[imax] > 1) - { - n1 = btn->n[imax] / 2; - n2 = btn->n[imax] - n1; + if (btn->n[imax] > 1) + { + n1 = btn->n[imax] / 2; + n2 = btn->n[imax] - n1; - btn1 = ObjectMalloc(OT_BINTREE, 1); - btn2 = ObjectMalloc(OT_BINTREE, 1); + btn1 = ObjectMalloc(OT_BINTREE, 1); + btn2 = ObjectMalloc(OT_BINTREE, 1); - btn->btn[0] = btn1; - btn->btn[1] = btn2; + btn->btn[0] = btn1; + btn->btn[1] = btn2; - btn1->btn[0] = NULL; - btn1->btn[1] = NULL; - btn1->axis = -1; + btn1->btn[0] = NULL; + btn1->btn[1] = NULL; + btn1->axis = -1; - btn2->btn[0] = NULL; - btn2->btn[1] = NULL; - btn2->axis = -1; + btn2->btn[0] = NULL; + btn2->btn[1] = NULL; + btn2->axis = -1; - btn1->i[0] = btn->i[0]; - btn1->i[1] = btn->i[1]; - btn1->i[2] = btn->i[2]; + btn1->i[0] = btn->i[0]; + btn1->i[1] = btn->i[1]; + btn1->i[2] = btn->i[2]; - btn2->i[0] = btn->i[0]; - btn2->i[1] = btn->i[1]; - btn2->i[2] = btn->i[2]; - btn2->i[imax] += n1; + btn2->i[0] = btn->i[0]; + btn2->i[1] = btn->i[1]; + btn2->i[2] = btn->i[2]; + btn2->i[imax] += n1; - btn1->n[0] = btn->n[0]; - btn1->n[1] = btn->n[1]; - btn1->n[2] = btn->n[2]; - btn1->n[imax] = n1; + btn1->n[0] = btn->n[0]; + btn1->n[1] = btn->n[1]; + btn1->n[2] = btn->n[2]; + btn1->n[imax] = n1; - btn2->n[0] = btn->n[0]; - btn2->n[1] = btn->n[1]; - btn2->n[2] = btn->n[2]; - btn2->n[imax] = n2; + btn2->n[0] = btn->n[0]; + btn2->n[1] = btn->n[1]; + btn2->n[2] = btn->n[2]; + btn2->n[imax] = n2; - btn1->p[0] = btn->p[0]; - btn1->p[1] = btn->p[1]; - btn1->p[2] = btn->p[2]; + btn1->p[0] = btn->p[0]; + btn1->p[1] = btn->p[1]; + btn1->p[2] = btn->p[2]; - btn2->p[0] = btn->p[0]; - btn2->p[1] = btn->p[1]; - btn2->p[2] = btn->p[2]; - btn2->p[imax] = btn->p[imax] + n1 * g->cellsize[imax]; + btn2->p[0] = btn->p[0]; + btn2->p[1] = btn->p[1]; + btn2->p[2] = btn->p[2]; + btn2->p[imax] = btn->p[imax] + n1 * g->cellsize[imax]; - b1.dnear[0] = btn1->p[0]; - b1.dnear[1] = btn1->p[1]; - b1.dnear[2] = btn1->p[2]; - b1.dfar[0] = btn1->p[0] + btn1->n[0] * g->cellsize[0]; - b1.dfar[1] = btn1->p[1] + btn1->n[1] * g->cellsize[1]; - b1.dfar[2] = btn1->p[2] + btn1->n[2] * g->cellsize[2]; + b1.dnear[0] = btn1->p[0]; + b1.dnear[1] = btn1->p[1]; + b1.dnear[2] = btn1->p[2]; + b1.dfar[0] = btn1->p[0] + btn1->n[0] * g->cellsize[0]; + b1.dfar[1] = btn1->p[1] + btn1->n[1] * g->cellsize[1]; + b1.dfar[2] = btn1->p[2] + btn1->n[2] * g->cellsize[2]; - btn1->pe = prims_in_box2(btn->pe, btn->nprims, b1, &(btn1->nprims)); - btn1->totalPrimsAllocated = btn->nprims; + btn1->pe = prims_in_box2(btn->pe, btn->nprims, b1, &(btn1->nprims)); + btn1->totalPrimsAllocated = btn->nprims; - b2.dnear[0] = btn2->p[0]; - b2.dnear[1] = btn2->p[1]; - b2.dnear[2] = btn2->p[2]; - b2.dfar[0] = btn2->p[0] + btn2->n[0] * g->cellsize[0]; - b2.dfar[1] = btn2->p[1] + btn2->n[1] * g->cellsize[1]; - b2.dfar[2] = btn2->p[2] + btn2->n[2] * g->cellsize[2]; + b2.dnear[0] = btn2->p[0]; + b2.dnear[1] = btn2->p[1]; + b2.dnear[2] = btn2->p[2]; + b2.dfar[0] = btn2->p[0] + btn2->n[0] * g->cellsize[0]; + b2.dfar[1] = btn2->p[1] + btn2->n[1] * g->cellsize[1]; + b2.dfar[2] = btn2->p[2] + btn2->n[2] * g->cellsize[2]; - btn2->pe = prims_in_box2(btn->pe, btn->nprims, b2, &(btn2->nprims)); - btn2->totalPrimsAllocated = btn->nprims; + btn2->pe = prims_in_box2(btn->pe, btn->nprims, b2, &(btn2->nprims)); + btn2->totalPrimsAllocated = btn->nprims; - } + } - if (btn1->n[0] == 1 && btn1->n[1] == 1 && btn1->n[2] == 1) - { - /* further optimize the pe so no space is wasted !! */ - } + if (btn1->n[0] == 1 && btn1->n[1] == 1 && btn1->n[2] == 1) + { + /* further optimize the pe so no space is wasted !! */ + } - if (btn2->n[0] == 1 && btn2->n[1] == 1 && btn2->n[2] == 1) - { - /* further optimize the pe so no space is wasted !! */ - } - } + if (btn2->n[0] == 1 && btn2->n[1] == 1 && btn2->n[2] == 1) + { + /* further optimize the pe so no space is wasted !! */ + } + } @@ -610,25 +611,25 @@ VOID subdiv_bintree(BTNODE *btn, GRID *g) */ VOID create_bintree(BTNODE *root, GRID *g) - { - BTNODE *btn; + { + BTNODE *btn; - /* It is assumed that root's children are NULL on entry. */ + /* It is assumed that root's children are NULL on entry. */ - btn = root; - if (btn->n[0] != 1 || btn->n[1] != 1 || btn->n[2] != 1) - { - subdiv_bintree(btn, g); - create_bintree(btn->btn[0], g); - create_bintree(btn->btn[1], g); + btn = root; + if (btn->n[0] != 1 || btn->n[1] != 1 || btn->n[2] != 1) + { + subdiv_bintree(btn, g); + create_bintree(btn->btn[0], g); + create_bintree(btn->btn[1], g); - if ((btn->nprims) > 0) - { - /* ObjectFree(OT_PEPARRAY, btn->totalPrimsAllocated, btn->pe); - btn->pe = NULL; */ - } - } - } + if ((btn->nprims) > 0) + { + /* ObjectFree(OT_PEPARRAY, btn->totalPrimsAllocated, btn->pe); + btn->pe = NULL; */ + } + } + } @@ -653,83 +654,83 @@ VOID create_bintree(BTNODE *root, GRID *g) */ ELEMENT **bintree_lookup(BTNODE *root, INT i, INT j, INT k, GRID *g, INT *n) - { - INT ijk[3]; - INT child; - INT idiv; - ELEMENT **pepa; - BTNODE *btn; + { + INT ijk[3]; + INT child; + INT idiv; + ELEMENT **pepa; + BTNODE *btn; - ijk[0] = i; - ijk[1] = j; - ijk[2] = k; + ijk[0] = i; + ijk[1] = j; + ijk[2] = k; - btn = root; + btn = root; - if (btn == NULL) - { - *n = 0; - return (NULL); - } + if (btn == NULL) + { + *n = 0; + return (NULL); + } - while (btn->n[0] != 1 || btn->n[1] != 1 || btn->n[2] != 1) - { - if (btn->axis == - 1) - { - /* Not a leaf & not subdivided but should be subdivided. */ + while (btn->n[0] != 1 || btn->n[1] != 1 || btn->n[2] != 1) + { + if (btn->axis == - 1) + { + /* Not a leaf & not subdivided but should be subdivided. */ - fprintf(stderr, "bintree_lookup: gridsizes (%ld, %ld, %ld), axis %ld & nprims %ld\n", - btn->n[0], btn->n[1], btn->n[2], btn->axis, btn->nprims); + fprintf(stderr, "bintree_lookup: gridsizes (%ld, %ld, %ld), axis %ld & nprims %ld\n", + btn->n[0], btn->n[1], btn->n[2], btn->axis, btn->nprims); - exit(-1); - } + exit(-1); + } - /* Descend the tree: find which branch. */ + /* Descend the tree: find which branch. */ - child = 0; - idiv = (btn->n[btn->axis]/2); + child = 0; + idiv = (btn->n[btn->axis]/2); - if (ijk[btn->axis] + 1 > idiv) - { - child = 1; - ijk[btn->axis] -= idiv; - } + if (ijk[btn->axis] + 1 > idiv) + { + child = 1; + ijk[btn->axis] -= idiv; + } - /* Child is now the correct branch. */ + /* Child is now the correct branch. */ - btn = btn->btn[child]; - if (btn == NULL) - { - *n = 0; - return (NULL); - } - } + btn = btn->btn[child]; + if (btn == NULL) + { + *n = 0; + return (NULL); + } + } - /* Now at a leaf. */ + /* Now at a leaf. */ - *n = btn->nprims; - pepa = btn->pe; + *n = btn->nprims; + pepa = btn->pe; /* if (btn->nprims == btn->totalPrimsAllocated) - pepa = btn->pe; - else - { - if (btn->pe) - pepa = GlobalRealloc(btn->pe, btn->nprims*sizeof(ELEMENT *)); - else - pepa = NULL; + pepa = btn->pe; + else + { + if (btn->pe) + pepa = GlobalRealloc(btn->pe, btn->nprims*sizeof(ELEMENT *)); + else + pepa = NULL; - pepa = ObjectMalloc(OT_PEPARRAY, btn->nprims); - for (x = 0; x < btn->nprims; x++) - pepa[x] = btn->pe[x]; + pepa = ObjectMalloc(OT_PEPARRAY, btn->nprims); + for (x = 0; x < btn->nprims; x++) + pepa[x] = btn->pe[x]; - ObjectFree(OT_PEPARRAY, btn->totalPrimsAllocated, btn->pe); - btn->pe = NULL; - } + ObjectFree(OT_PEPARRAY, btn->totalPrimsAllocated, btn->pe); + btn->pe = NULL; + } */ - return (pepa); - } + return (pepa); + } @@ -749,19 +750,19 @@ ELEMENT **bintree_lookup(BTNODE *root, INT i, INT j, INT k, GRID *g, INT *n) */ VOID deleteBinTree(BTNODE *binTree) - { - BTNODE *left, *right; + { + BTNODE *left, *right; - if (binTree != NULL) - { - left = binTree->btn[0]; - right = binTree->btn[1]; + if (binTree != NULL) + { + left = binTree->btn[0]; + right = binTree->btn[1]; - deleteBinTree(left); - deleteBinTree(right); + deleteBinTree(left); + deleteBinTree(right); /* ObjectFree(OT_BINTREE, 1, binTree); */ - } - } + } + } @@ -793,129 +794,129 @@ VOID deleteBinTree(BTNODE *binTree) */ GRID *create_grid(VOXEL *v, GRID *g, INT num_prims) - { - INT n; - INT i, j, k, r; - INT nprims; - INT index1D; - UINT *ec; - R64 ncells; - GRID *ng, *nng; /* New grid. */ - VOXEL *nv; - VOXEL **ht; - BTNODE *bintree; - ELEMENT **pepa; + { + INT n; + INT i, j, k, r; + INT nprims; + INT index1D; + UINT *ec; + R64 ncells; + GRID *ng, *nng; /* New grid. */ + VOXEL *nv; + VOXEL **ht; + BTNODE *bintree; + ELEMENT **pepa; - ng = ObjectMalloc(OT_GRID, 1); - ng->id = grids++; + ng = ObjectMalloc(OT_GRID, 1); + ng->id = grids++; - ht = ObjectMalloc(OT_HASHTABLE, hu_numbuckets); - ng->hashtable = ht; + ht = ObjectMalloc(OT_HASHTABLE, hu_numbuckets); + ng->hashtable = ht; - ncells = (R64)(hu_gridsize * hu_gridsize * hu_gridsize); - total_cells += ncells; + ncells = (R64)(hu_gridsize * hu_gridsize * hu_gridsize); + total_cells += ncells; - ec = ObjectMalloc(OT_EMPTYCELLS, (INT)ncells); - ng->emptycells = ec; + ec = ObjectMalloc(OT_EMPTYCELLS, (INT)ncells); + ng->emptycells = ec; - ng->num_prims = num_prims; - ng->pepa = (ELEMENT**)v->cell; - ng->indx_inc[0] = 1; - ng->indx_inc[1] = hu_gridsize; - ng->indx_inc[2] = hu_gridsize * hu_gridsize; - ng->num_buckets = hu_numbuckets; + ng->num_prims = num_prims; + ng->pepa = (ELEMENT**)v->cell; + ng->indx_inc[0] = 1; + ng->indx_inc[1] = hu_gridsize; + ng->indx_inc[2] = hu_gridsize * hu_gridsize; + ng->num_buckets = hu_numbuckets; - k = v->id/g->indx_inc[2]; - r = v->id - k*g->indx_inc[2]; - j = r/g->indx_inc[1]; - i = r - j*g->indx_inc[1]; + k = v->id/g->indx_inc[2]; + r = v->id - k*g->indx_inc[2]; + j = r/g->indx_inc[1]; + i = r - j*g->indx_inc[1]; - ng->min[0] = g->min[0] + i * g->cellsize[0]; - ng->min[1] = g->min[1] + j * g->cellsize[1]; - ng->min[2] = g->min[2] + k * g->cellsize[2]; + ng->min[0] = g->min[0] + i * g->cellsize[0]; + ng->min[1] = g->min[1] + j * g->cellsize[1]; + ng->min[2] = g->min[2] + k * g->cellsize[2]; - ng->cellsize[0] = g->cellsize[0]/ng->indx_inc[1]; - ng->cellsize[1] = g->cellsize[1]/ng->indx_inc[1]; - ng->cellsize[2] = g->cellsize[2]/ng->indx_inc[1]; - ng->subdiv_level = g->subdiv_level + 1; - ng->next = gridlist; + ng->cellsize[0] = g->cellsize[0]/ng->indx_inc[1]; + ng->cellsize[1] = g->cellsize[1]/ng->indx_inc[1]; + ng->cellsize[2] = g->cellsize[2]/ng->indx_inc[1]; + ng->subdiv_level = g->subdiv_level + 1; + ng->next = gridlist; - gridlist = ng; + gridlist = ng; - /* Calculate hierarchical grid */ + /* Calculate hierarchical grid */ - /* First create bintree. */ + /* First create bintree. */ - bintree = init_bintree(ng); - create_bintree(bintree, ng); + bintree = init_bintree(ng); + create_bintree(bintree, ng); - index1D = 0; - n = hu_gridsize; + index1D = 0; + n = hu_gridsize; - /* - * For each cell in new grid, create an ELEMENT array for the - * cell; if non empty create a voxel for it. If nonempty - * cell has more than MAX_PRIMS_PER_CELL (hu_max_prims_cell) primitives and - * MAX_SUBDIV_LEVEL (hu_max_subdiv_level) has not been reached, create a - * new grid (i.e. subdivide) and insert it in the hashtable. If nonempty - * cell has less than MAX_PRIMS_PER_CELL insert it in the - * hashtable. In any case make the appropriate entry in - * emptycells. - */ + /* + * For each cell in new grid, create an ELEMENT array for the + * cell; if non empty create a voxel for it. If nonempty + * cell has more than MAX_PRIMS_PER_CELL (hu_max_prims_cell) primitives and + * MAX_SUBDIV_LEVEL (hu_max_subdiv_level) has not been reached, create a + * new grid (i.e. subdivide) and insert it in the hashtable. If nonempty + * cell has less than MAX_PRIMS_PER_CELL insert it in the + * hashtable. In any case make the appropriate entry in + * emptycells. + */ - for (k = 0; k < n; k++) - { - for (j = 0; j < n; j++) - { - for (i = 0; i < n; i++) - { - pepa = bintree_lookup(bintree, i, j, k, ng, &nprims); + for (k = 0; k < n; k++) + { + for (j = 0; j < n; j++) + { + for (i = 0; i < n; i++) + { + pepa = bintree_lookup(bintree, i, j, k, ng, &nprims); - if (pepa != NULL) - { - nonempty_voxels++; - mark_nonempty(index1D, ng); + if (pepa != NULL) + { + nonempty_voxels++; + mark_nonempty(index1D, ng); - nv = ObjectMalloc(OT_VOXEL, 1); + nv = ObjectMalloc(OT_VOXEL, 1); - nv->id = index1D; - nv->celltype = GSM_VOXEL; - nv->cell = (CHAR*)pepa; - nv->numelements = nprims; + nv->id = index1D; + nv->celltype = GSM_VOXEL; + nv->cell = (CHAR*)pepa; + nv->numelements = nprims; - if (nprims > hu_max_prims_cell && ng->subdiv_level < hu_max_subdiv_level) - nng = create_grid(nv, ng, nprims); - else - { - /* Leaf cell. */ + if (nprims > hu_max_prims_cell && ng->subdiv_level < hu_max_subdiv_level) + nng = create_grid(nv, ng, nprims); + else + { + /* Leaf cell. */ - nonempty_leafs++; - prims_in_leafs += nprims; - } + nonempty_leafs++; + prims_in_leafs += nprims; + } - insert_in_hashtable(nv, ng); - } - else - { - /* Empty cell. */ + insert_in_hashtable(nv, ng); + } + else + { + /* Empty cell. */ - empty_voxels++; - mark_empty(index1D, ng); - } + empty_voxels++; + mark_empty(index1D, ng); + } - index1D++; - } - } - } + index1D++; + } + } + } - /* Store new grid ptr in input voxel. */ + /* Store new grid ptr in input voxel. */ - v->cell = (CHAR *)ng; - v->numelements = -1; /* this field doesn't make sence if cell is a GRID */ - v->celltype = GSM_GRID; + v->cell = (CHAR *)ng; + v->numelements = -1; /* this field doesn't make sence if cell is a GRID */ + v->celltype = GSM_GRID; - deleteBinTree(bintree); + deleteBinTree(bintree); - return (ng); - } + return (ng); + } diff --git a/splash2/codes/apps/raytrace/env.C b/splash2/codes/apps/raytrace/env.C index f41d6a54d..aa39e66df 100644 --- a/splash2/codes/apps/raytrace/env.C +++ b/splash2/codes/apps/raytrace/env.C @@ -25,12 +25,13 @@ * routines to manipulate lights, colors, and to print the environment. */ -#include -#include -#include - +#include +#include +#include #include "rt.h" + + /* * Define environment specification opcodes. */ @@ -85,11 +86,11 @@ */ typedef struct - { - CHAR *command; /* Command name. */ - CHAR opcode; /* Command code. */ - } - CTE; + { + CHAR *command; /* Command name. */ + CHAR opcode; /* Command code. */ + } + CTE; @@ -98,50 +99,50 @@ typedef struct */ CTE cmdtab[] = - { - {"eye", OP_EYE }, - {"center", OP_COI }, - {"light", OP_LIGHT }, - {"resolution", OP_RES }, - {"shadows", OP_SHAD }, - {"background", OP_BKGCOL }, - {"viewangle", OP_VANG }, - {"antilevel", OP_ANTILEVEL }, - {"minweight", OP_MINWEIGHT }, - {"project", OP_PROJECT }, - {"antitolerance", OP_ANTITOL }, - {"maxlevel", OP_MAXLEVEL }, - {"modelxform", OP_MODELMAT }, - {"shading", OP_SHADING }, - {"displayin", OP_DISPLAY_IN }, - {"displayout", OP_DISPLAY_OUT }, - {"geometry", OP_GEOM_FILE }, - {"texturetype", OP_TEXTURE }, - {"texturefile", OP_TEX_FILE }, - {"image", OP_IMAGE }, - {"footprint", OP_FOOTPRINT }, - {"traversal", OP_TRAVERSAL }, - {"rlfile", OP_RL_FILE }, - {"ambient", OP_AMBIENT }, - {"excellprim", OP_EXCELL_PRIM }, - {"excelldir", OP_EXCELL_DIR }, - {"excellsubdiv", OP_EXCELL_SUBDIV }, - {"hsublevel", OP_HIER_SUBLEVEL }, - {"hprim", OP_HIER_PRIMNUM }, - {"bfcull", OP_PREVIEW_BKCULL }, - {"fill", OP_PREVIEW_FILL }, - {"spheretess", OP_PREVIEW_SPHTESS }, - {"normdata", OP_NORM_DB }, - {"datatype", OP_DATA_TYPE }, - {"hu_maxprims", OP_HU_MAX_PRIMS_CELL }, - {"hu_gridsize", OP_HU_GRIDSIZE }, - {"hu_numbuckets", OP_HU_NUMBUCKETS }, - {"hu_maxsubdiv", OP_HU_MAX_SUBDIV }, - {"hu_lazy", OP_HU_LAZY }, - {"bundle", OP_BUNDLE }, - {"block", OP_BLOCK }, - {" ", OP_ERROR }, - }; + { + {"eye", OP_EYE }, + {"center", OP_COI }, + {"light", OP_LIGHT }, + {"resolution", OP_RES }, + {"shadows", OP_SHAD }, + {"background", OP_BKGCOL }, + {"viewangle", OP_VANG }, + {"antilevel", OP_ANTILEVEL }, + {"minweight", OP_MINWEIGHT }, + {"project", OP_PROJECT }, + {"antitolerance", OP_ANTITOL }, + {"maxlevel", OP_MAXLEVEL }, + {"modelxform", OP_MODELMAT }, + {"shading", OP_SHADING }, + {"displayin", OP_DISPLAY_IN }, + {"displayout", OP_DISPLAY_OUT }, + {"geometry", OP_GEOM_FILE }, + {"texturetype", OP_TEXTURE }, + {"texturefile", OP_TEX_FILE }, + {"image", OP_IMAGE }, + {"footprint", OP_FOOTPRINT }, + {"traversal", OP_TRAVERSAL }, + {"rlfile", OP_RL_FILE }, + {"ambient", OP_AMBIENT }, + {"excellprim", OP_EXCELL_PRIM }, + {"excelldir", OP_EXCELL_DIR }, + {"excellsubdiv", OP_EXCELL_SUBDIV }, + {"hsublevel", OP_HIER_SUBLEVEL }, + {"hprim", OP_HIER_PRIMNUM }, + {"bfcull", OP_PREVIEW_BKCULL }, + {"fill", OP_PREVIEW_FILL }, + {"spheretess", OP_PREVIEW_SPHTESS }, + {"normdata", OP_NORM_DB }, + {"datatype", OP_DATA_TYPE }, + {"hu_maxprims", OP_HU_MAX_PRIMS_CELL }, + {"hu_gridsize", OP_HU_GRIDSIZE }, + {"hu_numbuckets", OP_HU_NUMBUCKETS }, + {"hu_maxsubdiv", OP_HU_MAX_SUBDIV }, + {"hu_lazy", OP_HU_LAZY }, + {"bundle", OP_BUNDLE }, + {"block", OP_BLOCK }, + {" ", OP_ERROR }, + }; @@ -161,76 +162,76 @@ CTE cmdtab[] = */ VOID PrintEnv() - { - INT i; - LIGHT *lp; + { + INT i; + LIGHT *lp; - printf("\nEnvironment:\n"); - printf("\tEye pos: \t %f %f %f\n", View.eye[0], View.eye[1], View.eye[2]); - printf("\tCenter pos:\t %f %f %f\n", View.coi[0], View.coi[1], View.coi[2]); - printf("\tBackground:\t %f %f %f\n", View.bkg[0], View.bkg[1], View.bkg[2]); - printf("\tView Angle:\t %f\n", View.vang); - printf("\nAmbient Light:\t\t %f %f %f\n", View.ambient[0], View.ambient[1], View.ambient[2]); - printf("\nLights:\n"); + printf("\nEnvironment:\n"); + printf("\tEye pos: \t %f %f %f\n", View.eye[0], View.eye[1], View.eye[2]); + printf("\tCenter pos:\t %f %f %f\n", View.coi[0], View.coi[1], View.coi[2]); + printf("\tBackground:\t %f %f %f\n", View.bkg[0], View.bkg[1], View.bkg[2]); + printf("\tView Angle:\t %f\n", View.vang); + printf("\nAmbient Light:\t\t %f %f %f\n", View.ambient[0], View.ambient[1], View.ambient[2]); + printf("\nLights:\n"); - lp = lights; - for (i = 0; i < nlights; i++) - { - printf("\t[%ld] Pos:\t %f %f %f\n", i, lp->pos[0], lp->pos[1], lp->pos[2]); - printf("\t Col:\t %f %f %f\n", lp->col[0], lp->col[1], lp->col[2]); - printf("\t Shadow:\t %ld\n", lp->shadow); + lp = lights; + for (i = 0; i < nlights; i++) + { + printf("\t[%ld] Pos:\t %f %f %f\n", i, lp->pos[0], lp->pos[1], lp->pos[2]); + printf("\t Col:\t %f %f %f\n", lp->col[0], lp->col[1], lp->col[2]); + printf("\t Shadow:\t %ld\n", lp->shadow); - lp = lp->next; - } + lp = lp->next; + } - printf("\n"); - printf("Options:\n"); - printf("\tTraversal:\t\t\t"); + printf("\n"); + printf("Options:\n"); + printf("\tTraversal:\t\t\t"); - switch (TraversalType) - { - case TT_LIST: - printf("list\n"); - break; + switch (TraversalType) + { + case TT_LIST: + printf("list\n"); + break; - case TT_HUG: - printf("uniform grid hierarchy\n"); - printf("\t\t\t\t\t grid size %ld\n", hu_gridsize); - printf("\t\t\t\t\t max prims %ld\n", hu_max_prims_cell); - printf("\t\t\t\t\t max sublevel %ld\n", hu_max_subdiv_level); - printf("\t\t\t\t\t buckets %ld\n", hu_numbuckets); - printf("\t\t\t\t\t lazy %ld\n", hu_lazy); - break; - } + case TT_HUG: + printf("uniform grid hierarchy\n"); + printf("\t\t\t\t\t grid size %ld\n", hu_gridsize); + printf("\t\t\t\t\t max prims %ld\n", hu_max_prims_cell); + printf("\t\t\t\t\t max sublevel %ld\n", hu_max_subdiv_level); + printf("\t\t\t\t\t buckets %ld\n", hu_numbuckets); + printf("\t\t\t\t\t lazy %ld\n", hu_lazy); + break; + } - printf("\tNormalization DB:\t\t"); - printf(ModelNorm ? "yes\n" : "no\n"); + printf("\tNormalization DB:\t\t"); + printf(ModelNorm ? "yes\n" : "no\n"); - printf("\tProjection type:\t\t"); - printf(View.projection == PT_PERSP ? "perspective\n" : "orthographic\n"); + printf("\tProjection type:\t\t"); + printf(View.projection == PT_PERSP ? "perspective\n" : "orthographic\n"); - printf("\tShadows:\t\t\t"); - printf(View.shad ? "on\n" : "off\n"); + printf("\tShadows:\t\t\t"); + printf(View.shad ? "on\n" : "off\n"); - printf("\tShading:\t\t\t"); - printf(View.shading ? "on\n" : "off\n"); + printf("\tShading:\t\t\t"); + printf(View.shading ? "on\n" : "off\n"); - printf("\tResolution:\t\t\t%ld %ld\n", Display.xres, Display.yres); - printf("\tMin Ray Weight:\t\t\t%f\n", Display.minweight); - printf("\tMax Anti Subdivison Level:\t%ld\n", Display.maxAAsubdiv); - printf("\tAnti tolerance:\t\t\t%f\n", Display.aatolerance); + printf("\tResolution:\t\t\t%ld %ld\n", Display.xres, Display.yres); + printf("\tMin Ray Weight:\t\t\t%f\n", Display.minweight); + printf("\tMax Anti Subdivison Level:\t%ld\n", Display.maxAAsubdiv); + printf("\tAnti tolerance:\t\t\t%f\n", Display.aatolerance); - printf("\tBundle: \t\t\t%ld %ld\n", bundlex, bundley); - printf("\tBlock: \t\t\t%ld %ld\n", blockx, blocky); + printf("\tBundle: \t\t\t%ld %ld\n", bundlex, bundley); + printf("\tBlock: \t\t\t%ld %ld\n", blockx, blocky); - if (GeoFile) - printf("\tGeometry file:\t\t\t%s\n", GeoFileName); + if (GeoFile) + printf("\tGeometry file:\t\t\t%s\n", GeoFileName); - if (PicFile) - printf("\tImage file:\t\t\t%s\n", PicFileName); + if (PicFile) + printf("\tImage file:\t\t\t%s\n", PicFileName); - printf("\n"); - } + printf("\n"); + } @@ -246,107 +247,107 @@ VOID PrintEnv() */ VOID InitEnv() - { - /* Default eye position. */ - View.eye[0] = 0.5; - View.eye[1] = 0.5; - View.eye[2] = -1.5; + { + /* Default eye position. */ + View.eye[0] = 0.5; + View.eye[1] = 0.5; + View.eye[2] = -1.5; - /* Default center position. */ - View.coi[0] = 0.5; - View.coi[1] = 0.5; - View.coi[2] = 0.5; + /* Default center position. */ + View.coi[0] = 0.5; + View.coi[1] = 0.5; + View.coi[2] = 0.5; - /* Default background color. */ - View.bkg[0] = 0.0; - View.bkg[1] = 0.0; - View.bkg[2] = 0.8; + /* Default background color. */ + View.bkg[0] = 0.0; + View.bkg[1] = 0.0; + View.bkg[2] = 0.8; - /* Default viewing angle. */ - View.vang = 60.0; + /* Default viewing angle. */ + View.vang = 60.0; - /* Default ambient light. */ - View.ambient[0] = 0.1; - View.ambient[1] = 0.1; - View.ambient[2] = 0.1; + /* Default ambient light. */ + View.ambient[0] = 0.1; + View.ambient[1] = 0.1; + View.ambient[2] = 0.1; - /* Shadows and shading. */ - View.shad = TRUE; - View.shading = TRUE; + /* Shadows and shading. */ + View.shad = TRUE; + View.shading = TRUE; - /* Perspective projection. */ - View.projection = PT_PERSP; + /* Perspective projection. */ + View.projection = PT_PERSP; - /* Default resolution is 100 x 100 */ - Display.xres = 100; - Display.yres = 100; - Display.numpixels = 100*100; + /* Default resolution is 100 x 100 */ + Display.xres = 100; + Display.yres = 100; + Display.numpixels = 100*100; - /* Default maximum raytrace level. */ - Display.maxlevel = 5; + /* Default maximum raytrace level. */ + Display.maxlevel = 5; - /* Default anti-aliasing. */ - Display.maxAAsubdiv = 0; - Display.aatolerance = .020; - Display.aarow = MAX_AA_ROW - 1; - Display.aacol = MAX_AA_COL - 1; + /* Default anti-aliasing. */ + Display.maxAAsubdiv = 0; + Display.aatolerance = .020; + Display.aarow = MAX_AA_ROW - 1; + Display.aacol = MAX_AA_COL - 1; - /* Default ray minimum weight is 0.001. */ - Display.minweight = 0.001; + /* Default ray minimum weight is 0.001. */ + Display.minweight = 0.001; - /* Default screen size. */ - Display.scrDist = 164.5; - Display.scrWidth = 190.0; - Display.scrHeight = 190.0; + /* Default screen size. */ + Display.scrDist = 164.5; + Display.scrWidth = 190.0; + Display.scrHeight = 190.0; - Display.scrHalfWidth = Display.scrWidth * 0.5; - Display.scrHalfHeight = Display.scrHeight* 0.5; + Display.scrHalfWidth = Display.scrWidth * 0.5; + Display.scrHalfHeight = Display.scrHeight* 0.5; - Display.vWscale = Display.scrWidth/(REAL)Display.xres; - Display.vHscale = Display.scrHeight/(REAL)Display.yres; + Display.vWscale = Display.scrWidth/(REAL)Display.xres; + Display.vHscale = Display.scrHeight/(REAL)Display.yres; - /* Init transformation matrices. */ - MatrixIdentity(View.vtrans); - MatrixIdentity(View.model); + /* Init transformation matrices. */ + MatrixIdentity(View.vtrans); + MatrixIdentity(View.model); - GeoFile = FALSE; - PicFile = FALSE; - ModelNorm = TRUE; - ModelTransform = FALSE; - DataType = DT_ASCII; - TraversalType = TT_LIST; + GeoFile = FALSE; + PicFile = FALSE; + ModelNorm = TRUE; + ModelTransform = FALSE; + DataType = DT_ASCII; + TraversalType = TT_LIST; - /* Init statistics. - * - * Stats.total_rays = 0; - * Stats.prim_rays = 0; - * Stats.shad_rays = 0; - * Stats.shad_rays_not_hit = 0; - * Stats.shad_rays_hit = 0; - * Stats.shad_coherence_rays = 0; - * Stats.refl_rays = 0; - * Stats.trans_rays = 0; - * Stats.aa_rays = 0; - * Stats.bound_tests = 0; - * Stats.bound_hits = 0; - * Stats.bound_misses = 0; - * Stats.ray_obj_hit = 0; - * Stats.ray_obj_miss = 0; - * Stats.max_tree_depth = 0; - * Stats.max_objs_ray = 0; - * Stats.max_rays_pixel = 0; - * Stats.max_objs_pixel = 0; - * Stats.total_objs_tested = 0; - * Stats.coverage = 0; - */ + /* Init statistics. + * + * Stats.total_rays = 0; + * Stats.prim_rays = 0; + * Stats.shad_rays = 0; + * Stats.shad_rays_not_hit = 0; + * Stats.shad_rays_hit = 0; + * Stats.shad_coherence_rays = 0; + * Stats.refl_rays = 0; + * Stats.trans_rays = 0; + * Stats.aa_rays = 0; + * Stats.bound_tests = 0; + * Stats.bound_hits = 0; + * Stats.bound_misses = 0; + * Stats.ray_obj_hit = 0; + * Stats.ray_obj_miss = 0; + * Stats.max_tree_depth = 0; + * Stats.max_objs_ray = 0; + * Stats.max_rays_pixel = 0; + * Stats.max_objs_pixel = 0; + * Stats.total_objs_tested = 0; + * Stats.coverage = 0; + */ - lights = GlobalMalloc(sizeof(LIGHT), "env.c"); + lights = GlobalMalloc(sizeof(LIGHT), "env.c"); - bundlex = 25; - bundley = 25; - blockx = 2; - blocky = 2; - } + bundlex = 25; + bundley = 25; + blockx = 2; + blocky = 2; + } @@ -363,19 +364,19 @@ VOID InitEnv() */ VOID InitLights() - { - nlights = 1; + { + nlights = 1; - lights->pos[0] = 0.0; - lights->pos[1] = 0.0; - lights->pos[2] = -2000.0; - lights->pos[3] = 1.0; - lights->col[0] = 1.0; - lights->col[1] = 1.0; - lights->col[2] = 1.0; - lights->shadow = TRUE; - lights->next = NULL; - } + lights->pos[0] = 0.0; + lights->pos[1] = 0.0; + lights->pos[2] = -2000.0; + lights->pos[3] = 1.0; + lights->col[0] = 1.0; + lights->col[1] = 1.0; + lights->col[2] = 1.0; + lights->shadow = TRUE; + lights->next = NULL; + } @@ -391,20 +392,20 @@ VOID InitLights() */ VOID InitDisplay() - { - REAL aspect; /* Resolution aspect ratio. */ - REAL theta; /* View angle in radians. */ + { + REAL aspect; /* Resolution aspect ratio. */ + REAL theta; /* View angle in radians. */ - aspect = (REAL)Display.xres/(REAL)Display.yres; - theta = (View.vang*0.5)*0.0175; + aspect = (REAL)Display.xres/(REAL)Display.yres; + theta = (View.vang*0.5)*0.0175; - Display.scrWidth = Display.scrHeight*aspect; - Display.scrDist = (0.5*Display.scrHeight)/tan(theta); - Display.scrHalfWidth = Display.scrWidth*0.5; - Display.scrHalfHeight = Display.scrHeight*0.5; - Display.vWscale = Display.scrWidth/(REAL)Display.xres; - Display.vHscale = Display.scrHeight/(REAL)Display.yres; - } + Display.scrWidth = Display.scrHeight*aspect; + Display.scrDist = (0.5*Display.scrHeight)/tan(theta); + Display.scrHalfWidth = Display.scrWidth*0.5; + Display.scrHalfHeight = Display.scrHeight*0.5; + Display.vWscale = Display.scrWidth/(REAL)Display.xres; + Display.vHscale = Display.scrHeight/(REAL)Display.yres; + } @@ -421,17 +422,17 @@ VOID InitDisplay() */ BOOL VerifyColorRange(COLOR c) - { - if (c[0] < 0.0 || c[0] > 1.0 || - c[1] < 0.0 || c[1] > 1.0 || - c[2] < 0.0 || c[2] > 1.0) - { - printf("Invalid color %f %f %f.\n", c[0], c[1], c[2]); - return (FALSE); - } - else - return (TRUE); - } + { + if (c[0] < 0.0 || c[0] > 1.0 || + c[1] < 0.0 || c[1] > 1.0 || + c[2] < 0.0 || c[2] > 1.0) + { + printf("Invalid color %f %f %f.\n", c[0], c[1], c[2]); + return (FALSE); + } + else + return (TRUE); + } @@ -448,17 +449,17 @@ BOOL VerifyColorRange(COLOR c) */ VOID TransformLights(MATRIX m) - { - INT i; - LIGHT *lp; + { + INT i; + LIGHT *lp; - lp = lights; - for (i = 0; i < nlights; i++) - { - VecMatMult(lp->pos, m, lp->pos); - lp = lp->next; - } - } + lp = lights; + for (i = 0; i < nlights; i++) + { + VecMatMult(lp->pos, m, lp->pos); + lp = lp->next; + } + } @@ -476,40 +477,40 @@ VOID TransformLights(MATRIX m) */ VOID ViewRotate(MATRIX M, REAL x, REAL y, REAL z) - { - REAL r, rx; + { + REAL r, rx; - rx = sqrt(x*x + z*z); + rx = sqrt(x*x + z*z); - if (ABS(rx) < RAYEPS) - { - MatrixIdentity(M); - Rotate(X_AXIS, M, PI_over_2 * (Sign(y))); - return; - } + if (ABS(rx) < RAYEPS) + { + MatrixIdentity(M); + Rotate(X_AXIS, M, PI_over_2 * (Sign(y))); + return; + } - r = sqrt(x*x + y*y + z*z); + r = sqrt(x*x + y*y + z*z); - M[0][0] = z/rx; - M[0][1] = -x*y/(r*rx); - M[0][2] = x/r; - M[0][3] = 0.0; + M[0][0] = z/rx; + M[0][1] = -x*y/(r*rx); + M[0][2] = x/r; + M[0][3] = 0.0; - M[1][0] = 0.0; - M[1][1] = rx/r; - M[1][2] = y/r; - M[1][3] = 0.0; + M[1][0] = 0.0; + M[1][1] = rx/r; + M[1][2] = y/r; + M[1][3] = 0.0; - M[2][0] = -x/rx; - M[2][1] = -y*z/(r*rx); - M[2][2] = z/r; - M[2][3] = 0.0; + M[2][0] = -x/rx; + M[2][1] = -y*z/(r*rx); + M[2][2] = z/r; + M[2][3] = 0.0; - M[3][0] = 0.0; - M[3][1] = 0.0; - M[3][2] = 0.0; - M[3][3] = 1.0; - } + M[3][0] = 0.0; + M[3][1] = 0.0; + M[3][2] = 0.0; + M[3][3] = 1.0; + } @@ -528,19 +529,19 @@ VOID ViewRotate(MATRIX M, REAL x, REAL y, REAL z) */ VOID CreateViewMatrix() - { - MATRIX T, R; /* Temporary matrices. */ + { + MATRIX T, R; /* Temporary matrices. */ - /* Put eye at origin. */ + /* Put eye at origin. */ - Translate(T, -View.eye[0], -View.eye[1], -View.eye[2]); - MatrixMult(View.vtrans, View.vtrans, T); + Translate(T, -View.eye[0], -View.eye[1], -View.eye[2]); + MatrixMult(View.vtrans, View.vtrans, T); - /* Align view direction with Z axis. */ + /* Align view direction with Z axis. */ - ViewRotate(R, View.coi[0] - View.eye[0], View.coi[1] - View.eye[1], View.coi[2] - View.eye[2]); - MatrixMult(View.vtrans, View.vtrans, R); - } + ViewRotate(R, View.coi[0] - View.eye[0], View.coi[1] - View.eye[1], View.coi[2] - View.eye[2]); + MatrixMult(View.vtrans, View.vtrans, R); + } @@ -557,9 +558,9 @@ VOID CreateViewMatrix() */ VOID TransformViewRay(POINT tray) - { - VecMatMult(tray, View.vtransInv, tray); - } + { + VecMatMult(tray, View.vtransInv, tray); + } @@ -576,15 +577,15 @@ VOID TransformViewRay(POINT tray) */ VOID NormalizeEnv(MATRIX normMat) - { - View.eye[3] = 1.0; - VecMatMult(View.eye, normMat, View.eye); + { + View.eye[3] = 1.0; + VecMatMult(View.eye, normMat, View.eye); - View.coi[3] = 1.0; - VecMatMult(View.coi, normMat, View.coi); + View.coi[3] = 1.0; + VecMatMult(View.coi, normMat, View.coi); - TransformLights(normMat); - } + TransformLights(normMat); + } @@ -601,16 +602,16 @@ VOID NormalizeEnv(MATRIX normMat) */ CHAR LookupCommand(CHAR *s) - { - INT i; + { + INT i; - for (i = 0; i < NUM_COMMANDS; i++) - if (strcmp(s, cmdtab[i].command) == 0) - return (cmdtab[i].opcode); + for (i = 0; i < NUM_COMMANDS; i++) + if (strcmp(s, cmdtab[i].command) == 0) + return (cmdtab[i].opcode); - printf("\n\nInvalid command string %s.\n", s); - return (OP_ERROR); - } + printf("\n\nInvalid command string %s.\n", s); + return (OP_ERROR); + } @@ -627,476 +628,476 @@ CHAR LookupCommand(CHAR *s) */ VOID ReadEnvFile(CHAR *EnvFileName) - { - INT i, j; /* Indices. */ - INT stat; /* Input var status counter. */ - INT dummy; - CHAR opcode; /* Environment spec opcode. */ - CHAR command[30]; /* Environment spec command. */ - CHAR opparam[30]; /* Command parameter. */ - CHAR dummy_char[60]; - CHAR datafile[10]; - BOOL lights_set; /* Lights set? */ - FILE *pf; /* Input file pointer. */ - LIGHT *lptr, *lastlight; /* Light node pointers. */ - - - /* Open command file. */ - - pf = fopen(EnvFileName, "r"); - if (!pf) - { - printf("Unable to open environment file %s.\n", EnvFileName); - exit(-1); - } - - InitEnv(); /* Set defaults. */ - - nlights = 0; - lights_set = FALSE; - - - /* Process command file according to opcodes. */ - - while (fscanf(pf, "%s", command) != EOF) - { - opcode = LookupCommand(command); - - switch (opcode) - { - /* Eye position. */ - case OP_EYE: - stat = fscanf(pf, "%lf %lf %lf", &(View.eye[0]), &(View.eye[1]), &(View.eye[2])); - if (stat != 3) - { - printf("error: eye position.\n"); - exit(-1); - } - break; - - /* Center of interest position. */ - case OP_COI: - stat = fscanf(pf, "%lf %lf %lf", &(View.coi[0]), &(View.coi[1]), &(View.coi[2])); - if (stat != 3) - { - printf("error: coi position.\n"); - exit(-1); - } - break; - - /* Background color. */ - case OP_BKGCOL: - stat = fscanf(pf, "%lf %lf %lf", &(View.bkg[0]), &(View.bkg[1]), &(View.bkg[2])); - if (stat != 3) - { - printf("error: background color.\n"); - exit(-1); - } - - if (!VerifyColorRange(View.bkg)) - exit(-1); - break; - - /* Viewing angle in degrees. */ - case OP_VANG: - stat = fscanf(pf, "%lf", &(View.vang)); - if (stat != 1) - { - printf("error: viewing angle.\n"); - exit(-1); - } - - if (View.vang < 0.0 || View.vang > 100.0) - { - printf("Invalid angle %f.\n", View.vang); - exit(-1); - } - break; - - /* Ambient. */ - case OP_AMBIENT: - stat = fscanf(pf, "%lf %lf %lf", &(View.ambient[0]), &(View.ambient[1]), &(View.ambient[2])); - if (stat != 3) - { - printf("error: ambient.\n"); - exit(-1); - } - - if (!VerifyColorRange(View.ambient)) - exit(-1); - break; - - /* Anti-aliasing level. */ - case OP_ANTILEVEL: - stat = fscanf(pf, "%ld", &(Display.maxAAsubdiv)); - if (stat != 1) - { - printf("View error: antialias level.\n"); - exit(-1); - } - - if (Display.maxAAsubdiv < 0 || Display.maxAAsubdiv > 3) - { - printf("error: antialias level %ld.\n", Display.maxAAsubdiv); - exit(-1); - } - break; - - /* Recursion level. */ - case OP_MAXLEVEL: - stat = fscanf(pf, "%ld", &(Display.maxlevel)); - printf("maxlevel of ray recursion = %ld\n",Display.maxlevel); - fflush(stdout); - if (stat != 1) - { - printf("error: recursion level.\n"); - exit(-1); - } - - if (Display.maxlevel > 5 || Display.maxlevel < 0) - { - printf("error: recursion level %ld.\n", Display.maxlevel); - exit(-1); - } - break; - - /* Mininum ray weight. */ - case OP_MINWEIGHT: - stat = fscanf(pf, "%lf", &(Display.minweight)); - if (stat != 1) - { - printf("error: miniumum ray weight.\n"); - exit(-1); - } - - if (Display.minweight < 0.0 || Display.minweight > 1.0) - { - printf("error: invalid ray weight %f.\n", Display.minweight); - exit(-1); - } - break; - - /* Anti tolerance weight. */ - case OP_ANTITOL: - stat = fscanf(pf, "%lf", &(Display.aatolerance)); - if (stat != 1) - { - printf("error: anti tolerance weight.\n"); - exit(-1); - } - - if (Display.aatolerance < 0.0 || Display.aatolerance > 1.0) - { - printf("error: invalid anti tolerance weight %f.\n", Display.aatolerance); - exit(-1); - } - break; - - /* Resolution. */ - case OP_RES: - stat = fscanf(pf, "%ld %ld", &(Display.xres), &(Display.yres)); - if (stat != 2) - { - printf("error: resolution.\n"); - exit(-1); - } - break; - - /* Light positions and colors. */ - case OP_LIGHT: - lights_set = TRUE; - if (nlights > 0) - lptr = GlobalMalloc(sizeof(LIGHT), "env.c"); - else - lptr = lights; - - stat = fscanf(pf, "%lf %lf %lf %lf %lf %lf", - &(lptr->pos[0]), - &(lptr->pos[1]), - &(lptr->pos[2]), - &(lptr->col[0]), - &(lptr->col[1]), - &(lptr->col[2])); - - if (stat != 6) - { - printf("error: Lights.\n"); - exit(-1); - } - - if (!VerifyColorRange(lptr->col)) - exit(-1); - - lptr->pos[3] = 1.0; - stat = fscanf(pf, "%ld", &(lptr->shadow)); - if (stat != 1) - { - printf("error: Lights shadow indicator.\n"); - exit(-1); - } - - lptr->next = NULL; - if (nlights > 0) - lastlight->next = lptr; - - nlights++; - lastlight = lptr; - break; - - /* Model transformation matrix. */ - case OP_MODELMAT: - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - { - stat = fscanf(pf, "%lf", &(View.model[i][j])); - if (stat != 1) - { - printf("Error in matrix.\n"); - exit(-1); - } - } - - ModelTransform = TRUE; - break; - - /* Shadow info. */ - case OP_SHAD: - stat = fscanf(pf, "%s", opparam); - if (stat != 1) - { - printf("error: shadow.\n"); - exit(-1); - } - - if (strcmp(opparam, "on") == 0) - View.shad = TRUE; - else - View.shad = FALSE; - break; - - /* Shading info. */ - case OP_SHADING: - stat = fscanf(pf, "%s", opparam); - if (stat != 1) - { - printf("error: shading %s.\n", opparam); - exit(-1); - } - - if (strcmp(opparam, "on") == 0) - View.shading = TRUE; - else - View.shading = FALSE; - break; - - /* Projection type. */ - case OP_PROJECT: - stat = fscanf(pf, "%s", opparam); - if (stat != 1) - { - printf("error: projection %s.\n", opparam); - exit(-1); - } - - if (strcmp(opparam, "perspective") == 0) - View.projection = PT_PERSP; - else - if (strcmp(opparam, "orthographic") == 0) - View.projection = PT_ORTHO; - else - { - printf("Invalid projection %s.\n", opparam); - exit(-1); - } - break; - - /* Database traversal info. */ - case OP_TRAVERSAL: - stat = fscanf(pf, "%s", opparam); - if (stat != 1) - { - printf("error: traversal %s.\n", opparam); - exit(-1); - } - - if (strcmp(opparam, "list") == 0) - TraversalType = TT_LIST; - else - if (strcmp(opparam, "huniform") == 0) - TraversalType = TT_HUG; - else - { - printf("Invalid traversal code %s.\n", opparam); - exit(-1); - } - break; - - /* Geometry file. */ - case OP_GEOM_FILE: - stat = fscanf(pf, " %s", GeoFileName); - if (stat != 1) - { - printf("error: geometry file.\n"); - exit(-1); - } - - GeoFile = TRUE; - break; - - /* Runlength file. */ - case OP_RL_FILE: - stat = fscanf(pf, " %s", PicFileName); - if (stat != 1) - { - printf("error: runlength file.\n"); - exit(-1); - } - - PicFile = TRUE; - break; - - case OP_PREVIEW_BKCULL: - stat = fscanf(pf, "%ld", &dummy); - if (stat != 1) - { - printf("error: Preview bkcull.\n"); - exit(-1); - } - break; - - case OP_PREVIEW_FILL: - stat = fscanf(pf, "%ld", &dummy); - if (stat != 1) - { - printf("error: Preview fill.\n"); - exit(-1); - } - break; - - case OP_PREVIEW_SPHTESS: - stat = fscanf(pf, "%s", dummy_char); - if (stat != 1) - { - printf("error: sphere tess.\n"); - exit(-1); - } - break; - - case OP_NORM_DB: - stat = fscanf(pf, "%s", opparam); - if (stat != 1) - { - printf("error: norm database.\n"); - exit(-1); - } - - if (strcmp(opparam, "no") == 0) - ModelNorm = FALSE; - - break; - - case OP_DATA_TYPE: - stat = fscanf(pf, "%s", datafile); - if (stat != 1) - { - printf("error: datatype.\n"); - exit(-1); - } - - if (strcmp(datafile, "binary") == 0) - DataType = DT_BINARY; - - break; - - case OP_HU_MAX_PRIMS_CELL: - stat = fscanf(pf, "%ld", &hu_max_prims_cell); - if (stat != 1) - { - printf("error: Huniform prims per cell.\n"); - exit(-1); - } - break; - - case OP_HU_GRIDSIZE: - stat = fscanf(pf, "%ld", &hu_gridsize); - if (stat != 1) - { - printf("error: Huniform gridsize.\n"); - exit(-1); - } - break; - - case OP_HU_NUMBUCKETS: - stat = fscanf(pf, "%ld", &hu_numbuckets); - if (stat != 1) - { - printf("error: Huniform numbuckets.\n"); - exit(-1); - } - break; - - case OP_HU_MAX_SUBDIV: - stat = fscanf(pf, "%ld", &hu_max_subdiv_level); - if (stat != 1 || hu_max_subdiv_level > 3) - { - printf("error: Huniform max subdiv level.\n"); - exit(-1); - } - break; - - case OP_HU_LAZY: - stat = fscanf(pf, "%ld", &hu_lazy); - if (stat != 1) - { - printf("error: Huniform lazy.\n"); - exit(-1); - } - break; - - case OP_BUNDLE: - stat = fscanf(pf, "%ld %ld", &bundlex, &bundley); - if (stat != 2 ) - { - printf("error: bundle.\n"); - exit(-1); - } - break; - - case OP_BLOCK: - stat = fscanf(pf, "%ld %ld", &blockx, &blocky); - if (stat != 2 ) - { - printf("error: block.\n"); - exit(-1); - } - break; - - default: - printf("Warning: unrecognized env command: %s.\n", command); - break; - } - } - - fclose(pf); - - /* Display parameters reset. */ - Display.numpixels = Display.xres*Display.yres; - Display.vWscale = Display.scrWidth/Display.xres; - Display.vHscale = Display.scrHeight/Display.yres; - - - /* If no light information given, set default. */ - if (!lights_set) - InitLights(); - - /* Set up screen parameters. */ - InitDisplay(); - - /* Parameter check; think about lifting this restriction. */ - if ((TraversalType != TT_LIST) && ModelNorm == FALSE) - { - printf("Data must be normalized with this traversal method!.\n"); - ModelNorm = TRUE; - } - } + { + INT i, j; /* Indices. */ + INT stat; /* Input var status counter. */ + INT dummy; + CHAR opcode; /* Environment spec opcode. */ + CHAR command[30]; /* Environment spec command. */ + CHAR opparam[30]; /* Command parameter. */ + CHAR dummy_char[60]; + CHAR datafile[10]; + BOOL lights_set; /* Lights set? */ + FILE *pf; /* Input file pointer. */ + LIGHT *lptr, *lastlight; /* Light node pointers. */ + + + /* Open command file. */ + + pf = fopen(EnvFileName, "r"); + if (!pf) + { + printf("Unable to open environment file %s.\n", EnvFileName); + exit(-1); + } + + InitEnv(); /* Set defaults. */ + + nlights = 0; + lights_set = FALSE; + + + /* Process command file according to opcodes. */ + + while (fscanf(pf, "%s", command) != EOF) + { + opcode = LookupCommand(command); + + switch (opcode) + { + /* Eye position. */ + case OP_EYE: + stat = fscanf(pf, "%lf %lf %lf", &(View.eye[0]), &(View.eye[1]), &(View.eye[2])); + if (stat != 3) + { + printf("error: eye position.\n"); + exit(-1); + } + break; + + /* Center of interest position. */ + case OP_COI: + stat = fscanf(pf, "%lf %lf %lf", &(View.coi[0]), &(View.coi[1]), &(View.coi[2])); + if (stat != 3) + { + printf("error: coi position.\n"); + exit(-1); + } + break; + + /* Background color. */ + case OP_BKGCOL: + stat = fscanf(pf, "%lf %lf %lf", &(View.bkg[0]), &(View.bkg[1]), &(View.bkg[2])); + if (stat != 3) + { + printf("error: background color.\n"); + exit(-1); + } + + if (!VerifyColorRange(View.bkg)) + exit(-1); + break; + + /* Viewing angle in degrees. */ + case OP_VANG: + stat = fscanf(pf, "%lf", &(View.vang)); + if (stat != 1) + { + printf("error: viewing angle.\n"); + exit(-1); + } + + if (View.vang < 0.0 || View.vang > 100.0) + { + printf("Invalid angle %f.\n", View.vang); + exit(-1); + } + break; + + /* Ambient. */ + case OP_AMBIENT: + stat = fscanf(pf, "%lf %lf %lf", &(View.ambient[0]), &(View.ambient[1]), &(View.ambient[2])); + if (stat != 3) + { + printf("error: ambient.\n"); + exit(-1); + } + + if (!VerifyColorRange(View.ambient)) + exit(-1); + break; + + /* Anti-aliasing level. */ + case OP_ANTILEVEL: + stat = fscanf(pf, "%ld", &(Display.maxAAsubdiv)); + if (stat != 1) + { + printf("View error: antialias level.\n"); + exit(-1); + } + + if (Display.maxAAsubdiv < 0 || Display.maxAAsubdiv > 3) + { + printf("error: antialias level %ld.\n", Display.maxAAsubdiv); + exit(-1); + } + break; + + /* Recursion level. */ + case OP_MAXLEVEL: + stat = fscanf(pf, "%ld", &(Display.maxlevel)); + printf("maxlevel of ray recursion = %ld\n",Display.maxlevel); + fflush(stdout); + if (stat != 1) + { + printf("error: recursion level.\n"); + exit(-1); + } + + if (Display.maxlevel > 5 || Display.maxlevel < 0) + { + printf("error: recursion level %ld.\n", Display.maxlevel); + exit(-1); + } + break; + + /* Mininum ray weight. */ + case OP_MINWEIGHT: + stat = fscanf(pf, "%lf", &(Display.minweight)); + if (stat != 1) + { + printf("error: miniumum ray weight.\n"); + exit(-1); + } + + if (Display.minweight < 0.0 || Display.minweight > 1.0) + { + printf("error: invalid ray weight %f.\n", Display.minweight); + exit(-1); + } + break; + + /* Anti tolerance weight. */ + case OP_ANTITOL: + stat = fscanf(pf, "%lf", &(Display.aatolerance)); + if (stat != 1) + { + printf("error: anti tolerance weight.\n"); + exit(-1); + } + + if (Display.aatolerance < 0.0 || Display.aatolerance > 1.0) + { + printf("error: invalid anti tolerance weight %f.\n", Display.aatolerance); + exit(-1); + } + break; + + /* Resolution. */ + case OP_RES: + stat = fscanf(pf, "%ld %ld", &(Display.xres), &(Display.yres)); + if (stat != 2) + { + printf("error: resolution.\n"); + exit(-1); + } + break; + + /* Light positions and colors. */ + case OP_LIGHT: + lights_set = TRUE; + if (nlights > 0) + lptr = GlobalMalloc(sizeof(LIGHT), "env.c"); + else + lptr = lights; + + stat = fscanf(pf, "%lf %lf %lf %lf %lf %lf", + &(lptr->pos[0]), + &(lptr->pos[1]), + &(lptr->pos[2]), + &(lptr->col[0]), + &(lptr->col[1]), + &(lptr->col[2])); + + if (stat != 6) + { + printf("error: Lights.\n"); + exit(-1); + } + + if (!VerifyColorRange(lptr->col)) + exit(-1); + + lptr->pos[3] = 1.0; + stat = fscanf(pf, "%ld", &(lptr->shadow)); + if (stat != 1) + { + printf("error: Lights shadow indicator.\n"); + exit(-1); + } + + lptr->next = NULL; + if (nlights > 0) + lastlight->next = lptr; + + nlights++; + lastlight = lptr; + break; + + /* Model transformation matrix. */ + case OP_MODELMAT: + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + { + stat = fscanf(pf, "%lf", &(View.model[i][j])); + if (stat != 1) + { + printf("Error in matrix.\n"); + exit(-1); + } + } + + ModelTransform = TRUE; + break; + + /* Shadow info. */ + case OP_SHAD: + stat = fscanf(pf, "%s", opparam); + if (stat != 1) + { + printf("error: shadow.\n"); + exit(-1); + } + + if (strcmp(opparam, "on") == 0) + View.shad = TRUE; + else + View.shad = FALSE; + break; + + /* Shading info. */ + case OP_SHADING: + stat = fscanf(pf, "%s", opparam); + if (stat != 1) + { + printf("error: shading %s.\n", opparam); + exit(-1); + } + + if (strcmp(opparam, "on") == 0) + View.shading = TRUE; + else + View.shading = FALSE; + break; + + /* Projection type. */ + case OP_PROJECT: + stat = fscanf(pf, "%s", opparam); + if (stat != 1) + { + printf("error: projection %s.\n", opparam); + exit(-1); + } + + if (strcmp(opparam, "perspective") == 0) + View.projection = PT_PERSP; + else + if (strcmp(opparam, "orthographic") == 0) + View.projection = PT_ORTHO; + else + { + printf("Invalid projection %s.\n", opparam); + exit(-1); + } + break; + + /* Database traversal info. */ + case OP_TRAVERSAL: + stat = fscanf(pf, "%s", opparam); + if (stat != 1) + { + printf("error: traversal %s.\n", opparam); + exit(-1); + } + + if (strcmp(opparam, "list") == 0) + TraversalType = TT_LIST; + else + if (strcmp(opparam, "huniform") == 0) + TraversalType = TT_HUG; + else + { + printf("Invalid traversal code %s.\n", opparam); + exit(-1); + } + break; + + /* Geometry file. */ + case OP_GEOM_FILE: + stat = fscanf(pf, " %s", GeoFileName); + if (stat != 1) + { + printf("error: geometry file.\n"); + exit(-1); + } + + GeoFile = TRUE; + break; + + /* Runlength file. */ + case OP_RL_FILE: + stat = fscanf(pf, " %s", PicFileName); + if (stat != 1) + { + printf("error: runlength file.\n"); + exit(-1); + } + + PicFile = TRUE; + break; + + case OP_PREVIEW_BKCULL: + stat = fscanf(pf, "%ld", &dummy); + if (stat != 1) + { + printf("error: Preview bkcull.\n"); + exit(-1); + } + break; + + case OP_PREVIEW_FILL: + stat = fscanf(pf, "%ld", &dummy); + if (stat != 1) + { + printf("error: Preview fill.\n"); + exit(-1); + } + break; + + case OP_PREVIEW_SPHTESS: + stat = fscanf(pf, "%s", dummy_char); + if (stat != 1) + { + printf("error: sphere tess.\n"); + exit(-1); + } + break; + + case OP_NORM_DB: + stat = fscanf(pf, "%s", opparam); + if (stat != 1) + { + printf("error: norm database.\n"); + exit(-1); + } + + if (strcmp(opparam, "no") == 0) + ModelNorm = FALSE; + + break; + + case OP_DATA_TYPE: + stat = fscanf(pf, "%s", datafile); + if (stat != 1) + { + printf("error: datatype.\n"); + exit(-1); + } + + if (strcmp(datafile, "binary") == 0) + DataType = DT_BINARY; + + break; + + case OP_HU_MAX_PRIMS_CELL: + stat = fscanf(pf, "%ld", &hu_max_prims_cell); + if (stat != 1) + { + printf("error: Huniform prims per cell.\n"); + exit(-1); + } + break; + + case OP_HU_GRIDSIZE: + stat = fscanf(pf, "%ld", &hu_gridsize); + if (stat != 1) + { + printf("error: Huniform gridsize.\n"); + exit(-1); + } + break; + + case OP_HU_NUMBUCKETS: + stat = fscanf(pf, "%ld", &hu_numbuckets); + if (stat != 1) + { + printf("error: Huniform numbuckets.\n"); + exit(-1); + } + break; + + case OP_HU_MAX_SUBDIV: + stat = fscanf(pf, "%ld", &hu_max_subdiv_level); + if (stat != 1 || hu_max_subdiv_level > 3) + { + printf("error: Huniform max subdiv level.\n"); + exit(-1); + } + break; + + case OP_HU_LAZY: + stat = fscanf(pf, "%ld", &hu_lazy); + if (stat != 1) + { + printf("error: Huniform lazy.\n"); + exit(-1); + } + break; + + case OP_BUNDLE: + stat = fscanf(pf, "%ld %ld", &bundlex, &bundley); + if (stat != 2 ) + { + printf("error: bundle.\n"); + exit(-1); + } + break; + + case OP_BLOCK: + stat = fscanf(pf, "%ld %ld", &blockx, &blocky); + if (stat != 2 ) + { + printf("error: block.\n"); + exit(-1); + } + break; + + default: + printf("Warning: unrecognized env command: %s.\n", command); + break; + } + } + + fclose(pf); + + /* Display parameters reset. */ + Display.numpixels = Display.xres*Display.yres; + Display.vWscale = Display.scrWidth/Display.xres; + Display.vHscale = Display.scrHeight/Display.yres; + + + /* If no light information given, set default. */ + if (!lights_set) + InitLights(); + + /* Set up screen parameters. */ + InitDisplay(); + + /* Parameter check; think about lifting this restriction. */ + if ((TraversalType != TT_LIST) && ModelNorm == FALSE) + { + printf("Data must be normalized with this traversal method!.\n"); + ModelNorm = TRUE; + } + } diff --git a/splash2/codes/apps/raytrace/fbuf.C b/splash2/codes/apps/raytrace/fbuf.C index 330b3e4b7..63f922c43 100644 --- a/splash2/codes/apps/raytrace/fbuf.C +++ b/splash2/codes/apps/raytrace/fbuf.C @@ -31,23 +31,24 @@ */ -#include -#include - +#include +#include #include "rt.h" + + static struct /* Runlength pixel definition. */ - { - U8 r, g, b; /* Color. */ - U8 count; /* Pixel count for color. */ - } - image[MAX_X]; + { + U8 r, g, b; /* Color. */ + U8 count; /* Pixel count for color. */ + } + image[MAX_X]; /* - image does not have have to be made an array for tango-lite - since it is only used in RunLengthEncode, which is only - called by CloseFrameBuffer, which is only called after - all children have terminated + image does not have have to be made an array for tango-lite + since it is only used in RunLengthEncode, which is only + called by CloseFrameBuffer, which is only called after + all children have terminated */ @@ -67,48 +68,48 @@ static struct /* Runlength pixel definition. */ */ VOID RunLengthEncode(FILE *pf, PIXEL *fb, INT xsize) - { - INT x; /* Original buffer entry address. */ - INT rl; /* Runlength buffer entry address. */ - INT numpixels; /* Running count of identical pixels.*/ - U8 red, green, blue; /* Color holders. */ + { + INT x; /* Original buffer entry address. */ + INT rl; /* Runlength buffer entry address. */ + INT numpixels; /* Running count of identical pixels.*/ + U8 red, green, blue; /* Color holders. */ - rl = 0; - numpixels = 0; + rl = 0; + numpixels = 0; - image[0].r = (U8)( (INT) (fb[0].r * 255.0)); - image[0].g = (U8)( (INT) (fb[0].g * 255.0)); - image[0].b = (U8)( (INT) (fb[0].b * 255.0)); + image[0].r = (U8)( (INT) (fb[0].r * 255.0)); + image[0].g = (U8)( (INT) (fb[0].g * 255.0)); + image[0].b = (U8)( (INT) (fb[0].b * 255.0)); - for (x = 1; x < xsize; x++) - { - red = (U8)( (INT) (fb[x].r * 255.0)); - green = (U8)( (INT) (fb[x].g * 255.0)); - blue = (U8)( (INT) (fb[x].b * 255.0)); + for (x = 1; x < xsize; x++) + { + red = (U8)( (INT) (fb[x].r * 255.0)); + green = (U8)( (INT) (fb[x].g * 255.0)); + blue = (U8)( (INT) (fb[x].b * 255.0)); - if (red == image[rl].r && - green == image[rl].g && - blue == image[rl].b && - numpixels < 255) - numpixels++; - else - { - image[rl].count = (U8)numpixels; - rl++; + if (red == image[rl].r && + green == image[rl].g && + blue == image[rl].b && + numpixels < 255) + numpixels++; + else + { + image[rl].count = (U8)numpixels; + rl++; - image[rl].r = red; - image[rl].g = green; - image[rl].b = blue; - numpixels = 0; - } - } + image[rl].r = red; + image[rl].g = green; + image[rl].b = blue; + numpixels = 0; + } + } - image[rl].count = (U8)numpixels; + image[rl].count = (U8)numpixels; - for (x = 0; x <= rl; x++) - fprintf(pf, "%c%c%c%c", image[x].r, image[x].g, image[x].b, image[x].count); - } + for (x = 0; x <= rl; x++) + fprintf(pf, "%c%c%c%c", image[x].r, image[x].g, image[x].b, image[x].count); + } @@ -124,20 +125,20 @@ VOID RunLengthEncode(FILE *pf, PIXEL *fb, INT xsize) */ VOID OpenFrameBuffer() - { - INT i; - PIXEL *fb; + { + INT i; + PIXEL *fb; - fb = Display.framebuffer = GlobalMalloc(Display.numpixels*sizeof(PIXEL), "fbuf.c"); + fb = Display.framebuffer = GlobalMalloc(Display.numpixels*sizeof(PIXEL), "fbuf.c"); - for (i = 0; i < Display.numpixels; i++) - { - fb->r = 0.0; - fb->g = 0.0; - fb->b = 0.0; - fb++; - } - } + for (i = 0; i < Display.numpixels; i++) + { + fb->r = 0.0; + fb->g = 0.0; + fb->b = 0.0; + fb++; + } + } @@ -156,17 +157,17 @@ VOID OpenFrameBuffer() */ VOID AddPixelColor(COLOR c, INT x, INT y) - { - INT addr; /* Index into framebuffer. */ - PIXEL *fb; /* Ptr to framebuffer. */ + { + INT addr; /* Index into framebuffer. */ + PIXEL *fb; /* Ptr to framebuffer. */ - addr = Display.xres * y + x; - fb = Display.framebuffer; + addr = Display.xres * y + x; + fb = Display.framebuffer; - fb[addr].r += c[0]; - fb[addr].g += c[1]; - fb[addr].b += c[2]; - } + fb[addr].r += c[0]; + fb[addr].g += c[1]; + fb[addr].b += c[2]; + } @@ -183,50 +184,50 @@ VOID AddPixelColor(COLOR c, INT x, INT y) */ VOID CloseFrameBuffer(CHAR *PicFileName) - { - INT x; - INT y; - PIXEL *fb; /* Ptr to framebuffer. */ - FILE *pf; /* Ptr to picture file. */ + { + INT x; + INT y; + PIXEL *fb; /* Ptr to framebuffer. */ + FILE *pf; /* Ptr to picture file. */ - pf = fopen(PicFileName, "wb"); - if (!pf) - { - printf("Unable to open picture file %s.\n", PicFileName); - exit(-1); - } + pf = fopen(PicFileName, "wb"); + if (!pf) + { + printf("Unable to open picture file %s.\n", PicFileName); + exit(-1); + } - /* Write file header. */ + /* Write file header. */ - x = Display.xres; - y = Display.yres; - fb = Display.framebuffer; + x = Display.xres; + y = Display.yres; + fb = Display.framebuffer; - fprintf(pf, "%c%c%c%c%c%c%c%c", - (char)(0), (char)(0), (char)(x/256), (char) (x%256), - (char)(0), (char)(0), (char)(y/256), (char) (y%256)); + fprintf(pf, "%c%c%c%c%c%c%c%c", + (char)(0), (char)(0), (char)(x/256), (char) (x%256), + (char)(0), (char)(0), (char)(y/256), (char) (y%256)); - /* Clamp, run-length encode, and write out pixels on a scanline basis. */ + /* Clamp, run-length encode, and write out pixels on a scanline basis. */ - for (y = 0; y < Display.yres; y++) - { - for (x = 0; x < Display.xres; x++) - { - fb[x].r = Min(fb[x].r, 1.0); - fb[x].g = Min(fb[x].g, 1.0); - fb[x].b = Min(fb[x].b, 1.0); - fb[x].r = Max(fb[x].r, 0.0); - fb[x].g = Max(fb[x].g, 0.0); - fb[x].b = Max(fb[x].b, 0.0); - } + for (y = 0; y < Display.yres; y++) + { + for (x = 0; x < Display.xres; x++) + { + fb[x].r = Min(fb[x].r, 1.0); + fb[x].g = Min(fb[x].g, 1.0); + fb[x].b = Min(fb[x].b, 1.0); + fb[x].r = Max(fb[x].r, 0.0); + fb[x].g = Max(fb[x].g, 0.0); + fb[x].b = Max(fb[x].b, 0.0); + } - RunLengthEncode(pf, fb, Display.xres); - fb += Display.xres; - } + RunLengthEncode(pf, fb, Display.xres); + fb += Display.xres; + } - fclose(pf); - GlobalFree(Display.framebuffer); - } + fclose(pf); + GlobalFree(Display.framebuffer); + } diff --git a/splash2/codes/apps/raytrace/geo.C b/splash2/codes/apps/raytrace/geo.C index 2c473d8de..851b58534 100644 --- a/splash2/codes/apps/raytrace/geo.C +++ b/splash2/codes/apps/raytrace/geo.C @@ -27,49 +27,49 @@ */ +#include #include - -#include -#include -#include - +#include +#include #include "rt.h" + + /* * Allocate and initialize sphere function pointer array. */ static PPROCS SphProcs = - { - SphName, - SphPrint, - SphRead, - NULL, - SphTransform, - SphIntersect, - SphPeIntersect, - SphNormal, - SphDataNormalize, - SphBoundBox - }; + { + SphName, + SphPrint, + SphRead, + NULL, + SphTransform, + SphIntersect, + SphPeIntersect, + SphNormal, + SphDataNormalize, + SphBoundBox + }; /* * Allocate and initialize polygon function pointer array. */ static PPROCS PolyProcs = - { - PolyName, - PolyPrint, - PolyRead, - NULL, - PolyTransform, - PolyIntersect, - PolyPeIntersect, - PolyNormal, - PolyDataNormalize, - PolyBoundBox - }; + { + PolyName, + PolyPrint, + PolyRead, + NULL, + PolyTransform, + PolyIntersect, + PolyPeIntersect, + PolyNormal, + PolyDataNormalize, + PolyBoundBox + }; @@ -78,18 +78,18 @@ static PPROCS PolyProcs = */ static PPROCS TriProcs = - { - TriName, - TriPrint, - TriRead, - NULL, - TriTransform, - TriIntersect, - TriPeIntersect, - TriNormal, - TriDataNormalize, - TriBoundBox - }; + { + TriName, + TriPrint, + TriRead, + NULL, + TriTransform, + TriIntersect, + TriPeIntersect, + TriNormal, + TriDataNormalize, + TriBoundBox + }; @@ -107,34 +107,34 @@ static PPROCS TriProcs = */ ELEMENT **MakeElementArray(INT *totalElements) - { - INT i; - OBJECT *po; /* Ptr to object. */ - INT currArrayPosition = 0; - ELEMENT **npepa; + { + INT i; + OBJECT *po; /* Ptr to object. */ + INT currArrayPosition = 0; + ELEMENT **npepa; - po = gm->modelroot; - *totalElements = 0; + po = gm->modelroot; + *totalElements = 0; - while (po) - { - (*totalElements) += po->numelements; - po = po->next; - } + while (po) + { + (*totalElements) += po->numelements; + po = po->next; + } - po = gm->modelroot; - npepa = ObjectMalloc(OT_PEPARRAY, *totalElements); + po = gm->modelroot; + npepa = ObjectMalloc(OT_PEPARRAY, *totalElements); - while (po) - { - for (i = 0; i < po->numelements; i++) - npepa[currArrayPosition++] = po->pelem + i; + while (po) + { + for (i = 0; i < po->numelements; i++) + npepa[currArrayPosition++] = po->pelem + i; - po = po->next; - } + po = po->next; + } - return (npepa); - } + return (npepa); + } @@ -151,23 +151,23 @@ ELEMENT **MakeElementArray(INT *totalElements) */ VOID PrintGeo(OBJECT *po) - { - while (po) - { - fprintf(stdout, "Object %s\n", po->name); - fprintf(stdout, "\tcolor %f %f %f %f %f %f\n", - po->surf->fcolor[0], po->surf->fcolor[1], - po->surf->fcolor[2], po->surf->bcolor[0], - po->surf->bcolor[1], po->surf->bcolor[2]); + { + while (po) + { + fprintf(stdout, "Object %s\n", po->name); + fprintf(stdout, "\tcolor %f %f %f %f %f %f\n", + po->surf->fcolor[0], po->surf->fcolor[1], + po->surf->fcolor[2], po->surf->bcolor[0], + po->surf->bcolor[1], po->surf->bcolor[2]); - fprintf(stdout, "\tcoeffs %f %f %f %f %f\n", - po->surf->kdiff, po->surf->kspec, po->surf->ktran, - po->surf->refrindex, po->surf->kspecn); + fprintf(stdout, "\tcoeffs %f %f %f %f %f\n", + po->surf->kdiff, po->surf->kspec, po->surf->ktran, + po->surf->refrindex, po->surf->kspecn); - (*po->procs->print)(po); - po = po->next; - } - } + (*po->procs->print)(po); + po = po->next; + } + } @@ -186,70 +186,70 @@ VOID PrintGeo(OBJECT *po) */ VOID NormalizeGeo(OBJECT *po, MATRIX model, MATRIX modelInvT) - { - REAL norm_minx; /* Normalize min values. */ - REAL norm_miny; - REAL norm_minz; - REAL norm_maxx; /* Normalize max values. */ - REAL norm_maxy; - REAL norm_maxz; - REAL scale_min; /* Object min max values. */ - REAL scale_max; - REAL scale; /* Normalization scale val. */ - REAL trans; /* Normalization xlat val. */ - OBJECT *poHead; /* Ptr to head of object list*/ - MATRIX normMat; /* Normalization matrix. */ - MATRIX tempMat; /* Temporary work matrix. */ + { + REAL norm_minx; /* Normalize min values. */ + REAL norm_miny; + REAL norm_minz; + REAL norm_maxx; /* Normalize max values. */ + REAL norm_maxy; + REAL norm_maxz; + REAL scale_min; /* Object min max values. */ + REAL scale_max; + REAL scale; /* Normalization scale val. */ + REAL trans; /* Normalization xlat val. */ + OBJECT *poHead; /* Ptr to head of object list*/ + MATRIX normMat; /* Normalization matrix. */ + MATRIX tempMat; /* Temporary work matrix. */ - poHead = po; /* Save ptr to head of list. */ + poHead = po; /* Save ptr to head of list. */ - if (! (TraversalType == TT_LIST && ModelNorm == FALSE) ) - { - /* Find global bound box min/max. */ + if (! (TraversalType == TT_LIST && ModelNorm == FALSE) ) + { + /* Find global bound box min/max. */ - norm_minx = norm_miny = norm_minz = HUGE_REAL; - norm_maxx = norm_maxy = norm_maxz = -HUGE_REAL; + norm_minx = norm_miny = norm_minz = HUGE_REAL; + norm_maxx = norm_maxy = norm_maxz = -HUGE_REAL; - while (po) - { - norm_minx = Min(norm_minx, po->bv.dnear[0]); - norm_miny = Min(norm_miny, po->bv.dnear[1]); - norm_minz = Min(norm_minz, po->bv.dnear[2]); - norm_maxx = Max(norm_maxx, po->bv.dfar[0]); - norm_maxy = Max(norm_maxy, po->bv.dfar[1]); - norm_maxz = Max(norm_maxz, po->bv.dfar[2]); + while (po) + { + norm_minx = Min(norm_minx, po->bv.dnear[0]); + norm_miny = Min(norm_miny, po->bv.dnear[1]); + norm_minz = Min(norm_minz, po->bv.dnear[2]); + norm_maxx = Max(norm_maxx, po->bv.dfar[0]); + norm_maxy = Max(norm_maxy, po->bv.dfar[1]); + norm_maxz = Max(norm_maxz, po->bv.dfar[2]); - po = po->next; - } + po = po->next; + } - /* Compute scale factor. */ + /* Compute scale factor. */ - scale_min = Min(norm_minx, norm_miny); - scale_min = Min(scale_min, norm_minz); - scale_max = Max(norm_maxx, norm_maxy); - scale_max = Max(scale_max, norm_maxz); + scale_min = Min(norm_minx, norm_miny); + scale_min = Min(scale_min, norm_minz); + scale_max = Max(norm_maxx, norm_maxy); + scale_max = Max(scale_max, norm_maxz); - scale = 1.0/(scale_max - scale_min); - trans = (-scale_min*scale); + scale = 1.0/(scale_max - scale_min); + trans = (-scale_min*scale); - Scale(tempMat, scale, scale, scale); - Translate(normMat, trans, trans, trans); - MatrixMult(normMat, tempMat, normMat); + Scale(tempMat, scale, scale, scale); + Translate(normMat, trans, trans, trans); + MatrixMult(normMat, tempMat, normMat); - /* Now, normalize object data. */ + /* Now, normalize object data. */ - po = poHead; + po = poHead; - while (po) - { - (*po->procs->normalize)(po, normMat); - po = po->next; - } - } - } + while (po) + { + (*po->procs->normalize)(po, normMat); + po = po->next; + } + } + } @@ -275,187 +275,187 @@ VOID NormalizeGeo(OBJECT *po, MATRIX model, MATRIX modelInvT) */ VOID ReadGeoFile(CHAR *GeoFileName) - { - INT i; - INT dummy; - INT stat; /* Input read counter. */ - CHAR comchar; - CHAR primop; /* Primitive opcode. */ - CHAR objstr[NAME_LEN]; /* Object descriptions. */ - CHAR objname[NAME_LEN]; - FILE *pf; /* Ptr to geo file desc. */ - SURF *ps; /* Ptr to surface desc. */ - MATRIX model; /* Model matrix. */ - MATRIX modelInv; /* Model matrix inverse. */ - MATRIX modelInvT; /* Model matrix inv transpose*/ - OBJECT *prev; /* Ptr to previous object. */ - OBJECT *curr; /* Ptr to current object. */ - ELEMENT *pe; /* Ptr to the element list. */ + { + INT i; + INT dummy; + INT stat; /* Input read counter. */ + CHAR comchar; + CHAR primop; /* Primitive opcode. */ + CHAR objstr[NAME_LEN]; /* Object descriptions. */ + CHAR objname[NAME_LEN]; + FILE *pf; /* Ptr to geo file desc. */ + SURF *ps; /* Ptr to surface desc. */ + MATRIX model; /* Model matrix. */ + MATRIX modelInv; /* Model matrix inverse. */ + MATRIX modelInvT; /* Model matrix inv transpose*/ + OBJECT *prev; /* Ptr to previous object. */ + OBJECT *curr; /* Ptr to current object. */ + ELEMENT *pe; /* Ptr to the element list. */ - /* Open the model file. */ + /* Open the model file. */ - pf = fopen(GeoFileName, "r"); - if (!pf) - { - printf("Unable to open model file %s.\n", GeoFileName); - exit(1); - } + pf = fopen(GeoFileName, "r"); + if (!pf) + { + printf("Unable to open model file %s.\n", GeoFileName); + exit(1); + } - /* Initialize pointers and counters. */ + /* Initialize pointers and counters. */ - curr = NULL; - prev = NULL; - gm->modelroot = NULL; - prim_obj_cnt = 0; - prim_elem_cnt = 0; + curr = NULL; + prev = NULL; + gm->modelroot = NULL; + prim_obj_cnt = 0; + prim_elem_cnt = 0; - /* Retrieve model transform. */ + /* Retrieve model transform. */ - MatrixCopy(model, View.model); - MatrixInverse(modelInv, model); - MatrixTranspose(modelInvT, modelInv); + MatrixCopy(model, View.model); + MatrixInverse(modelInv, model); + MatrixTranspose(modelInvT, modelInv); - /* Check for comments. */ + /* Check for comments. */ - if ((comchar = getc(pf)) != '#') - ungetc(comchar, pf); - else - { - comchar = '\0'; /* Set to other than '#'. */ + if ((comchar = getc(pf)) != '#') + ungetc(comchar, pf); + else + { + comchar = '\0'; /* Set to other than '#'. */ - while (comchar != '#') - if ((comchar = getc(pf)) == EOF) - { - fprintf(stderr, "Incorrect comment in geometry file.\n"); - exit(-1); - } - } + while (comchar != '#') + if ((comchar = getc(pf)) == EOF) + { + fprintf(stderr, "Incorrect comment in geometry file.\n"); + exit(-1); + } + } - /* Process the file data for each object. */ + /* Process the file data for each object. */ - while ((stat = fscanf(pf, "%s %s", objstr, objname)) != EOF) - { - if (stat != 2 || strcmp(objstr, "object") != 0) - { - printf("Invalid object definition %s.\n", objstr); - exit(-1); - } + while ((stat = fscanf(pf, "%s %s", objstr, objname)) != EOF) + { + if (stat != 2 || strcmp(objstr, "object") != 0) + { + printf("Invalid object definition %s.\n", objstr); + exit(-1); + } - /* Allocate next object and set list pointers. */ + /* Allocate next object and set list pointers. */ - prim_obj_cnt++; + prim_obj_cnt++; - curr = GlobalMalloc(sizeof(OBJECT), "geo.c"); - curr->index = prim_obj_cnt; - curr->next = NULL; + curr = GlobalMalloc(sizeof(OBJECT), "geo.c"); + curr->index = prim_obj_cnt; + curr->next = NULL; - strcpy(curr->name, objname); + strcpy(curr->name, objname); - if (gm->modelroot == NULL) - gm->modelroot = curr; - else - prev->next = curr; + if (gm->modelroot == NULL) + gm->modelroot = curr; + else + prev->next = curr; - /* Get surface characteristics. */ + /* Get surface characteristics. */ - ps = GlobalMalloc(sizeof(SURF), "geo.c"); - curr->surf = ps; + ps = GlobalMalloc(sizeof(SURF), "geo.c"); + curr->surf = ps; - stat = fscanf(pf, "%lf %lf %lf %lf %lf %lf", - &(ps->fcolor[0]), &(ps->fcolor[1]), &(ps->fcolor[2]), - &(ps->bcolor[0]), &(ps->bcolor[1]), &(ps->bcolor[2])); + stat = fscanf(pf, "%lf %lf %lf %lf %lf %lf", + &(ps->fcolor[0]), &(ps->fcolor[1]), &(ps->fcolor[2]), + &(ps->bcolor[0]), &(ps->bcolor[1]), &(ps->bcolor[2])); - if (stat != 6) - { - printf("Object color incorrect.\n"); - exit(-1); - } + if (stat != 6) + { + printf("Object color incorrect.\n"); + exit(-1); + } - stat = fscanf(pf, "%lf %lf %lf %lf %lf", - &(ps->kdiff), &(ps->kspec), &(ps->ktran), - &(ps->refrindex), &(ps->kspecn)); + stat = fscanf(pf, "%lf %lf %lf %lf %lf", + &(ps->kdiff), &(ps->kspec), &(ps->ktran), + &(ps->refrindex), &(ps->kspecn)); - if (stat != 5) - { - printf("Object surface coefficients incorrect.\n"); - exit(-1); - } + if (stat != 5) + { + printf("Object surface coefficients incorrect.\n"); + exit(-1); + } - /* Get texture and flag information. */ + /* Get texture and flag information. */ - stat = fscanf(pf, "%ld %ld %ld %ld\n", &dummy, &dummy, &dummy, &dummy); + stat = fscanf(pf, "%ld %ld %ld %ld\n", &dummy, &dummy, &dummy, &dummy); - if (stat != 4) - { - printf("Texture and/or flag information not all present.\n"); - exit(-1); - } + if (stat != 4) + { + printf("Texture and/or flag information not all present.\n"); + exit(-1); + } - /* Get primitive opcode. */ + /* Get primitive opcode. */ - stat = fscanf(pf, "%c %ld", &primop, &(curr->numelements)); + stat = fscanf(pf, "%c %ld", &primop, &(curr->numelements)); - if (stat != 2) - { - printf("Object primitive opcode.\n"); - exit(-1); - } + if (stat != 2) + { + printf("Object primitive opcode.\n"); + exit(-1); + } - switch (primop) - { - case 's': - curr->procs = &SphProcs; - break; + switch (primop) + { + case 's': + curr->procs = &SphProcs; + break; - case 'p': - curr->procs = &PolyProcs; - break; + case 'p': + curr->procs = &PolyProcs; + break; - case 't': - curr->procs = &TriProcs; - break; + case 't': + curr->procs = &TriProcs; + break; - case 'c': - case 'q': - printf("Code for cylinders and quadrics not implemented yet.\n"); - exit(-1); + case 'c': + case 'q': + printf("Code for cylinders and quadrics not implemented yet.\n"); + exit(-1); - default: - printf("Invalid primitive type \'%c\'.\n", primop); - exit(-1); - } + default: + printf("Invalid primitive type \'%c\'.\n", primop); + exit(-1); + } - /* Allocate primitive elements and create indices. */ + /* Allocate primitive elements and create indices. */ - pe = GlobalMalloc(sizeof(ELEMENT)*curr->numelements, "geo.c"); - curr->pelem = pe; + pe = GlobalMalloc(sizeof(ELEMENT)*curr->numelements, "geo.c"); + curr->pelem = pe; - prim_elem_cnt += curr->numelements; + prim_elem_cnt += curr->numelements; - for (i = 1; i <= curr->numelements; i++, pe++) - pe->index = i; + for (i = 1; i <= curr->numelements; i++, pe++) + pe->index = i; - /* Read, transform, and compute bounding box for object. */ + /* Read, transform, and compute bounding box for object. */ - (*curr->procs->read)(curr, pf); - (*curr->procs->transform)(curr, model, modelInvT); - (*curr->procs->bbox)(curr); + (*curr->procs->read)(curr, pf); + (*curr->procs->transform)(curr, model, modelInvT); + (*curr->procs->bbox)(curr); - prev = curr; - } + prev = curr; + } - NormalizeGeo(gm->modelroot, model, modelInvT); - fclose(pf); - } + NormalizeGeo(gm->modelroot, model, modelInvT); + fclose(pf); + } diff --git a/splash2/codes/apps/raytrace/huprn.C b/splash2/codes/apps/raytrace/huprn.C index 21bd83902..e06b6f7aa 100644 --- a/splash2/codes/apps/raytrace/huprn.C +++ b/splash2/codes/apps/raytrace/huprn.C @@ -25,196 +25,195 @@ */ -#include -#include - +#include +#include #include "rt.h" VOID prn_voxel(VOXEL *v) - { - ELEMENT *pe, **pepa; - GRID *g; - INT i; + { + ELEMENT *pe, **pepa; + GRID *g; + INT i; - fprintf(stderr, " Print Voxel id = %ld \n", v->id); - fprintf(stderr, " celltype %d \n", v->celltype); + fprintf(stderr, " Print Voxel id = %ld \n", v->id); + fprintf(stderr, " celltype %d \n", v->celltype); - if (v->celltype == GSM_VOXEL) - { - fprintf(stderr, " gsm_voxel \n"); - fprintf(stderr, " primElement index list:\n"); + if (v->celltype == GSM_VOXEL) + { + fprintf(stderr, " gsm_voxel \n"); + fprintf(stderr, " primElement index list:\n"); - pepa = (ELEMENT**)v->cell; + pepa = (ELEMENT**)v->cell; - for (i=0; i < v->numelements; i++) - { - pe = pepa[i]; - fprintf(stderr, " %ld \n", pe->index); - } - } + for (i=0; i < v->numelements; i++) + { + pe = pepa[i]; + fprintf(stderr, " %ld \n", pe->index); + } + } - if (v->celltype == GSM_GRID) - { - g = (GRID *)v->cell; - prn_grid(g); - fprintf(stderr, " gsm_grid id %ld \n", g->id); - } + if (v->celltype == GSM_GRID) + { + g = (GRID *)v->cell; + prn_grid(g); + fprintf(stderr, " gsm_grid id %ld \n", g->id); + } - fprintf(stderr, " End Voxel \n"); - } + fprintf(stderr, " End Voxel \n"); + } VOID prn_grid(GRID *g) - { - INT i; - INT n; - GRID *ng; - VOXEL *v; + { + INT i; + INT n; + GRID *ng; + VOXEL *v; - fprintf(stderr, " Print Grid %ld \n", g->id); - fprintf(stderr, " num_prims = %ld \n", g->num_prims); - fprintf(stderr, " indx_inc[0,1,2] = %ld, %ld, %ld \n", g->indx_inc[0], g->indx_inc[1], g->indx_inc[2]); - fprintf(stderr, " num_buckets = %ld \n", g->num_buckets); - fprintf(stderr, " min[0,1,2] = %lf, %lf, %lf \n", g->min[0], g->min[1], g->min[2] ); - fprintf(stderr, " cellsize[0,1,2] = %lf, %lf, %lf \n", g->cellsize[0], g->cellsize[1], g->cellsize[2]); - fprintf(stderr, " subdiv_level = %ld \n", g->subdiv_level); + fprintf(stderr, " Print Grid %ld \n", g->id); + fprintf(stderr, " num_prims = %ld \n", g->num_prims); + fprintf(stderr, " indx_inc[0,1,2] = %ld, %ld, %ld \n", g->indx_inc[0], g->indx_inc[1], g->indx_inc[2]); + fprintf(stderr, " num_buckets = %ld \n", g->num_buckets); + fprintf(stderr, " min[0,1,2] = %lf, %lf, %lf \n", g->min[0], g->min[1], g->min[2] ); + fprintf(stderr, " cellsize[0,1,2] = %lf, %lf, %lf \n", g->cellsize[0], g->cellsize[1], g->cellsize[2]); + fprintf(stderr, " subdiv_level = %ld \n", g->subdiv_level); - if (g->next != NULL) - { - ng = g->next; - fprintf(stderr, " next grid id %ld \n", ng->id); - } - else - fprintf(stderr, " next grid id NULL \n"); + if (g->next != NULL) + { + ng = g->next; + fprintf(stderr, " next grid id %ld \n", ng->id); + } + else + fprintf(stderr, " next grid id NULL \n"); - fprintf(stderr, " Voxel List \n"); + fprintf(stderr, " Voxel List \n"); - n = g->indx_inc[1] * g->indx_inc[2]; + n = g->indx_inc[1] * g->indx_inc[2]; - for (i = 0; i < n; i++) - { - if (lookup_emptycells(i, g) == EMPTY) - fprintf(stderr, " Voxel %ld is empty. \n", i); - else - { - v = lookup_hashtable(i, g); - prn_voxel(v); - } - } + for (i = 0; i < n; i++) + { + if (lookup_emptycells(i, g) == EMPTY) + fprintf(stderr, " Voxel %ld is empty. \n", i); + else + { + v = lookup_hashtable(i, g); + prn_voxel(v); + } + } - fprintf(stderr, " End Grid \n"); - } + fprintf(stderr, " End Grid \n"); + } VOID prn_ray(RAY *r) - { - RAYINFO *ri; - GRID *g; + { + RAYINFO *ri; + GRID *g; - fprintf(stderr, " Print Ray id %ld \n", r->id ); - fprintf(stderr, " origin: ( %lf, %lf, %lf ) \n", r->P[0], r->P[1], r->P[2]); - fprintf(stderr, " direction: ( %lf, %lf, %lf ) \n", r->D[0], r->D[1], r->D[2] ); - fprintf(stderr, " indx_inc3D[0,1,2] = [ %ld, %ld, %ld ] \n", r->indx_inc3D[0],r->indx_inc3D[1],r->indx_inc3D[2] ); - fprintf(stderr, " ri_indx = %ld \n", r->ri_indx); - fprintf(stderr, " rayinfo: \n"); + fprintf(stderr, " Print Ray id %ld \n", r->id ); + fprintf(stderr, " origin: ( %lf, %lf, %lf ) \n", r->P[0], r->P[1], r->P[2]); + fprintf(stderr, " direction: ( %lf, %lf, %lf ) \n", r->D[0], r->D[1], r->D[2] ); + fprintf(stderr, " indx_inc3D[0,1,2] = [ %ld, %ld, %ld ] \n", r->indx_inc3D[0],r->indx_inc3D[1],r->indx_inc3D[2] ); + fprintf(stderr, " ri_indx = %ld \n", r->ri_indx); + fprintf(stderr, " rayinfo: \n"); - ri = r->ri; - g = ri->grid; + ri = r->ri; + g = ri->grid; - fprintf(stderr, " ray is in grid %ld \n", g->id ); - fprintf(stderr, " d[0,1,2] = [ %lf, %lf, %lf ] \n", ri->d[0], ri->d[1], ri->d[2]); - fprintf(stderr, " entry_plane %ld \n", ri->entry_plane ); - fprintf(stderr, " t_in = %lf \n", ri->t_in ); - fprintf(stderr, " exit_plane %ld \n", ri->exit_plane ); - fprintf(stderr, " t_out = %lf \n", ri->t_out ); - fprintf(stderr, " delta[0,1,2] = [ %lf, %lf, %lf ] \n", ri->delta[0], ri->delta[1], ri->delta[2]); - fprintf(stderr, " index3D[0,1,2] = [ %ld, %ld, %ld ] \n", ri->index3D[0], ri->index3D[1], ri->index3D[2]); - fprintf(stderr, " index1D = %ld \n", ri->index1D ); - fprintf(stderr, " indx_inc1D[0,1,2] = [ %ld, %ld, %ld ] \n", ri->indx_inc1D[0], ri->indx_inc1D[1], ri->indx_inc1D[2]); - fprintf(stderr, " End Ray \n"); - } + fprintf(stderr, " ray is in grid %ld \n", g->id ); + fprintf(stderr, " d[0,1,2] = [ %lf, %lf, %lf ] \n", ri->d[0], ri->d[1], ri->d[2]); + fprintf(stderr, " entry_plane %ld \n", ri->entry_plane ); + fprintf(stderr, " t_in = %lf \n", ri->t_in ); + fprintf(stderr, " exit_plane %ld \n", ri->exit_plane ); + fprintf(stderr, " t_out = %lf \n", ri->t_out ); + fprintf(stderr, " delta[0,1,2] = [ %lf, %lf, %lf ] \n", ri->delta[0], ri->delta[1], ri->delta[2]); + fprintf(stderr, " index3D[0,1,2] = [ %ld, %ld, %ld ] \n", ri->index3D[0], ri->index3D[1], ri->index3D[2]); + fprintf(stderr, " index1D = %ld \n", ri->index1D ); + fprintf(stderr, " indx_inc1D[0,1,2] = [ %ld, %ld, %ld ] \n", ri->indx_inc1D[0], ri->indx_inc1D[1], ri->indx_inc1D[2]); + fprintf(stderr, " End Ray \n"); + } VOID prn_PrimElem(ELEMENT *p) - { - BBOX b; + { + BBOX b; - if (p == NULL) - { - fprintf(stderr, "%s: prn_PrimElem: Null pointer.\n", ProgName); - exit(-1); - } + if (p == NULL) + { + fprintf(stderr, "%s: prn_PrimElem: Null pointer.\n", ProgName); + exit(-1); + } - fprintf(stderr, "PrimElem: index %ld ptr %p, PrimObj index %ld ptr %p \n", - p->index, p, p->parent->index, p->parent); + fprintf(stderr, "PrimElem: index %ld ptr %p, PrimObj index %ld ptr %p \n", + p->index, p, p->parent->index, p->parent); - b = p->bv; + b = p->bv; - fprintf(stderr, " BBox: ( %lf, %lf, %lf ) -> \n ( %lf, %lf, %lf ) \n", - b.dnear[0],b.dnear[1],b.dnear[2],b.dfar[0],b.dfar[1],b.dfar[2] ); - } + fprintf(stderr, " BBox: ( %lf, %lf, %lf ) -> \n ( %lf, %lf, %lf ) \n", + b.dnear[0],b.dnear[1],b.dnear[2],b.dfar[0],b.dfar[1],b.dfar[2] ); + } VOID prn_bintree_node(BTNODE *b) - { - INT i; + { + INT i; - fprintf(stderr, "Bintree node: \n"); - fprintf(stderr, " indecies of cell: ( %ld, %ld, %ld ) \n", b->i[0], b->i[1], b->i[2]); - fprintf(stderr, " gridsizes: ( %ld, %ld, %ld ) \n", b->n[0], b->n[1], b->n[2]); - fprintf(stderr, " minimum point ( %lf, %lf, %lf ) \n", b->p[0], b->p[1], b->p[2]); - fprintf(stderr, " subdiv axis %ld \n", b->axis); - fprintf(stderr, " number of primitives %ld \n", b->nprims); - fprintf(stderr, " Primitive element list: \n"); + fprintf(stderr, "Bintree node: \n"); + fprintf(stderr, " indecies of cell: ( %ld, %ld, %ld ) \n", b->i[0], b->i[1], b->i[2]); + fprintf(stderr, " gridsizes: ( %ld, %ld, %ld ) \n", b->n[0], b->n[1], b->n[2]); + fprintf(stderr, " minimum point ( %lf, %lf, %lf ) \n", b->p[0], b->p[1], b->p[2]); + fprintf(stderr, " subdiv axis %ld \n", b->axis); + fprintf(stderr, " number of primitives %ld \n", b->nprims); + fprintf(stderr, " Primitive element list: \n"); - if (b->nprims > 0) - for (i = 0; i < b->nprims; i++) - { - fprintf(stderr, " %ld", b->pe[i]->index); + if (b->nprims > 0) + for (i = 0; i < b->nprims; i++) + { + fprintf(stderr, " %ld", b->pe[i]->index); - if (i % 8 == 7) - fprintf(stderr, "\n"); - } + if (i % 8 == 7) + fprintf(stderr, "\n"); + } - fprintf(stderr, "\n End of bintree node \n"); - } + fprintf(stderr, "\n End of bintree node \n"); + } VOID prn_bintree_leaves(BTNODE *root) - { - BTNODE *b; + { + BTNODE *b; - b = root; - if (b->axis == -1) - prn_bintree_node(b); - else - { - prn_bintree_leaves(b->btn[0]); - prn_bintree_leaves(b->btn[1]); - } - } + b = root; + if (b->axis == -1) + prn_bintree_node(b); + else + { + prn_bintree_leaves(b->btn[0]); + prn_bintree_leaves(b->btn[1]); + } + } VOID prn_pepa_prim_list(ELEMENT **pepa, INT nprims) - { - INT i; + { + INT i; - if (nprims > 0) - { - for (i = 0; i < nprims; i++) - { - fprintf(stderr, " %ld", pepa[i]->index); + if (nprims > 0) + { + for (i = 0; i < nprims; i++) + { + fprintf(stderr, " %ld", pepa[i]->index); - if (i % 8 == 7) - fprintf(stderr, "\n"); - } - } - } + if (i % 8 == 7) + fprintf(stderr, "\n"); + } + } + } diff --git a/splash2/codes/apps/raytrace/husetup.C b/splash2/codes/apps/raytrace/husetup.C index 8a755e550..d39fec79e 100644 --- a/splash2/codes/apps/raytrace/husetup.C +++ b/splash2/codes/apps/raytrace/husetup.C @@ -26,11 +26,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + /* * NAME * Huniform_defaults - setup the five HUG parameter defaults @@ -43,13 +44,13 @@ */ VOID Huniform_defaults() - { - hu_max_prims_cell = 2; - hu_gridsize = 5; - hu_numbuckets = 23; - hu_max_subdiv_level = 1; - hu_lazy = 0; - } + { + hu_max_prims_cell = 2; + hu_gridsize = 5; + hu_numbuckets = 23; + hu_max_subdiv_level = 1; + hu_lazy = 0; + } @@ -66,27 +67,27 @@ VOID Huniform_defaults() */ VOID BuildHierarchy_Uniform() - { - INT num_pe; - GRID *g; - GRID *ng; - VOXEL *v; - ELEMENT **pepa; + { + INT num_pe; + GRID *g; + GRID *ng; + VOXEL *v; + ELEMENT **pepa; - init_masks(); + init_masks(); - pepa = MakeElementArray(&num_pe); + pepa = MakeElementArray(&num_pe); - v = init_world_voxel(pepa,num_pe); + v = init_world_voxel(pepa,num_pe); - gm->world_level_grid = init_world_grid(v, pepa, num_pe); - g = gm->world_level_grid; + gm->world_level_grid = init_world_grid(v, pepa, num_pe); + g = gm->world_level_grid; - ng = create_grid(v, g, num_pe); + ng = create_grid(v, g, num_pe); - fprintf(stderr, "Uniform Hierarchy built.\n"); - } + fprintf(stderr, "Uniform Hierarchy built.\n"); + } @@ -108,34 +109,34 @@ VOID BuildHierarchy_Uniform() */ VOID IntersectHuniformPrimlist(INT *intersectPrim, IRECORD *hit, VOXEL *v, RAY *r, INT pid) - { - ELEMENT **pptr; /* Primitive element list ptr. */ - OBJECT *peParent; /* Ptr to parent object. */ - ELEMENT *pe; /* Primitive element ptr. */ - IRECORD newhit[ISECT_MAX]; /* Hit recorder. */ - INT hitcode,i; - REAL t_out; + { + ELEMENT **pptr; /* Primitive element list ptr. */ + OBJECT *peParent; /* Ptr to parent object. */ + ELEMENT *pe; /* Primitive element ptr. */ + IRECORD newhit[ISECT_MAX]; /* Hit recorder. */ + INT hitcode,i; + REAL t_out; - t_out = r->ri->t_out; - hit[0].t = HUGE_REAL; - pptr = (ELEMENT**)v->cell; + t_out = r->ri->t_out; + hit[0].t = HUGE_REAL; + pptr = (ELEMENT**)v->cell; - for (i = 0; i < v->numelements; i++) - { - pe = pptr[i]; - peParent = pe->parent; - hitcode = (*peParent->procs->pe_intersect)(r, pe, newhit); + for (i = 0; i < v->numelements; i++) + { + pe = pptr[i]; + peParent = pe->parent; + hitcode = (*peParent->procs->pe_intersect)(r, pe, newhit); - if (hitcode) - if (newhit[0].t < hit[0].t && newhit[0].t < t_out) - hit[0] = newhit[0]; - } + if (hitcode) + if (newhit[0].t < hit[0].t && newhit[0].t < t_out) + hit[0] = newhit[0]; + } - if (hit[0].t < HUGE_REAL) - *intersectPrim = TRUE; - else - *intersectPrim = FALSE; - } + if (hit[0].t < HUGE_REAL) + *intersectPrim = TRUE; + else + *intersectPrim = FALSE; + } @@ -156,56 +157,56 @@ VOID IntersectHuniformPrimlist(INT *intersectPrim, IRECORD *hit, VOXEL *v, RAY * */ REAL HuniformShadowIntersect(RAY *r, REAL lightlength, ELEMENT *pe, INT pid) - { - INT status; - INT hitcode,i; - REAL trans; /* Transparency factor. */ - OBJECT *peParent; /* Ptr to parent object. */ - ELEMENT **pptr; /* Primitive element list ptr. */ - ELEMENT *pe2; /* Ptr to element. */ - IRECORD newhit[ISECT_MAX]; /* Hit record. */ - VOXEL *v; + { + INT status; + INT hitcode,i; + REAL trans; /* Transparency factor. */ + OBJECT *peParent; /* Ptr to parent object. */ + ELEMENT **pptr; /* Primitive element list ptr. */ + ELEMENT *pe2; /* Ptr to element. */ + IRECORD newhit[ISECT_MAX]; /* Hit record. */ + VOXEL *v; - trans = 1.0; + trans = 1.0; - /* Now try uniform hierarchy. */ + /* Now try uniform hierarchy. */ - r->ri = NULL; - v = init_ray(r, gm->world_level_grid); + r->ri = NULL; + v = init_ray(r, gm->world_level_grid); - if (v == NULL) - { - reset_rayinfo(r); - return(trans); - } + if (v == NULL) + { + reset_rayinfo(r); + return(trans); + } - newhit[0].t = HUGE_REAL; - status = IN_WORLD; + newhit[0].t = HUGE_REAL; + status = IN_WORLD; - while (trans > 0.0 && status != EXITED_WORLD) - { - /* Intersect primitives in cell. */ + while (trans > 0.0 && status != EXITED_WORLD) + { + /* Intersect primitives in cell. */ - pptr = (ELEMENT**)v->cell; + pptr = (ELEMENT**)v->cell; - for (i = 0; (i < v->numelements) && (trans > 0.0); i++) - { - pe2 = pptr[i]; - peParent = pe2->parent; - hitcode = (*peParent->procs->pe_intersect)(r, pe2, newhit); + for (i = 0; (i < v->numelements) && (trans > 0.0); i++) + { + pe2 = pptr[i]; + peParent = pe2->parent; + hitcode = (*peParent->procs->pe_intersect)(r, pe2, newhit); - if (hitcode && newhit[0].pelem != pe && newhit[0].t < lightlength) - trans *= newhit[0].pelem->parent->surf->ktran; + if (hitcode && newhit[0].pelem != pe && newhit[0].t < lightlength) + trans *= newhit[0].pelem->parent->surf->ktran; - } + } - if (trans > 0.0) - v = next_nonempty_leaf(r, STEP, &status); - } + if (trans > 0.0) + v = next_nonempty_leaf(r, STEP, &status); + } - reset_rayinfo(r); - return (trans); - } + reset_rayinfo(r); + return (trans); + } @@ -225,33 +226,33 @@ REAL HuniformShadowIntersect(RAY *r, REAL lightlength, ELEMENT *pe, INT pid) */ BOOL TraverseHierarchyUniform(RAY *r, IRECORD *hit, INT pid) - { - INT status; - INT intersectPrim; - VOXEL *v; + { + INT status; + INT intersectPrim; + VOXEL *v; - r->ri = NULL; - v = init_ray(r, gm->world_level_grid); + r->ri = NULL; + v = init_ray(r, gm->world_level_grid); - if (v == NULL) - { - reset_rayinfo(r); - return (FALSE); - } + if (v == NULL) + { + reset_rayinfo(r); + return (FALSE); + } - intersectPrim = FALSE; - hit[0].t = HUGE_REAL; - status = IN_WORLD; + intersectPrim = FALSE; + hit[0].t = HUGE_REAL; + status = IN_WORLD; - while (!intersectPrim && status != EXITED_WORLD) - { - IntersectHuniformPrimlist(&intersectPrim, hit, v, r, pid); + while (!intersectPrim && status != EXITED_WORLD) + { + IntersectHuniformPrimlist(&intersectPrim, hit, v, r, pid); - if (!intersectPrim) - v = next_nonempty_leaf(r, STEP, &status); - } + if (!intersectPrim) + v = next_nonempty_leaf(r, STEP, &status); + } - reset_rayinfo(r); - return (intersectPrim); - } + reset_rayinfo(r); + return (intersectPrim); + } diff --git a/splash2/codes/apps/raytrace/hutv.C b/splash2/codes/apps/raytrace/hutv.C index 46b3eb35d..1bba31313 100644 --- a/splash2/codes/apps/raytrace/hutv.C +++ b/splash2/codes/apps/raytrace/hutv.C @@ -23,9 +23,8 @@ */ -#include -#include - +#include +#include #include "rt.h" /* @@ -51,8 +50,8 @@ REAL eps_t = 1.0E-10; */ VOID prn_tv_stats() - { - } + { + } @@ -73,9 +72,9 @@ VOID prn_tv_stats() */ INT send_ray(RAY *r, VOXEL *v) - { - return(0); - } + { + return(0); + } @@ -100,25 +99,25 @@ INT send_ray(RAY *r, VOXEL *v) */ VOXEL *lookup_hashtable(INT indx, GRID *g) - { - INT i; - VOXEL *v; + { + INT i; + VOXEL *v; - i = indx - ((indx / g->num_buckets) * g->num_buckets); - v = g->hashtable[i]; + i = indx - ((indx / g->num_buckets) * g->num_buckets); + v = g->hashtable[i]; - while (v->id != indx) - { - v = v->next; - if (v == NULL) - { - fprintf(stderr, "hashtable error \n"); - exit(-1); - } - } + while (v->id != indx) + { + v = v->next; + if (v == NULL) + { + fprintf(stderr, "hashtable error \n"); + exit(-1); + } + } - return (v); - } + return (v); + } @@ -141,20 +140,20 @@ VOXEL *lookup_hashtable(INT indx, GRID *g) */ INT lookup_emptycells(INT indx, GRID *g) - { - INT i, w, r, num_bits; - UINT p, b; + { + INT i, w, r, num_bits; + UINT p, b; - num_bits = sizeof(UINT)*8; + num_bits = sizeof(UINT)*8; - w = indx / num_bits; - r = indx - w * num_bits; - p = g->emptycells[w]; - b = p & (MSB >> r); - i = b > 0 ? EMPTY : NONEMPTY; + w = indx / num_bits; + r = indx - w * num_bits; + p = g->emptycells[w]; + b = p & (MSB >> r); + i = b > 0 ? EMPTY : NONEMPTY; - return (i); - } + return (i); + } @@ -176,15 +175,15 @@ INT lookup_emptycells(INT indx, GRID *g) */ VOID pop_up_a_grid(RAY *r) - { - RAYINFO *old_ri; + { + RAYINFO *old_ri; - old_ri = r->ri; - r->ri = old_ri->next; + old_ri = r->ri; + r->ri = old_ri->next; - free_rayinfo(r); + free_rayinfo(r); - } + } @@ -206,306 +205,306 @@ VOID pop_up_a_grid(RAY *r) */ VOID push_down_grid(RAY *r, VOXEL *v) - { - INT n; /* # cells per axis in new grid. */ - INT small; - INT i_in, i_out, i, il, ih; - REAL wc[3]; /* Entry point of grid in world coord.*/ - REAL ti; - REAL del1, del2; - REAL t_in, t_out, tl, th; - REAL t[6], min[3]; - GRID *new_g; - RAYINFO *new_ri; - RAYINFO *old_ri; + { + INT n; /* # cells per axis in new grid. */ + INT small; + INT i_in, i_out, i, il, ih; + REAL wc[3]; /* Entry point of grid in world coord.*/ + REAL ti; + REAL del1, del2; + REAL t_in, t_out, tl, th; + REAL t[6], min[3]; + GRID *new_g; + RAYINFO *new_ri; + RAYINFO *old_ri; - old_ri = r->ri; - new_g = (GRID *)v->cell; + old_ri = r->ri; + new_g = (GRID *)v->cell; - new_ri = ma_rayinfo(r); - r->ri = new_ri; + new_ri = ma_rayinfo(r); + r->ri = new_ri; - new_ri->next = old_ri; /* Push new RAYINFO onto the stack. */ - new_ri->grid = new_g; + new_ri->next = old_ri; /* Push new RAYINFO onto the stack. */ + new_ri->grid = new_g; - n = new_g->indx_inc[1]; + n = new_g->indx_inc[1]; - new_ri->delta[0] = old_ri->delta[0]/n; - new_ri->delta[1] = old_ri->delta[1]/n; - new_ri->delta[2] = old_ri->delta[2]/n; + new_ri->delta[0] = old_ri->delta[0]/n; + new_ri->delta[1] = old_ri->delta[1]/n; + new_ri->delta[2] = old_ri->delta[2]/n; - if (old_ri->t_in >= 0.0) - { - /* Ray origin outside the voxel. */ + if (old_ri->t_in >= 0.0) + { + /* Ray origin outside the voxel. */ - new_ri->entry_plane = old_ri->entry_plane; - new_ri->t_in = old_ri->t_in; - ti = old_ri->t_in + eps_t; - } - else - { - /* Ray origin inside the voxel. */ + new_ri->entry_plane = old_ri->entry_plane; + new_ri->t_in = old_ri->t_in; + ti = old_ri->t_in + eps_t; + } + else + { + /* Ray origin inside the voxel. */ - ti= 0.0; - new_ri->entry_plane = -1; /* no entry plane calculated */ - new_ri->t_in = old_ri->t_in; - } + ti= 0.0; + new_ri->entry_plane = -1; /* no entry plane calculated */ + new_ri->t_in = old_ri->t_in; + } - wc[0] = ti*r->D[0] + r->P[0]; - wc[1] = ti*r->D[1] + r->P[1]; - wc[2] = ti*r->D[2] + r->P[2]; + wc[0] = ti*r->D[0] + r->P[0]; + wc[1] = ti*r->D[1] + r->P[1]; + wc[2] = ti*r->D[2] + r->P[2]; - new_ri->index3D[0] = (INT)((wc[0] - new_g->min[0]) / new_g->cellsize[0]); + new_ri->index3D[0] = (INT)((wc[0] - new_g->min[0]) / new_g->cellsize[0]); - if (new_ri->index3D[0] < 0) - new_ri->index3D[0] = 0; + if (new_ri->index3D[0] < 0) + new_ri->index3D[0] = 0; - if (new_ri->index3D[0] >= n) - new_ri->index3D[0] = n - 1; + if (new_ri->index3D[0] >= n) + new_ri->index3D[0] = n - 1; - new_ri->index3D[1] = (INT)((wc[1] - new_g->min[1]) / new_g->cellsize[1]); + new_ri->index3D[1] = (INT)((wc[1] - new_g->min[1]) / new_g->cellsize[1]); - if (new_ri->index3D[1] < 0) - new_ri->index3D[1] = 0; + if (new_ri->index3D[1] < 0) + new_ri->index3D[1] = 0; - if (new_ri->index3D[1] >= n) - new_ri->index3D[1] = n - 1; + if (new_ri->index3D[1] >= n) + new_ri->index3D[1] = n - 1; - new_ri->index3D[2] = (INT)((wc[2] - new_g->min[2]) / new_g->cellsize[2]); + new_ri->index3D[2] = (INT)((wc[2] - new_g->min[2]) / new_g->cellsize[2]); - if (new_ri->index3D[2] < 0) - new_ri->index3D[2] = 0; + if (new_ri->index3D[2] < 0) + new_ri->index3D[2] = 0; - if (new_ri->index3D[2] >= n) - new_ri->index3D[2] = n - 1; + if (new_ri->index3D[2] >= n) + new_ri->index3D[2] = n - 1; - new_ri->index1D = new_ri->index3D[0] + new_ri->index3D[1]*n + new_ri->index3D[2]*new_g->indx_inc[2]; + new_ri->index1D = new_ri->index3D[0] + new_ri->index3D[1]*n + new_ri->index3D[2]*new_g->indx_inc[2]; - new_ri->indx_inc1D[0] = r->indx_inc3D[0]; - new_ri->indx_inc1D[1] = r->indx_inc3D[1]*n; - new_ri->indx_inc1D[2] = r->indx_inc3D[2]*new_g->indx_inc[2]; + new_ri->indx_inc1D[0] = r->indx_inc3D[0]; + new_ri->indx_inc1D[1] = r->indx_inc3D[1]*n; + new_ri->indx_inc1D[2] = r->indx_inc3D[2]*new_g->indx_inc[2]; - switch (new_ri->entry_plane) - { - case 3: /* max X */ - new_ri->entry_plane = 0; + switch (new_ri->entry_plane) + { + case 3: /* max X */ + new_ri->entry_plane = 0; - case 0: /* min X */ - new_ri->d[0] = new_ri->t_in + new_ri->delta[0]; + case 0: /* min X */ + new_ri->d[0] = new_ri->t_in + new_ri->delta[0]; - del1 = fmod((double)(old_ri->d[1] - new_ri->t_in), - (double)new_ri->delta[1]); + del1 = fmod((double)(old_ri->d[1] - new_ri->t_in), + (double)new_ri->delta[1]); - if (del1 <= eps_t) - new_ri->d[1] = new_ri->t_in + new_ri->delta[1]; - else - new_ri->d[1] = new_ri->t_in + del1; + if (del1 <= eps_t) + new_ri->d[1] = new_ri->t_in + new_ri->delta[1]; + else + new_ri->d[1] = new_ri->t_in + del1; - del2= fmod((double)(old_ri->d[2] - new_ri->t_in), - (double)new_ri->delta[2]); + del2= fmod((double)(old_ri->d[2] - new_ri->t_in), + (double)new_ri->delta[2]); - if (del2 <= eps_t) - new_ri->d[2] = new_ri->t_in + new_ri->delta[2]; - else - new_ri->d[2] = new_ri->t_in + del2; + if (del2 <= eps_t) + new_ri->d[2] = new_ri->t_in + new_ri->delta[2]; + else + new_ri->d[2] = new_ri->t_in + del2; - small = new_ri->d[0] <= new_ri->d[1] ? 0 : 1; - small = new_ri->d[small] <= new_ri->d[2] ? small : 2; + small = new_ri->d[0] <= new_ri->d[1] ? 0 : 1; + small = new_ri->d[small] <= new_ri->d[2] ? small : 2; - new_ri->t_out = new_ri->d[small]; - new_ri->exit_plane = small; - break; + new_ri->t_out = new_ri->d[small]; + new_ri->exit_plane = small; + break; - case 4: /* max Y */ - new_ri->entry_plane = 1; + case 4: /* max Y */ + new_ri->entry_plane = 1; - case 1: /* min Y */ - new_ri->d[1] = new_ri->t_in + new_ri->delta[1]; + case 1: /* min Y */ + new_ri->d[1] = new_ri->t_in + new_ri->delta[1]; - del1 = fmod((double)(old_ri->d[0] - new_ri->t_in), - (double)new_ri->delta[0]); + del1 = fmod((double)(old_ri->d[0] - new_ri->t_in), + (double)new_ri->delta[0]); - if (del1 <= eps_t) - new_ri->d[0] = new_ri->t_in + new_ri->delta[0]; - else - new_ri->d[0] = new_ri->t_in + del1; + if (del1 <= eps_t) + new_ri->d[0] = new_ri->t_in + new_ri->delta[0]; + else + new_ri->d[0] = new_ri->t_in + del1; - del2 = fmod((double)(old_ri->d[2] - new_ri->t_in), - (double)new_ri->delta[2]); + del2 = fmod((double)(old_ri->d[2] - new_ri->t_in), + (double)new_ri->delta[2]); - if (del2 <= eps_t) - new_ri->d[2] = new_ri->t_in + new_ri->delta[2]; - else - new_ri->d[2] = new_ri->t_in + del2; + if (del2 <= eps_t) + new_ri->d[2] = new_ri->t_in + new_ri->delta[2]; + else + new_ri->d[2] = new_ri->t_in + del2; - small = new_ri->d[0] <= new_ri->d[1] ? 0 : 1; - small = new_ri->d[small] <= new_ri->d[2] ? small : 2; + small = new_ri->d[0] <= new_ri->d[1] ? 0 : 1; + small = new_ri->d[small] <= new_ri->d[2] ? small : 2; - new_ri->t_out = new_ri->d[small]; - new_ri->exit_plane = small; - break; + new_ri->t_out = new_ri->d[small]; + new_ri->exit_plane = small; + break; - case 5: /* max Z */ - new_ri->entry_plane = 2; + case 5: /* max Z */ + new_ri->entry_plane = 2; - case 2: /* min Z */ - new_ri->d[2] = new_ri->t_in + new_ri->delta[2]; + case 2: /* min Z */ + new_ri->d[2] = new_ri->t_in + new_ri->delta[2]; - del1 = fmod((double)(old_ri->d[0] - new_ri->t_in), - (double)new_ri->delta[0]); + del1 = fmod((double)(old_ri->d[0] - new_ri->t_in), + (double)new_ri->delta[0]); - if (del1 <= eps_t) - new_ri->d[0] = new_ri->t_in + new_ri->delta[0]; - else - new_ri->d[0] = new_ri->t_in + del1; + if (del1 <= eps_t) + new_ri->d[0] = new_ri->t_in + new_ri->delta[0]; + else + new_ri->d[0] = new_ri->t_in + del1; - del2 = fmod((double)(old_ri->d[1] - new_ri->t_in), - (double)new_ri->delta[1]); + del2 = fmod((double)(old_ri->d[1] - new_ri->t_in), + (double)new_ri->delta[1]); - if (del2 <= eps_t) - new_ri->d[1] = new_ri->t_in + new_ri->delta[1]; - else - new_ri->d[1] = new_ri->t_in + del2; + if (del2 <= eps_t) + new_ri->d[1] = new_ri->t_in + new_ri->delta[1]; + else + new_ri->d[1] = new_ri->t_in + del2; - small = new_ri->d[0] <= new_ri->d[1] ? 0 : 1; - small = new_ri->d[small] <= new_ri->d[2] ? small : 2; + small = new_ri->d[0] <= new_ri->d[1] ? 0 : 1; + small = new_ri->d[small] <= new_ri->d[2] ? small : 2; - new_ri->t_out = new_ri->d[small]; - new_ri->exit_plane = small; - break; + new_ri->t_out = new_ri->d[small]; + new_ri->exit_plane = small; + break; - case -1: /* No entry plane calculated, origin inside voxel. */ + case -1: /* No entry plane calculated, origin inside voxel. */ - min[0] = new_g->min[0] + new_ri->index3D[0]*new_g->cellsize[0]; - min[1] = new_g->min[1] + new_ri->index3D[1]*new_g->cellsize[1]; - min[2] = new_g->min[2] + new_ri->index3D[2]*new_g->cellsize[2]; + min[0] = new_g->min[0] + new_ri->index3D[0]*new_g->cellsize[0]; + min[1] = new_g->min[1] + new_ri->index3D[1]*new_g->cellsize[1]; + min[2] = new_g->min[2] + new_ri->index3D[2]*new_g->cellsize[2]; - if (r->D[0] == 0.0) - { - if (r->P[0] >= min[0] && r->P[0] <= min[0] + new_g->cellsize[0]) - t[0] = -HUGE_REAL; - else - t[0] = HUGE_REAL; - } - else - t[0] = (min[0] - r->P[0]) / r->D[0]; + if (r->D[0] == 0.0) + { + if (r->P[0] >= min[0] && r->P[0] <= min[0] + new_g->cellsize[0]) + t[0] = -HUGE_REAL; + else + t[0] = HUGE_REAL; + } + else + t[0] = (min[0] - r->P[0]) / r->D[0]; - if (r->D[1] == 0.0) - { - if (r->P[1] >= min[1] && r->P[1] <= min[1] + new_g->cellsize[1]) - t[1] = -HUGE_REAL; - else - t[1] = HUGE_REAL; - } - else - t[1] = (min[1] - r->P[1]) / r->D[1]; + if (r->D[1] == 0.0) + { + if (r->P[1] >= min[1] && r->P[1] <= min[1] + new_g->cellsize[1]) + t[1] = -HUGE_REAL; + else + t[1] = HUGE_REAL; + } + else + t[1] = (min[1] - r->P[1]) / r->D[1]; - if (r->D[2] == 0.0) - { - if (r->P[2] >= min[2] && r->P[2] <= min[2] + new_g->cellsize[2]) - t[2] = -HUGE_REAL; - else - t[2] = HUGE_REAL; - } - else - t[2] = (min[2] - r->P[2]) / r->D[2]; + if (r->D[2] == 0.0) + { + if (r->P[2] >= min[2] && r->P[2] <= min[2] + new_g->cellsize[2]) + t[2] = -HUGE_REAL; + else + t[2] = HUGE_REAL; + } + else + t[2] = (min[2] - r->P[2]) / r->D[2]; - if (r->D[0] == 0.0) - { - if (r->P[0] >= min[0] && r->P[0] <= min[0] + new_g->cellsize[0]) - t[3] = HUGE_REAL; - else - t[3] = HUGE_REAL; - } - else - t[3] = (min[0] + new_g->cellsize[0] - r->P[0]) / r->D[0]; + if (r->D[0] == 0.0) + { + if (r->P[0] >= min[0] && r->P[0] <= min[0] + new_g->cellsize[0]) + t[3] = HUGE_REAL; + else + t[3] = HUGE_REAL; + } + else + t[3] = (min[0] + new_g->cellsize[0] - r->P[0]) / r->D[0]; - if (r->D[1] == 0.0) - { - if (r->P[1] >= min[1] && r->P[1] <= min[1] + new_g->cellsize[1]) - t[4] = HUGE_REAL; - else - t[4] = HUGE_REAL; - } - else - t[4] = (min[1] + new_g->cellsize[1] - r->P[1]) / r->D[1]; + if (r->D[1] == 0.0) + { + if (r->P[1] >= min[1] && r->P[1] <= min[1] + new_g->cellsize[1]) + t[4] = HUGE_REAL; + else + t[4] = HUGE_REAL; + } + else + t[4] = (min[1] + new_g->cellsize[1] - r->P[1]) / r->D[1]; - if (r->D[2] == 0.0) - { - if (r->P[2] >= min[2] && r->P[2] <= min[2] + new_g->cellsize[2]) - t[5] = HUGE_REAL; - else - t[5] = HUGE_REAL; - } - else - t[5] = (min[2] + new_g->cellsize[2] - r->P[2]) / r->D[2]; + if (r->D[2] == 0.0) + { + if (r->P[2] >= min[2] && r->P[2] <= min[2] + new_g->cellsize[2]) + t[5] = HUGE_REAL; + else + t[5] = HUGE_REAL; + } + else + t[5] = (min[2] + new_g->cellsize[2] - r->P[2]) / r->D[2]; - t_in = -HUGE_REAL; - i_in = -1; - t_out = HUGE_REAL; - i_out = -1; + t_in = -HUGE_REAL; + i_in = -1; + t_out = HUGE_REAL; + i_out = -1; - for (i = 0; i < 3; i++) - { - if (t[i] < t[i + 3]) - { - tl = t[i]; - il = i; - th = t[i + 3]; - ih = i + 3; - } - else - { - tl = t[i + 3]; - il = i + 3; - th = t[i]; - ih = i; - } + for (i = 0; i < 3; i++) + { + if (t[i] < t[i + 3]) + { + tl = t[i]; + il = i; + th = t[i + 3]; + ih = i + 3; + } + else + { + tl = t[i + 3]; + il = i + 3; + th = t[i]; + ih = i; + } - new_ri->d[i] = th; + new_ri->d[i] = th; // if (t_in < tl) /* max min */ - if (t_in - tl < 0.0) - { - t_in = tl; - i_in = il; - } + if (t_in - tl < 0.0) + { + t_in = tl; + i_in = il; + } // if (t_out > th) /* min max */ - if (t_out - th > 0.0) - { - t_out = th; - i_out = ih; - } - } + if (t_out - th > 0.0) + { + t_out = th; + i_out = ih; + } + } // if ((t_in > t_out) || (t_out < 0.0)) - if ((t_in - t_out > 0.0) || (t_out < 0.0)) - { - fprintf(stderr, "push_down_grid: Ray origin not in voxel \n"); - exit(-1); - } + if ((t_in - t_out > 0.0) || (t_out < 0.0)) + { + fprintf(stderr, "push_down_grid: Ray origin not in voxel \n"); + exit(-1); + } - if (i_in > 2) - i_in -= 3; + if (i_in > 2) + i_in -= 3; - if (i_out > 2) - i_out -= 3; + if (i_out > 2) + i_out -= 3; - new_ri->entry_plane = i_in; - new_ri->t_in = t_in; - new_ri->t_out = t_out; - new_ri->exit_plane = i_out; - break; - } - } + new_ri->entry_plane = i_in; + new_ri->t_in = t_in; + new_ri->t_out = t_out; + new_ri->exit_plane = i_out; + break; + } + } @@ -530,49 +529,49 @@ VOID push_down_grid(RAY *r, VOXEL *v) */ INT step_grid(RAY *r) - { - INT n; /* # cells per axis in grid. */ - INT small; /* Index of closest cell boundary. */ - INT *indx; - RAY *ra; - GRID *gr; - RAYINFO *rinfo; + { + INT n; /* # cells per axis in grid. */ + INT small; /* Index of closest cell boundary. */ + INT *indx; + RAY *ra; + GRID *gr; + RAYINFO *rinfo; - ra = r; - rinfo = r->ri; - gr = rinfo->grid; - indx = gr->indx_inc; - n = indx[1]; /* n = r->ri->grid->indx_inc[1]; */ + ra = r; + rinfo = r->ri; + gr = rinfo->grid; + indx = gr->indx_inc; + n = indx[1]; /* n = r->ri->grid->indx_inc[1]; */ - rinfo->t_in = rinfo->t_out; - rinfo->index3D[rinfo->exit_plane] += r->indx_inc3D[rinfo->exit_plane]; - rinfo->entry_plane = rinfo->exit_plane; + rinfo->t_in = rinfo->t_out; + rinfo->index3D[rinfo->exit_plane] += r->indx_inc3D[rinfo->exit_plane]; + rinfo->entry_plane = rinfo->exit_plane; - if (rinfo->index3D[rinfo->exit_plane] < 0 || rinfo->index3D[rinfo->exit_plane] >= n) - { - /* Out of range, off the grid. */ + if (rinfo->index3D[rinfo->exit_plane] < 0 || rinfo->index3D[rinfo->exit_plane] >= n) + { + /* Out of range, off the grid. */ - return (-1); - } - else - { - /* Within current grid. */ + return (-1); + } + else + { + /* Within current grid. */ - rinfo->d[rinfo->exit_plane] += rinfo->delta[rinfo->exit_plane]; - rinfo->index1D += rinfo->indx_inc1D[rinfo->exit_plane]; + rinfo->d[rinfo->exit_plane] += rinfo->delta[rinfo->exit_plane]; + rinfo->index1D += rinfo->indx_inc1D[rinfo->exit_plane]; - /* Update exit info. */ + /* Update exit info. */ - small = rinfo->d[0] <= rinfo->d[1] ? 0 : 1; - small = rinfo->d[small] <= rinfo->d[2] ? small : 2; + small = rinfo->d[0] <= rinfo->d[1] ? 0 : 1; + small = rinfo->d[small] <= rinfo->d[2] ? small : 2; - rinfo->t_out = rinfo->d[small]; - rinfo->exit_plane = small; + rinfo->t_out = rinfo->d[small]; + rinfo->exit_plane = small; - return (rinfo->index1D); - } - } + return (rinfo->index1D); + } + } @@ -597,34 +596,34 @@ INT step_grid(RAY *r) */ INT next_voxel(RAY *r) - { - INT indx; - GRID *gr; - RAYINFO *rinfo; + { + INT indx; + GRID *gr; + RAYINFO *rinfo; - while ((indx = step_grid(r)) == -1) - { - /* Step carried off grid. */ + while ((indx = step_grid(r)) == -1) + { + /* Step carried off grid. */ - rinfo = r->ri; - gr = rinfo->grid; + rinfo = r->ri; + gr = rinfo->grid; - if (gr->subdiv_level != 0) - { - pop_up_a_grid(r); - indx = r->ri->index1D; - } - else - { - /* Top level & off grid. */ - /* Exited world space. */ + if (gr->subdiv_level != 0) + { + pop_up_a_grid(r); + indx = r->ri->index1D; + } + else + { + /* Top level & off grid. */ + /* Exited world space. */ - return (-1); - } - } + return (-1); + } + } - return (indx); - } + return (indx); + } @@ -650,37 +649,37 @@ INT next_voxel(RAY *r) */ VOXEL *next_nonempty_voxel(RAY *r) - { - INT indx; - VOXEL *v; - GRID *gr; - RAYINFO *rinfo; + { + INT indx; + VOXEL *v; + GRID *gr; + RAYINFO *rinfo; - indx = next_voxel(r); - if (indx < 0) - return (NULL); + indx = next_voxel(r); + if (indx < 0) + return (NULL); - rinfo = r->ri; - gr = rinfo->grid; + rinfo = r->ri; + gr = rinfo->grid; - while (lookup_emptycells(indx, gr) == EMPTY) - { - indx = next_voxel(r); + while (lookup_emptycells(indx, gr) == EMPTY) + { + indx = next_voxel(r); - if (indx < 0) { - return (NULL); - } + if (indx < 0) { + return (NULL); + } - rinfo = r->ri; - gr = rinfo->grid; - } + rinfo = r->ri; + gr = rinfo->grid; + } - /* Found a nonempty cell. */ + /* Found a nonempty cell. */ - v = lookup_hashtable(indx, gr); + v = lookup_hashtable(indx, gr); - return (v); - } + return (v); + } @@ -720,72 +719,72 @@ VOXEL *next_nonempty_voxel(RAY *r) */ VOXEL *next_nonempty_leaf(RAY *r, INT step, INT *status) - { - INT indx; - VOXEL *v; - RAYINFO *rinfo; + { + INT indx; + VOXEL *v; + RAYINFO *rinfo; - if (step == STEP) - v = next_nonempty_voxel(r); - else - { - /* Only used by init_ray when step == 0. */ + if (step == STEP) + v = next_nonempty_voxel(r); + else + { + /* Only used by init_ray when step == 0. */ - rinfo = r->ri; - v = lookup_hashtable(rinfo->index1D, rinfo->grid); - } + rinfo = r->ri; + v = lookup_hashtable(rinfo->index1D, rinfo->grid); + } - if (v == NULL) - { - *status = EXITED_WORLD; - return (v); - } + if (v == NULL) + { + *status = EXITED_WORLD; + return (v); + } - /* Nonempty voxel either a GRID or a nonempty leaf. */ + /* Nonempty voxel either a GRID or a nonempty leaf. */ - while (v->celltype == REMOTE_GRID || v->celltype == GSM_GRID) - { - if (v->celltype == REMOTE_GRID) - { - send_ray(r, v); - *status = SENT_TO_REMOTE; - return (NULL); - } + while (v->celltype == REMOTE_GRID || v->celltype == GSM_GRID) + { + if (v->celltype == REMOTE_GRID) + { + send_ray(r, v); + *status = SENT_TO_REMOTE; + return (NULL); + } - push_down_grid(r, v); + push_down_grid(r, v); - rinfo = r->ri; - indx = rinfo->index1D; + rinfo = r->ri; + indx = rinfo->index1D; - if (lookup_emptycells(indx, rinfo->grid) != EMPTY) - { - v = lookup_hashtable(indx, rinfo->grid); - if (v->celltype != REMOTE_GRID && v->celltype != GSM_GRID) - { - /* Nonempty leaf. */ + if (lookup_emptycells(indx, rinfo->grid) != EMPTY) + { + v = lookup_hashtable(indx, rinfo->grid); + if (v->celltype != REMOTE_GRID && v->celltype != GSM_GRID) + { + /* Nonempty leaf. */ - if (v->celltype == REMOTE_VOXEL) - { - send_ray(r, v); - *status = SENT_TO_REMOTE; - return (NULL); - } + if (v->celltype == REMOTE_VOXEL) + { + send_ray(r, v); + *status = SENT_TO_REMOTE; + return (NULL); + } - return (v); - } + return (v); + } - /* Nonempty grid so do another while loop. */ - } - else - { - v = next_nonempty_leaf(r, STEP, status); + /* Nonempty grid so do another while loop. */ + } + else + { + v = next_nonempty_leaf(r, STEP, status); - return (v); - } - } + return (v); + } + } - return (v); - } + return (v); + } @@ -808,197 +807,197 @@ VOXEL *next_nonempty_leaf(RAY *r, INT step, INT *status) */ VOXEL *init_ray(RAY *r, GRID *g) - { - INT status; - INT indx, grid_id; - INT i_in, i_out, i, il, ih; - REAL t_in, t_out, tl, th; - REAL t[6]; - VOXEL *v; - GRID *gr; - RAYINFO *ri; + { + INT status; + INT indx, grid_id; + INT i_in, i_out, i, il, ih; + REAL t_in, t_out, tl, th; + REAL t[6]; + VOXEL *v; + GRID *gr; + RAYINFO *ri; - reset_rayinfo(r); + reset_rayinfo(r); - if (r->D[0] == 0.0) - { - if (r->P[0] >= g->min[0] && r->P[0] <= g->min[0] + g->cellsize[0]) - t[0] = -HUGE_REAL; - else - t[0] = HUGE_REAL; - } - else - t[0] = (g->min[0] - r->P[0]) / r->D[0]; + if (r->D[0] == 0.0) + { + if (r->P[0] >= g->min[0] && r->P[0] <= g->min[0] + g->cellsize[0]) + t[0] = -HUGE_REAL; + else + t[0] = HUGE_REAL; + } + else + t[0] = (g->min[0] - r->P[0]) / r->D[0]; - if (r->D[1] == 0.0) - { - if (r->P[1] >= g->min[1] && r->P[1] <= g->min[1] + g->cellsize[1]) - t[1] = -HUGE_REAL; - else - t[1] = HUGE_REAL; - } - else - t[1] = (g->min[1] - r->P[1]) / r->D[1]; + if (r->D[1] == 0.0) + { + if (r->P[1] >= g->min[1] && r->P[1] <= g->min[1] + g->cellsize[1]) + t[1] = -HUGE_REAL; + else + t[1] = HUGE_REAL; + } + else + t[1] = (g->min[1] - r->P[1]) / r->D[1]; - if (r->D[2] == 0.0) - { - if (r->P[2] >= g->min[2] && r->P[2] <= g->min[2] + g->cellsize[2]) - t[2] = -HUGE_REAL; - else - t[2] = HUGE_REAL; - } - else - t[2] = (g->min[2] - r->P[2]) / r->D[2]; + if (r->D[2] == 0.0) + { + if (r->P[2] >= g->min[2] && r->P[2] <= g->min[2] + g->cellsize[2]) + t[2] = -HUGE_REAL; + else + t[2] = HUGE_REAL; + } + else + t[2] = (g->min[2] - r->P[2]) / r->D[2]; - if (r->D[0] == 0.0) - { - if (r->P[0] >= g->min[0] && r->P[0] <= g->min[0] + g->cellsize[0]) - t[3] = HUGE_REAL; - else - t[3] = HUGE_REAL; - } - else - t[3] = (g->min[0] + g->cellsize[0] - r->P[0]) / r->D[0]; + if (r->D[0] == 0.0) + { + if (r->P[0] >= g->min[0] && r->P[0] <= g->min[0] + g->cellsize[0]) + t[3] = HUGE_REAL; + else + t[3] = HUGE_REAL; + } + else + t[3] = (g->min[0] + g->cellsize[0] - r->P[0]) / r->D[0]; - if (r->D[1] == 0.0) - { - if (r->P[1] >= g->min[1] && r->P[1] <= g->min[1] + g->cellsize[1]) - t[4] = HUGE_REAL; - else - t[4] = HUGE_REAL; - } - else - t[4] = (g->min[1] + g->cellsize[1] - r->P[1]) / r->D[1]; + if (r->D[1] == 0.0) + { + if (r->P[1] >= g->min[1] && r->P[1] <= g->min[1] + g->cellsize[1]) + t[4] = HUGE_REAL; + else + t[4] = HUGE_REAL; + } + else + t[4] = (g->min[1] + g->cellsize[1] - r->P[1]) / r->D[1]; - if (r->D[2] == 0.0) - { - if (r->P[2] >= g->min[2] && r->P[2] <= g->min[2] + g->cellsize[2]) - t[5] = HUGE_REAL; - else - t[5] = HUGE_REAL; - } - else - t[5] = (g->min[2] + g->cellsize[2] - r->P[2]) / r->D[2]; + if (r->D[2] == 0.0) + { + if (r->P[2] >= g->min[2] && r->P[2] <= g->min[2] + g->cellsize[2]) + t[5] = HUGE_REAL; + else + t[5] = HUGE_REAL; + } + else + t[5] = (g->min[2] + g->cellsize[2] - r->P[2]) / r->D[2]; - t_in = -HUGE_REAL; - i_in = -1; - t_out = HUGE_REAL; - i_out = -1; + t_in = -HUGE_REAL; + i_in = -1; + t_out = HUGE_REAL; + i_out = -1; - for (i = 0 ; i < 3; i++) - { - if (t[i] < t[i + 3]) - { - tl = t[i]; - il = i; - th = t[i + 3]; - ih = i+3; - } - else - { - tl = t[i + 3]; - il = i + 3; - th = t[i]; - ih = i; - } + for (i = 0 ; i < 3; i++) + { + if (t[i] < t[i + 3]) + { + tl = t[i]; + il = i; + th = t[i + 3]; + ih = i+3; + } + else + { + tl = t[i + 3]; + il = i + 3; + th = t[i]; + ih = i; + } - if (t_in < tl) /* max min */ - { - t_in = tl; - i_in = il; - } + if (t_in < tl) /* max min */ + { + t_in = tl; + i_in = il; + } - if (t_out > th) /* min max */ - { - t_out = th; - i_out = ih; - } - } + if (t_out > th) /* min max */ + { + t_out = th; + i_out = ih; + } + } - if (t_in >= t_out || t_out < 0.0) - { - return (NULL); /* Ray missed world cube. */ - } + if (t_in >= t_out || t_out < 0.0) + { + return (NULL); /* Ray missed world cube. */ + } - ri = ma_rayinfo(r); - r->ri = ri; - ri->grid = g; + ri = ma_rayinfo(r); + r->ri = ri; + ri->grid = g; - /* Store exit t[]s. */ + /* Store exit t[]s. */ - if (t[0] >= t[3]) - ri->d[0] = t[0]; - else - ri->d[0] = t[3]; + if (t[0] >= t[3]) + ri->d[0] = t[0]; + else + ri->d[0] = t[3]; - if (t[1] >= t[4]) - ri->d[1] = t[1]; - else - ri->d[1] = t[4]; + if (t[1] >= t[4]) + ri->d[1] = t[1]; + else + ri->d[1] = t[4]; - if (t[2] >= t[5]) - ri->d[2] = t[2]; - else - ri->d[2] = t[5]; + if (t[2] >= t[5]) + ri->d[2] = t[2]; + else + ri->d[2] = t[5]; - if (i_in > 2) - i_in -= 3; + if (i_in > 2) + i_in -= 3; - if (i_out > 2) - i_out -= 3; + if (i_out > 2) + i_out -= 3; - ri->entry_plane = i_in; - ri->t_in = t_in; - ri->t_out = t_out; - ri->exit_plane = i_out; + ri->entry_plane = i_in; + ri->t_in = t_in; + ri->t_out = t_out; + ri->exit_plane = i_out; - ri->delta[0] = r->D[0] == 0.0 ? HUGE_REAL : g->cellsize[0] / ABS(r->D[0]); - ri->delta[1] = r->D[1] == 0.0 ? HUGE_REAL : g->cellsize[1] / ABS(r->D[1]); - ri->delta[2] = r->D[2] == 0.0 ? HUGE_REAL : g->cellsize[2] / ABS(r->D[2]); + ri->delta[0] = r->D[0] == 0.0 ? HUGE_REAL : g->cellsize[0] / ABS(r->D[0]); + ri->delta[1] = r->D[1] == 0.0 ? HUGE_REAL : g->cellsize[1] / ABS(r->D[1]); + ri->delta[2] = r->D[2] == 0.0 ? HUGE_REAL : g->cellsize[2] / ABS(r->D[2]); - ri->index3D[0] = 0; - ri->index3D[1] = 0; - ri->index3D[2] = 0; + ri->index3D[0] = 0; + ri->index3D[1] = 0; + ri->index3D[2] = 0; - r->indx_inc3D[0] = r->D[0] >= 0.0 ? 1 : -1; - r->indx_inc3D[1] = r->D[1] >= 0.0 ? 1 : -1; - r->indx_inc3D[2] = r->D[2] >= 0.0 ? 1 : -1; + r->indx_inc3D[0] = r->D[0] >= 0.0 ? 1 : -1; + r->indx_inc3D[1] = r->D[1] >= 0.0 ? 1 : -1; + r->indx_inc3D[2] = r->D[2] >= 0.0 ? 1 : -1; - ri->index1D = 0; + ri->index1D = 0; - ri->indx_inc1D[0] = r->D[0] >= 0.0 ? 1 : -1; - ri->indx_inc1D[1] = r->D[1] >= 0.0 ? 1 : -1; - ri->indx_inc1D[2] = r->D[2] >= 0.0 ? 1 : -1; - ri->next = NULL; + ri->indx_inc1D[0] = r->D[0] >= 0.0 ? 1 : -1; + ri->indx_inc1D[1] = r->D[1] >= 0.0 ? 1 : -1; + ri->indx_inc1D[2] = r->D[2] >= 0.0 ? 1 : -1; + ri->next = NULL; - /* - * At this point the ray is in the top grid in the hierarchy it - * must now descend to a leaf cell. - */ + /* + * At this point the ray is in the top grid in the hierarchy it + * must now descend to a leaf cell. + */ - if ((v = next_nonempty_leaf(r, NO_STEP, &status)) != NULL) - { - ri = r->ri; - indx = ri->index1D; - gr = ri->grid; - grid_id = gr->id; - } - else - { - return (NULL); - } + if ((v = next_nonempty_leaf(r, NO_STEP, &status)) != NULL) + { + ri = r->ri; + indx = ri->index1D; + gr = ri->grid; + grid_id = gr->id; + } + else + { + return (NULL); + } - return (v); - } + return (v); + } diff --git a/splash2/codes/apps/raytrace/isect.C b/splash2/codes/apps/raytrace/isect.C index d39099987..43b4b7b48 100644 --- a/splash2/codes/apps/raytrace/isect.C +++ b/splash2/codes/apps/raytrace/isect.C @@ -26,11 +26,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + /* * NAME * Intersect - intersect ray with objects in linked list @@ -45,28 +46,28 @@ */ BOOL Intersect(RAY *pr, IRECORD *hit) - { - OBJECT *po; /* Ptr to the object. */ - IRECORD newhit; /* New intersection. */ + { + OBJECT *po; /* Ptr to the object. */ + IRECORD newhit; /* New intersection. */ - po = gm->modelroot; - hit->t = HUGE_REAL; - hit->pelem = NULL; + po = gm->modelroot; + hit->t = HUGE_REAL; + hit->pelem = NULL; - while (po) - { - if ((*po->procs->intersect)(pr, po, &newhit)) - if (newhit.t < hit[0].t) - *hit = newhit; + while (po) + { + if ((*po->procs->intersect)(pr, po, &newhit)) + if (newhit.t < hit[0].t) + *hit = newhit; - po = po->next; - } + po = po->next; + } - if (hit->t < HUGE_REAL) - return (TRUE); - else - return (FALSE); - } + if (hit->t < HUGE_REAL) + return (TRUE); + else + return (FALSE); + } @@ -88,22 +89,22 @@ BOOL Intersect(RAY *pr, IRECORD *hit) */ REAL ShadowIntersect(RAY *pr, REAL lightdist, ELEMENT *pe) - { - REAL trans; /* Transparency factor. */ - OBJECT *po; /* Ptr to the object. */ - IRECORD newhit; /* New hit record. */ + { + REAL trans; /* Transparency factor. */ + OBJECT *po; /* Ptr to the object. */ + IRECORD newhit; /* New hit record. */ - trans = 1.0; - po = gm->modelroot; + trans = 1.0; + po = gm->modelroot; - while (po && trans > 0.0) - { - if ((*po->procs->intersect)(pr, po, &newhit) && newhit.pelem != pe && newhit.t < lightdist) - trans *= newhit.pelem->parent->surf->ktran; + while (po && trans > 0.0) + { + if ((*po->procs->intersect)(pr, po, &newhit) && newhit.pelem != pe && newhit.t < lightdist) + trans *= newhit.pelem->parent->surf->ktran; - po = po->next; - } + po = po->next; + } - return (trans); - } + return (trans); + } diff --git a/splash2/codes/apps/raytrace/main.C b/splash2/codes/apps/raytrace/main.C index 1f761b197..21503ff1d 100644 --- a/splash2/codes/apps/raytrace/main.C +++ b/splash2/codes/apps/raytrace/main.C @@ -80,11 +80,11 @@ #define VERSION "1.00" -#include -#include - +#include +#include #include "rt.h" + CHAR *ProgName = "RAYTRACE"; /* The program name. */ INT nprocs = 1; /* The number of processors to use. */ INT MaxGlobMem = 32; /* Maximum global memory needed (MB).*/ @@ -104,19 +104,19 @@ INT dostats = 0; */ VOID Usage() - { - fprintf(stdout, "%s - parallel ray tracer\n", ProgName); - fprintf(stdout, "Version %s\n\n", VERSION); + { + fprintf(stdout, "%s - parallel ray tracer\n", ProgName); + fprintf(stdout, "Version %s\n\n", VERSION); - fprintf(stdout, "Usage:\t%s [options] envfile\n\n", ProgName); + fprintf(stdout, "Usage:\t%s [options] envfile\n\n", ProgName); - fprintf(stdout, "\t-h\tPrint this usage message.\n"); - fprintf(stdout, "\t-a\tEnable antialiasing with n subpixels (default = 1).\n\tWhen using with SPLASH suite for evaluation, use default (no antialiasing)\n"); - fprintf(stdout, "\t-m\tRequest n megabytes of global memory (default = 32).\n"); - fprintf(stdout, "\t-p\tRun on n processors (default = 1).\n"); + fprintf(stdout, "\t-h\tPrint this usage message.\n"); + fprintf(stdout, "\t-a\tEnable antialiasing with n subpixels (default = 1).\n\tWhen using with SPLASH suite for evaluation, use default (no antialiasing)\n"); + fprintf(stdout, "\t-m\tRequest n megabytes of global memory (default = 32).\n"); + fprintf(stdout, "\t-p\tRun on n processors (default = 1).\n"); fprintf(stdout, "\t-s\tMeasure and print per-process timing information.\n"); - fprintf(stdout, "\n"); - } + fprintf(stdout, "\n"); + } @@ -132,37 +132,37 @@ VOID Usage() */ VOID PrintStatistics() - { - /* - printf("\n****** Ray trace Stats ******\n"); + { + /* + printf("\n****** Ray trace Stats ******\n"); - printf("\tResolution:\t\t%ld by %ld\n", Display.xres+1, Display.yres+1); - printf("\tNumber Lights:\t\t%ld\n", nlights); - printf("\tAnti level:\t\t%ld\n", Display.maxAAsubdiv); - printf("\tTotal Rays:\t\t%ld\n", Stats.total_rays); - printf("\tPrimary Rays:\t\t%ld\n", Stats.prim_rays); - printf("\tShadow Rays:\t\t%ld\n", Stats.shad_rays); - printf("\tShadow Rays Hit:\t%ld\n", Stats.shad_rays_hit); - printf("\tShadow Rays Not Hit:\t%ld\n", Stats.shad_rays_not_hit); - printf("\tShadow Coherence Rays:\t%ld\n", Stats.shad_coherence_rays); - printf("\tReflective Rays:\t%ld\n", Stats.refl_rays); - printf("\tTransmissiveRays:\t%ld\n", Stats.trans_rays); - printf("\tAnti-Aliasing Rays:\t%ld\n", Stats.aa_rays); - printf("\tBackground Pixels:\t%ld\n", Stats.coverage); - printf("\tMax Tree depth reached:\t%ld\n", Stats.max_tree_depth); - printf("\tMax # prims tested for a ray:\t%ld\n", Stats.max_objs_ray); - printf("\tMax Rays shot for a pixel:\t%ld\n", Stats.max_rays_pixel); - printf("\tMax # prims tested for a pixel:\t%ld\n", Stats.max_objs_pixel); - printf("\n"); - */ + printf("\tResolution:\t\t%ld by %ld\n", Display.xres+1, Display.yres+1); + printf("\tNumber Lights:\t\t%ld\n", nlights); + printf("\tAnti level:\t\t%ld\n", Display.maxAAsubdiv); + printf("\tTotal Rays:\t\t%ld\n", Stats.total_rays); + printf("\tPrimary Rays:\t\t%ld\n", Stats.prim_rays); + printf("\tShadow Rays:\t\t%ld\n", Stats.shad_rays); + printf("\tShadow Rays Hit:\t%ld\n", Stats.shad_rays_hit); + printf("\tShadow Rays Not Hit:\t%ld\n", Stats.shad_rays_not_hit); + printf("\tShadow Coherence Rays:\t%ld\n", Stats.shad_coherence_rays); + printf("\tReflective Rays:\t%ld\n", Stats.refl_rays); + printf("\tTransmissiveRays:\t%ld\n", Stats.trans_rays); + printf("\tAnti-Aliasing Rays:\t%ld\n", Stats.aa_rays); + printf("\tBackground Pixels:\t%ld\n", Stats.coverage); + printf("\tMax Tree depth reached:\t%ld\n", Stats.max_tree_depth); + printf("\tMax # prims tested for a ray:\t%ld\n", Stats.max_objs_ray); + printf("\tMax Rays shot for a pixel:\t%ld\n", Stats.max_rays_pixel); + printf("\tMax # prims tested for a pixel:\t%ld\n", Stats.max_objs_pixel); + printf("\n"); + */ - if (TraversalType == TT_HUG) - { - /* prn_ds_stats(); - prn_tv_stats(); */ - ma_print(); - } - } + if (TraversalType == TT_HUG) + { + /* prn_ds_stats(); + prn_tv_stats(); */ + ma_print(); + } + } @@ -178,47 +178,47 @@ VOID PrintStatistics() */ VOID StartRayTrace() - { - INT pid; /* Our internal process id number. */ - UINT begin; - UINT end; + { + INT pid; /* Our internal process id number. */ + UINT begin; + UINT end; - LOCK(gm->pidlock) - pid = gm->pid++; - UNLOCK(gm->pidlock) + LOCK(gm->pidlock) + pid = gm->pid++; + UNLOCK(gm->pidlock) - BARINCLUDE(gm->start); + BARINCLUDE(gm->start); - if ((pid == 0) || (dostats)) + if ((pid == 0) || (dostats)) CLOCK(begin); - /* POSSIBLE ENHANCEMENT: Here's where one might lock processes down - to processors if need be */ + /* POSSIBLE ENHANCEMENT: Here's where one might lock processes down + to processors if need be */ - InitWorkPool(pid); - InitRayTreeStack(Display.maxlevel, pid); + InitWorkPool(pid); + InitRayTreeStack(Display.maxlevel, pid); - /* - * Wait for all processes to be created, initialize their work - * pools, and arrive at this point; then proceed. This BARRIER - * is absolutely required. Read comments in PutJob before - * moving this barrier. - */ + /* + * Wait for all processes to be created, initialize their work + * pools, and arrive at this point; then proceed. This BARRIER + * is absolutely required. Read comments in PutJob before + * moving this barrier. + */ - BARRIER(gm->start, gm->nprocs) + BARRIER(gm->start, gm->nprocs) - /* POSSIBLE ENHANCEMENT: Here's where one would RESET STATISTICS - and TIMING if one wanted to measure only the parallel part */ + /* POSSIBLE ENHANCEMENT: Here's where one would RESET STATISTICS + and TIMING if one wanted to measure only the parallel part */ - RayTrace(pid); + RayTrace(pid); - if ((pid == 0) || (dostats)) { + if ((pid == 0) || (dostats)) { CLOCK(end); gm->partime[pid] = (end - begin) & 0x7FFFFFFF; if (pid == 0) gm->par_start_time = begin; } - } + } @@ -242,191 +242,191 @@ VOID StartRayTrace() */ int main(int argc, CHAR *argv[]) - { - INT i; - UINT begin; - UINT end; - UINT lapsed; - MATRIX vtrans, Vinv; /* View transformation and inverse. */ + { + INT i; + UINT begin; + UINT end; + UINT lapsed; + MATRIX vtrans, Vinv; /* View transformation and inverse. */ - /* - * First, process command line arguments. - */ - i = 1; - while ((i < argc) && (argv[i][0] == '-')) { - switch (argv[i][1]) { - case '?': - case 'h': - case 'H': - Usage(); - exit(1); + /* + * First, process command line arguments. + */ + i = 1; + while ((i < argc) && (argv[i][0] == '-')) { + switch (argv[i][1]) { + case '?': + case 'h': + case 'H': + Usage(); + exit(1); - case 'a': - case 'A': - AntiAlias = TRUE; - if (argv[i][2] != '\0') { - NumSubRays = atoi(&argv[i][2]); - } else { - NumSubRays = atoi(&argv[++i][0]); - } - break; + case 'a': + case 'A': + AntiAlias = TRUE; + if (argv[i][2] != '\0') { + NumSubRays = atoi(&argv[i][2]); + } else { + NumSubRays = atoi(&argv[++i][0]); + } + break; - case 'm': - if (argv[i][2] != '\0') { - MaxGlobMem = atoi(&argv[i][2]); - } else { - MaxGlobMem = atoi(&argv[++i][0]); - } - break; + case 'm': + if (argv[i][2] != '\0') { + MaxGlobMem = atoi(&argv[i][2]); + } else { + MaxGlobMem = atoi(&argv[++i][0]); + } + break; - case 'p': - if (argv[i][2] != '\0') { - nprocs = atoi(&argv[i][2]); - } else { - nprocs = atoi(&argv[++i][0]); - } - break; + case 'p': + if (argv[i][2] != '\0') { + nprocs = atoi(&argv[i][2]); + } else { + nprocs = atoi(&argv[++i][0]); + } + break; - case 's': - case 'S': - dostats = TRUE; - break; + case 's': + case 'S': + dostats = TRUE; + break; - default: - fprintf(stderr, "%s: Invalid option \'%c\'.\n", ProgName, argv[i][0]); - exit(1); - } - i++; - } + default: + fprintf(stderr, "%s: Invalid option \'%c\'.\n", ProgName, argv[i][0]); + exit(1); + } + i++; + } - if (i == argc) { - Usage(); - exit(1); - } + if (i == argc) { + Usage(); + exit(1); + } - /* - * Make sure nprocs is within valid range. - */ + /* + * Make sure nprocs is within valid range. + */ - if (nprocs < 1 || nprocs > MAX_PROCS) - { - fprintf(stderr, "%s: Valid range for #processors is [1, %d].\n", ProgName, MAX_PROCS); - exit(1); - } + if (nprocs < 1 || nprocs > MAX_PROCS) + { + fprintf(stderr, "%s: Valid range for #processors is [1, %d].\n", ProgName, MAX_PROCS); + exit(1); + } - /* - * Print command line parameters. - */ + /* + * Print command line parameters. + */ - printf("\n"); - printf("Number of processors: \t%ld\n", nprocs); - printf("Global shared memory size:\t%ld MB\n", MaxGlobMem); - printf("Samples per pixel: \t%ld\n", NumSubRays); - printf("\n"); + printf("\n"); + printf("Number of processors: \t%ld\n", nprocs); + printf("Global shared memory size:\t%ld MB\n", MaxGlobMem); + printf("Samples per pixel: \t%ld\n", NumSubRays); + printf("\n"); - /* - * Initialize the shared memory environment and request the total - * amount of amount of shared memory we might need. This - * includes memory for the database, grid, and framebuffer. - */ + /* + * Initialize the shared memory environment and request the total + * amount of amount of shared memory we might need. This + * includes memory for the database, grid, and framebuffer. + */ - MaxGlobMem <<= 20; /* Convert MB to bytes. */ - MAIN_INITENV(,MaxGlobMem + 512*1024) - gm = (GMEM *)G_MALLOC(sizeof(GMEM)); + MaxGlobMem <<= 20; /* Convert MB to bytes. */ + MAIN_INITENV(,MaxGlobMem + 512*1024) + gm = (GMEM *)G_MALLOC(sizeof(GMEM)); - /* - * Perform shared environment initializations. - */ + /* + * Perform shared environment initializations. + */ - gm->nprocs = nprocs; - gm->pid = 0; - gm->rid = 1; + gm->nprocs = nprocs; + gm->pid = 0; + gm->rid = 1; - BARINIT(gm->start, nprocs) - LOCKINIT(gm->pidlock) - LOCKINIT(gm->ridlock) - LOCKINIT(gm->memlock) - ALOCKINIT(gm->wplock, nprocs) + BARINIT(gm->start, nprocs) + LOCKINIT(gm->pidlock) + LOCKINIT(gm->ridlock) + LOCKINIT(gm->memlock) + ALOCKINIT(gm->wplock, nprocs) /* POSSIBLE ENHANCEMENT: Here is where one might distribute the raystruct data structure across physically distributed memories as desired. */ - if (!GlobalHeapInit(MaxGlobMem)) - { - fprintf(stderr, "%s: Cannot initialize global heap.\n", ProgName); - exit(1); - } + if (!GlobalHeapInit(MaxGlobMem)) + { + fprintf(stderr, "%s: Cannot initialize global heap.\n", ProgName); + exit(1); + } - /* - * Initialize HUG parameters, read environment and geometry files. - */ + /* + * Initialize HUG parameters, read environment and geometry files. + */ - Huniform_defaults(); - ReadEnvFile(/* *argv*/argv[i]); - ReadGeoFile(GeoFileName); - OpenFrameBuffer(); + Huniform_defaults(); + ReadEnvFile(/* *argv*/argv[i]); + ReadGeoFile(GeoFileName); + OpenFrameBuffer(); - /* - * Compute view transform and its inverse. - */ + /* + * Compute view transform and its inverse. + */ - CreateViewMatrix(); - MatrixCopy(vtrans, View.vtrans); - MatrixInverse(Vinv, vtrans); - MatrixCopy(View.vtransInv, Vinv); + CreateViewMatrix(); + MatrixCopy(vtrans, View.vtrans); + MatrixInverse(Vinv, vtrans); + MatrixCopy(View.vtransInv, Vinv); - /* - * Print out what we have so far. - */ + /* + * Print out what we have so far. + */ - printf("Number of primitive objects: \t%ld\n", prim_obj_cnt); - printf("Number of primitive elements:\t%ld\n", prim_elem_cnt); + printf("Number of primitive objects: \t%ld\n", prim_obj_cnt); + printf("Number of primitive elements:\t%ld\n", prim_elem_cnt); - /* - * Preprocess database into hierarchical uniform grid. - */ + /* + * Preprocess database into hierarchical uniform grid. + */ - if (TraversalType == TT_HUG) - BuildHierarchy_Uniform(); + if (TraversalType == TT_HUG) + BuildHierarchy_Uniform(); - /* - * Now create slave processes. - */ + /* + * Now create slave processes. + */ - CLOCK(begin) - CREATE(StartRayTrace, gm->nprocs); - WAIT_FOR_END(gm->nprocs); - CLOCK(end) + CLOCK(begin) + CREATE(StartRayTrace, gm->nprocs); + WAIT_FOR_END(gm->nprocs); + CLOCK(end) - /* - * We are finished. Clean up, print statistics and run time. - */ + /* + * We are finished. Clean up, print statistics and run time. + */ - CloseFrameBuffer(PicFileName); - PrintStatistics(); + CloseFrameBuffer(PicFileName); + PrintStatistics(); - lapsed = (end - begin) & 0x7FFFFFFF; + lapsed = (end - begin) & 0x7FFFFFFF; - printf("TIMING STATISTICS MEASURED BY MAIN PROCESS:\n"); - printf(" Overall start time %20lu\n", begin); - printf(" Overall end time %20lu\n", end); - printf(" Total time with initialization %20lu\n", lapsed); - printf(" Total time without initialization %20lu\n", end - gm->par_start_time); + printf("TIMING STATISTICS MEASURED BY MAIN PROCESS:\n"); + printf(" Overall start time %20lu\n", begin); + printf(" Overall end time %20lu\n", end); + printf(" Total time with initialization %20lu\n", lapsed); + printf(" Total time without initialization %20lu\n", end - gm->par_start_time); if (dostats) { unsigned totalproctime, maxproctime, minproctime; @@ -454,6 +454,6 @@ int main(int argc, CHAR *argv[]) printf("%20s%20d\n","Avg = ",(int) (((double) totalproctime) / ((double) (1.0 * gm->nprocs)))); } - MAIN_END - } + MAIN_END + } diff --git a/splash2/codes/apps/raytrace/matrix.C b/splash2/codes/apps/raytrace/matrix.C index 87eb34d68..1883f5a0d 100644 --- a/splash2/codes/apps/raytrace/matrix.C +++ b/splash2/codes/apps/raytrace/matrix.C @@ -25,11 +25,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + typedef REAL GJMATRIX[4][8]; /* Matrix for Gauss-Jordan inversion.*/ @@ -47,17 +48,17 @@ typedef REAL GJMATRIX[4][8]; /* Matrix for Gauss-Jordan inversion.*/ */ VOID VecNorm(POINT V) - { - REAL l; + { + REAL l; - l = VecLen(V); - if (l > 0.0000001) - { - V[0] /= l; - V[1] /= l; - V[2] /= l; - } - } + l = VecLen(V); + if (l > 0.0000001) + { + V[0] /= l; + V[1] /= l; + V[2] /= l; + } + } @@ -76,24 +77,24 @@ VOID VecNorm(POINT V) */ VOID VecMatMult(POINT Vt, MATRIX M, POINT V) - { - INT i, j; - POINT tvec; + { + INT i, j; + POINT tvec; - /* tvec = M * V */ + /* tvec = M * V */ - for (i = 0; i < 4; i++) - { - tvec[i] = 0.0; - for (j = 0; j < 4; j++) - tvec[i] += V[j] * M[j][i]; - } + for (i = 0; i < 4; i++) + { + tvec[i] = 0.0; + for (j = 0; j < 4; j++) + tvec[i] += V[j] * M[j][i]; + } - /* copy tvec to Vt */ + /* copy tvec to Vt */ - for (i = 0; i < 4; i++) - Vt[i] = tvec[i]; - } + for (i = 0; i < 4; i++) + Vt[i] = tvec[i]; + } @@ -111,21 +112,21 @@ VOID VecMatMult(POINT Vt, MATRIX M, POINT V) */ VOID PrintMatrix(MATRIX M, CHAR *s) - { - INT i, j; + { + INT i, j; - printf("\n%s\n", s); + printf("\n%s\n", s); - for (i = 0; i < 4; i++) - { - printf("\t"); + for (i = 0; i < 4; i++) + { + printf("\t"); - for (j = 0; j < 4; j++) - printf("%f ", M[i][j]); + for (j = 0; j < 4; j++) + printf("%f ", M[i][j]); - printf("\n"); - } - } + printf("\n"); + } + } @@ -142,18 +143,18 @@ VOID PrintMatrix(MATRIX M, CHAR *s) */ VOID MatrixIdentity(MATRIX M) - { - INT i, j; + { + INT i, j; - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - M[i][j] = 0.0; + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + M[i][j] = 0.0; - M[0][0] = 1.0; - M[1][1] = 1.0; - M[2][2] = 1.0; - M[3][3] = 1.0; - } + M[0][0] = 1.0; + M[1][1] = 1.0; + M[2][2] = 1.0; + M[3][3] = 1.0; + } @@ -171,13 +172,13 @@ VOID MatrixIdentity(MATRIX M) */ VOID MatrixCopy(MATRIX A, MATRIX B) - { - INT i, j; + { + INT i, j; - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - A[i][j] = B[i][j]; - } + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + A[i][j] = B[i][j]; + } @@ -195,16 +196,16 @@ VOID MatrixCopy(MATRIX A, MATRIX B) */ VOID MatrixTranspose(MATRIX MT, MATRIX M) - { - INT i, j; - MATRIX tmp; + { + INT i, j; + MATRIX tmp; - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - tmp[j][i] = M[i][j]; + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + tmp[j][i] = M[i][j]; - MatrixCopy(MT, tmp); - } + MatrixCopy(MT, tmp); + } @@ -221,26 +222,26 @@ VOID MatrixTranspose(MATRIX MT, MATRIX M) */ VOID MatrixMult(MATRIX C, MATRIX A, MATRIX B) - { - INT i, j, k; - MATRIX T; /* Temporary matrix. */ + { + INT i, j, k; + MATRIX T; /* Temporary matrix. */ - /* T = A*B */ + /* T = A*B */ - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - { - T[i][j] = 0.0; - for (k = 0; k < 4; k++) - T[i][j] += A[i][k] * B[k][j]; - } + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + { + T[i][j] = 0.0; + for (k = 0; k < 4; k++) + T[i][j] += A[i][k] * B[k][j]; + } - /* copy T to C */ + /* copy T to C */ - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - C[i][j] = T[i][j]; - } + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + C[i][j] = T[i][j]; + } @@ -258,98 +259,98 @@ VOID MatrixMult(MATRIX C, MATRIX A, MATRIX B) */ VOID MatrixInverse(MATRIX Minv, MATRIX Mat) - { - INT i, j, k; /* Indices. */ - GJMATRIX gjmat; /* Inverse calculator. */ - REAL tbuf[8]; /* Row holder. */ - REAL pval, aval; /* Pivot candidates. */ - INT prow; /* Pivot row number. */ - REAL c; /* Pivot scale factor. */ - MATRIX tmp; + { + INT i, j, k; /* Indices. */ + GJMATRIX gjmat; /* Inverse calculator. */ + REAL tbuf[8]; /* Row holder. */ + REAL pval, aval; /* Pivot candidates. */ + INT prow; /* Pivot row number. */ + REAL c; /* Pivot scale factor. */ + MATRIX tmp; - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) - gjmat[i][j] = Mat[i][j]; + for (i = 0; i < 4; i++) + for (j = 0; j < 4; j++) + gjmat[i][j] = Mat[i][j]; - k = 0; - for (i = 4; i < 8; i++) - { - for (j = 4; j < 8; j++) - if (i == j) - gjmat[k][j] = 1.0; - else - gjmat[k][j] = 0.0; - k++ ; - } + k = 0; + for (i = 4; i < 8; i++) + { + for (j = 4; j < 8; j++) + if (i == j) + gjmat[k][j] = 1.0; + else + gjmat[k][j] = 0.0; + k++ ; + } - /* Gaussian elimination. */ + /* Gaussian elimination. */ - for (i = 0; i < 3; i++) - { - pval = ABS(gjmat[i][i]); - prow = i; + for (i = 0; i < 3; i++) + { + pval = ABS(gjmat[i][i]); + prow = i; - for (j = i + 1; j < 4; j++) - { - aval = ABS(gjmat[j][i]); - if (aval > pval) - { - pval = aval; - prow = j; - } - } + for (j = i + 1; j < 4; j++) + { + aval = ABS(gjmat[j][i]); + if (aval > pval) + { + pval = aval; + prow = j; + } + } - if (i != prow) - { - for (k = 0; k < 8; k++) - tbuf[k] = gjmat[i][k]; + if (i != prow) + { + for (k = 0; k < 8; k++) + tbuf[k] = gjmat[i][k]; - for (k = 0; k < 8; k++) - gjmat[i][k] = gjmat[prow][k]; + for (k = 0; k < 8; k++) + gjmat[i][k] = gjmat[prow][k]; - for (k = 0; k < 8; k++) - gjmat[prow][k] = tbuf[k]; - } + for (k = 0; k < 8; k++) + gjmat[prow][k] = tbuf[k]; + } - for (j = i + 1; j < 4; j++) - { - c = gjmat[j][i] / gjmat[i][i]; - gjmat[j][i] = 0.0; + for (j = i + 1; j < 4; j++) + { + c = gjmat[j][i] / gjmat[i][i]; + gjmat[j][i] = 0.0; - for (k = i + 1; k < 8; k++) - gjmat[j][k] = gjmat[j][k] - c * gjmat[i][k]; - } - } + for (k = i + 1; k < 8; k++) + gjmat[j][k] = gjmat[j][k] - c * gjmat[i][k]; + } + } - /* Zero columns */ + /* Zero columns */ - for (i = 0; i < 3; i++) - for (j = i + 1; j < 4; j++) - { - c = gjmat[i][j] / gjmat[j][j]; - gjmat[i][j] = 0.0; + for (i = 0; i < 3; i++) + for (j = i + 1; j < 4; j++) + { + c = gjmat[i][j] / gjmat[j][j]; + gjmat[i][j] = 0.0; - for (k = j + 1; k < 8; k++) - gjmat[i][k] = gjmat[i][k] - c * gjmat[j][k]; - } + for (k = j + 1; k < 8; k++) + gjmat[i][k] = gjmat[i][k] - c * gjmat[j][k]; + } - for (i = 0; i < 4; i++) - for (k = 4; k < 8; k++) /* normalize row */ - gjmat[i][k] /= gjmat[i][i]; + for (i = 0; i < 4; i++) + for (k = 4; k < 8; k++) /* normalize row */ + gjmat[i][k] /= gjmat[i][i]; - /* Generate inverse matrix. */ + /* Generate inverse matrix. */ - for (i = 0; i < 4; i++) - for (j = 4; j < 8; j++) - Minv[i][j - 4] = gjmat[i][j]; + for (i = 0; i < 4; i++) + for (j = 4; j < 8; j++) + Minv[i][j - 4] = gjmat[i][j]; - MatrixMult(tmp, Mat, Minv); - } + MatrixMult(tmp, Mat, Minv); + } @@ -367,13 +368,13 @@ VOID MatrixInverse(MATRIX Minv, MATRIX Mat) */ VOID Translate(MATRIX M, REAL dx, REAL dy, REAL dz) - { - MatrixIdentity(M); + { + MatrixIdentity(M); - M[3][0] = dx; - M[3][1] = dy; - M[3][2] = dz; - } + M[3][0] = dx; + M[3][1] = dy; + M[3][2] = dz; + } @@ -391,13 +392,13 @@ VOID Translate(MATRIX M, REAL dx, REAL dy, REAL dz) */ VOID Scale(MATRIX M, REAL sx, REAL sy, REAL sz) - { - MatrixIdentity(M); + { + MatrixIdentity(M); - M[0][0] = sx; - M[1][1] = sy; - M[2][2] = sz; - } + M[0][0] = sx; + M[1][1] = sy; + M[2][2] = sz; + } @@ -416,41 +417,41 @@ VOID Scale(MATRIX M, REAL sx, REAL sy, REAL sz) */ VOID Rotate(INT axis, MATRIX M, REAL angle) - { - REAL cosangle; - REAL sinangle; + { + REAL cosangle; + REAL sinangle; - MatrixIdentity(M); + MatrixIdentity(M); - cosangle = cos(angle); - sinangle = sin(angle); + cosangle = cos(angle); + sinangle = sin(angle); - switch (axis) - { - case X_AXIS: - M[1][1] = cosangle; - M[1][2] = sinangle; - M[2][1] = -sinangle; - M[2][2] = cosangle; - break; + switch (axis) + { + case X_AXIS: + M[1][1] = cosangle; + M[1][2] = sinangle; + M[2][1] = -sinangle; + M[2][2] = cosangle; + break; - case Y_AXIS: - M[0][0] = cosangle; - M[0][2] = -sinangle; - M[2][0] = sinangle; - M[2][2] = cosangle; - break; + case Y_AXIS: + M[0][0] = cosangle; + M[0][2] = -sinangle; + M[2][0] = sinangle; + M[2][2] = cosangle; + break; - case Z_AXIS: - M[0][0] = cosangle; - M[0][1] = sinangle; - M[1][0] = -sinangle; - M[1][1] = cosangle; - break; + case Z_AXIS: + M[0][0] = cosangle; + M[0][1] = sinangle; + M[1][0] = -sinangle; + M[1][1] = cosangle; + break; - default: - printf("Unknown rotation axis %ld.\n", axis); - exit(5); - break; - } - } + default: + printf("Unknown rotation axis %ld.\n", axis); + exit(5); + break; + } + } diff --git a/splash2/codes/apps/raytrace/memory.C b/splash2/codes/apps/raytrace/memory.C index d4c9250d4..549d0d89c 100644 --- a/splash2/codes/apps/raytrace/memory.C +++ b/splash2/codes/apps/raytrace/memory.C @@ -29,11 +29,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + #define CKSM 0x55AA55AA #define PAGESIZE (4*1024) #define THRESHOLD (sizeof(NODE) + 16) @@ -100,18 +101,18 @@ INT maxmem_pepArray; */ VOID *LocalMalloc(UINT n, CHAR *msg) - { - VOID *p; + { + VOID *p; - p = (VOID *) /*malloc*/G_MALLOC(n); - if (!p) - { - printf("%s: %s cannot allocate local memory.\n", ProgName, msg); - exit(-1); - } + p = (VOID *) /*malloc*/G_MALLOC(n); + if (!p) + { + printf("%s: %s cannot allocate local memory.\n", ProgName, msg); + exit(-1); + } - return (p); - } + return (p); + } @@ -134,10 +135,10 @@ VOID *LocalMalloc(UINT n, CHAR *msg) */ VOID LocalFree(VOID *p) - { - free(p); + { + free(p); - } + } @@ -156,34 +157,34 @@ VOID LocalFree(VOID *p) */ VOID GlobalHeapWalk() - { - NODE huge *curr; + { + NODE huge *curr; - LOCK(gm->memlock) - curr = begmem; + LOCK(gm->memlock) + curr = begmem; - printf("freelist ->\t0x%08lX\n\n", (U32)gm->freelist); + printf("freelist ->\t0x%08lX\n\n", (U32)gm->freelist); - printf("node addr \tnode->next\tnode->size\tnode->free\tnode->cksm\n"); - printf("==========\t==========\t==========\t==========\t==========\n"); + printf("node addr \tnode->next\tnode->size\tnode->free\tnode->cksm\n"); + printf("==========\t==========\t==========\t==========\t==========\n"); - while (curr < endmem) - { - printf("0x%08lX\t0x%08lX\t%10ld\t%s\t\t0x%08lX\n", - (U32)curr, (U32)curr->next, curr->size, - (curr->free ? "FREE" : " "), curr->cksm); + while (curr < endmem) + { + printf("0x%08lX\t0x%08lX\t%10ld\t%s\t\t0x%08lX\n", + (U32)curr, (U32)curr->next, curr->size, + (curr->free ? "FREE" : " "), curr->cksm); - if (curr->cksm != CKSM) - { - fprintf(stderr, "GlobalHeapWalk: Invalid checksum in node.\n"); - exit(1); - } + if (curr->cksm != CKSM) + { + fprintf(stderr, "GlobalHeapWalk: Invalid checksum in node.\n"); + exit(1); + } - curr = NODE_ADD(curr, curr->size + nodesize); - } + curr = NODE_ADD(curr, curr->size + nodesize); + } - UNLOCK(gm->memlock) - } + UNLOCK(gm->memlock) + } @@ -212,27 +213,27 @@ VOID GlobalHeapWalk() */ BOOL GlobalHeapInit(UINT size) - { - size = ROUND_UP(size); - gm->freelist = (NODE huge *)G_MALLOC(size); + { + size = ROUND_UP(size); + gm->freelist = (NODE huge *)G_MALLOC(size); - if (!gm->freelist) - return (FALSE); + if (!gm->freelist) + return (FALSE); - nodesize = sizeof(NODE); - begmem = gm->freelist; - endmem = NODE_ADD(gm->freelist, size); + nodesize = sizeof(NODE); + begmem = gm->freelist; + endmem = NODE_ADD(gm->freelist, size); - gm->freelist->size = size - nodesize; - gm->freelist->next = NULL; - gm->freelist->free = TRUE; - gm->freelist->cksm = CKSM; + gm->freelist->size = size - nodesize; + gm->freelist->next = NULL; + gm->freelist->free = TRUE; + gm->freelist->cksm = CKSM; /* NOTE TO USERS: Here's where one can allocate the memory segment from - begmem to endmem round-robin among memories or however one desires */ + begmem to endmem round-robin among memories or however one desires */ - return (TRUE); - } + return (TRUE); + } @@ -265,81 +266,81 @@ BOOL GlobalHeapInit(UINT size) */ VOID *GlobalMalloc(UINT size, CHAR *msg) - { - NODE huge *prev; - NODE huge *curr; - NODE huge *next; + { + NODE huge *prev; + NODE huge *curr; + NODE huge *next; - if (!size) - return (NULL); + if (!size) + return (NULL); - LOCK(gm->memlock) + LOCK(gm->memlock) - prev = NULL; - curr = gm->freelist; - size = ROUND_UP(size); + prev = NULL; + curr = gm->freelist; + size = ROUND_UP(size); - /* - * Scan through list for large enough node (first fit). - */ + /* + * Scan through list for large enough node (first fit). + */ - while (curr && curr->size < size) - { - if (curr->cksm != CKSM) - { - fprintf(stderr, "GlobalMalloc: Invalid checksum in node.\n"); - exit(1); - } + while (curr && curr->size < size) + { + if (curr->cksm != CKSM) + { + fprintf(stderr, "GlobalMalloc: Invalid checksum in node.\n"); + exit(1); + } - if (curr->free != TRUE) - { - fprintf(stderr, "GlobalMalloc: Node in free list not marked as free.\n"); - exit(1); - } + if (curr->free != TRUE) + { + fprintf(stderr, "GlobalMalloc: Node in free list not marked as free.\n"); + exit(1); + } - prev = curr; - curr = curr->next; - } + prev = curr; + curr = curr->next; + } - if (!curr) - { - fprintf(stderr, "%s: %s cannot allocate global memory.\n", ProgName, msg); - exit(-1); - } + if (!curr) + { + fprintf(stderr, "%s: %s cannot allocate global memory.\n", ProgName, msg); + exit(-1); + } - /* - * If node is larger than needed, free extra space at end - * by inserting remaining space into free list. - */ + /* + * If node is larger than needed, free extra space at end + * by inserting remaining space into free list. + */ - if (curr->size - size > THRESHOLD) - { - next = NODE_ADD(curr, nodesize + size); - next->size = curr->size - nodesize - size; - next->next = curr->next; - next->free = TRUE; - next->cksm = CKSM; - curr->size = size; - } - else - next = curr->next; + if (curr->size - size > THRESHOLD) + { + next = NODE_ADD(curr, nodesize + size); + next->size = curr->size - nodesize - size; + next->next = curr->next; + next->free = TRUE; + next->cksm = CKSM; + curr->size = size; + } + else + next = curr->next; - if (!prev) - gm->freelist = next; - else - prev->next = next; + if (!prev) + gm->freelist = next; + else + prev->next = next; - UNLOCK(gm->memlock) - curr->next = NULL; - curr->free = FALSE; - curr = NODE_ADD(curr, nodesize); + UNLOCK(gm->memlock) + curr->next = NULL; + curr->free = FALSE; + curr = NODE_ADD(curr, nodesize); - return ((VOID *)curr); - } + return ((VOID *)curr); + } @@ -366,21 +367,21 @@ VOID *GlobalMalloc(UINT size, CHAR *msg) */ VOID *GlobalCalloc(UINT n, UINT size) - { - UINT nbytes; - UINT huge *p; - VOID huge *q; + { + UINT nbytes; + UINT huge *p; + VOID huge *q; - nbytes = ROUND_UP(n*size); + nbytes = ROUND_UP(n*size); - p = q = GlobalMalloc(nbytes, "GlobalCalloc"); + p = q = GlobalMalloc(nbytes, "GlobalCalloc"); - nbytes >>= 2; /* Need size in words. */ - while (nbytes--) - *p++ = 0; + nbytes >>= 2; /* Need size in words. */ + while (nbytes--) + *p++ = 0; - return (q); - } + return (q); + } @@ -441,162 +442,162 @@ VOID *GlobalCalloc(UINT n, UINT size) */ VOID *GlobalRealloc(VOID *p, UINT size) - { - UINT oldsize; - UINT newsize; - UINT totsize; - VOID huge *q; - UINT huge *r; - UINT huge *s; - NODE huge *pn; - NODE huge *prev; - NODE huge *curr; - NODE huge *next; - NODE huge *node; + { + UINT oldsize; + UINT newsize; + UINT totsize; + VOID huge *q; + UINT huge *r; + UINT huge *s; + NODE huge *pn; + NODE huge *prev; + NODE huge *curr; + NODE huge *next; + NODE huge *node; - if (!size) - { - GlobalFree(p); - return (NULL); - } + if (!size) + { + GlobalFree(p); + return (NULL); + } - if (!p) - return (GlobalMalloc(size, "GlobalRealloc")); + if (!p) + return (GlobalMalloc(size, "GlobalRealloc")); - pn = NODE_ADD(p, -nodesize); /* Adjust ptr back to arena. */ + pn = NODE_ADD(p, -nodesize); /* Adjust ptr back to arena. */ - if (pn->cksm != CKSM) - { - fprintf(stderr, "GlobalRealloc: Attempted to realloc node with invalid checksum.\n"); - exit(1); - } + if (pn->cksm != CKSM) + { + fprintf(stderr, "GlobalRealloc: Attempted to realloc node with invalid checksum.\n"); + exit(1); + } - if (pn->free) - { - fprintf(stderr, "GlobalRealloc: Attempted to realloc an unallocated node.\n"); - exit(1); - } + if (pn->free) + { + fprintf(stderr, "GlobalRealloc: Attempted to realloc an unallocated node.\n"); + exit(1); + } - newsize = ROUND_UP(size); - oldsize = pn->size; + newsize = ROUND_UP(size); + oldsize = pn->size; - /* - * If new size is less than current node size, truncate the node - * and return end to free list. - */ + /* + * If new size is less than current node size, truncate the node + * and return end to free list. + */ - if (newsize <= oldsize) - { - if (oldsize - newsize < THRESHOLD) - return (p); + if (newsize <= oldsize) + { + if (oldsize - newsize < THRESHOLD) + return (p); - pn->size = newsize; + pn->size = newsize; - next = NODE_ADD(p, newsize); - next->size = oldsize - nodesize - newsize; - next->next = NULL; - next->free = FALSE; - next->cksm = CKSM; - next = NODE_ADD(next, nodesize); + next = NODE_ADD(p, newsize); + next->size = oldsize - nodesize - newsize; + next->next = NULL; + next->free = FALSE; + next->cksm = CKSM; + next = NODE_ADD(next, nodesize); - GlobalFree(next); - return (p); - } + GlobalFree(next); + return (p); + } - /* - * New size is bigger than current node. Try to expand next node - * in list. - */ + /* + * New size is bigger than current node. Try to expand next node + * in list. + */ - next = NODE_ADD(p, oldsize); - totsize = oldsize + nodesize + next->size; + next = NODE_ADD(p, oldsize); + totsize = oldsize + nodesize + next->size; - LOCK(gm->memlock) - if (next < endmem && next->free && totsize >= newsize) - { - /* Find next in free list. */ + LOCK(gm->memlock) + if (next < endmem && next->free && totsize >= newsize) + { + /* Find next in free list. */ - prev = NULL; - curr = gm->freelist; + prev = NULL; + curr = gm->freelist; - while (curr && curr < next && curr < endmem) - { - prev = curr; - curr = curr->next; - } + while (curr && curr < next && curr < endmem) + { + prev = curr; + curr = curr->next; + } - if (curr != next) - { - fprintf(stderr, "GlobalRealloc: Could not find next node in free list.\n"); - exit(1); - } + if (curr != next) + { + fprintf(stderr, "GlobalRealloc: Could not find next node in free list.\n"); + exit(1); + } - if (totsize - newsize < THRESHOLD) - { - /* Just remove next from free list. */ + if (totsize - newsize < THRESHOLD) + { + /* Just remove next from free list. */ - if (!prev) - gm->freelist = next->next; - else - prev->next = next->next; + if (!prev) + gm->freelist = next->next; + else + prev->next = next->next; - next->next = NULL; - next->free = FALSE; - pn->size = totsize; + next->next = NULL; + next->free = FALSE; + pn->size = totsize; - UNLOCK(gm->memlock) - return (p); - } - else - { - /* Remove next from free list while adding node. */ + UNLOCK(gm->memlock) + return (p); + } + else + { + /* Remove next from free list while adding node. */ - node = NODE_ADD(p, newsize); - node->next = next->next; - node->size = totsize - nodesize - newsize; - node->free = TRUE; - node->cksm = CKSM; + node = NODE_ADD(p, newsize); + node->next = next->next; + node->size = totsize - nodesize - newsize; + node->free = TRUE; + node->cksm = CKSM; - if (!prev) - gm->freelist = node; - else - prev->next = node; + if (!prev) + gm->freelist = node; + else + prev->next = node; - next->next = NULL; - next->free = FALSE; - pn->size = newsize; + next->next = NULL; + next->free = FALSE; + pn->size = newsize; - UNLOCK(gm->memlock) - return (p); - } - } + UNLOCK(gm->memlock) + return (p); + } + } - /* - * New size is bigger than current node, but next node in list - * could not be expanded. Try to allocate new node and move data - * to new location. - */ + /* + * New size is bigger than current node, but next node in list + * could not be expanded. Try to allocate new node and move data + * to new location. + */ - UNLOCK(gm->memlock) + UNLOCK(gm->memlock) - s = q = GlobalMalloc(newsize, "GlobalRealloc"); - if (!q) - return (NULL); + s = q = GlobalMalloc(newsize, "GlobalRealloc"); + if (!q) + return (NULL); - r = (UINT huge *)p; - oldsize >>= 2; + r = (UINT huge *)p; + oldsize >>= 2; - while (oldsize--) - *s++ = *r++; + while (oldsize--) + *s++ = *r++; - GlobalFree(p); - return (q); - } + GlobalFree(p); + return (q); + } @@ -619,175 +620,175 @@ VOID *GlobalRealloc(VOID *p, UINT size) */ VOID GlobalFree(VOID *p) - { - BOOL pcom; /* TRUE if prev can combine. */ - BOOL ncom; /* TRUE if next can combine. */ - NODE huge *pn; - NODE huge *prev; /* Pointer to previous node. */ - NODE huge *curr; /* Pointer to this node. */ - NODE huge *next; /* Pointer to next node. */ + { + BOOL pcom; /* TRUE if prev can combine. */ + BOOL ncom; /* TRUE if next can combine. */ + NODE huge *pn; + NODE huge *prev; /* Pointer to previous node. */ + NODE huge *curr; /* Pointer to this node. */ + NODE huge *next; /* Pointer to next node. */ - if (!begmem) - return; + if (!begmem) + return; - pn = NODE_ADD(p, -nodesize); /* Adjust ptr back to arena. */ + pn = NODE_ADD(p, -nodesize); /* Adjust ptr back to arena. */ - if (pn->cksm != CKSM) - { - fprintf(stderr, "GlobalFree: Attempted to free node with invalid checksum.\n"); - exit(1); - } + if (pn->cksm != CKSM) + { + fprintf(stderr, "GlobalFree: Attempted to free node with invalid checksum.\n"); + exit(1); + } - if (pn->free) - { - fprintf(stderr, "GlobalFree: Attempted to free unallocated node.\n"); - exit(1); - } + if (pn->free) + { + fprintf(stderr, "GlobalFree: Attempted to free unallocated node.\n"); + exit(1); + } - pcom = FALSE; - prev = NULL; + pcom = FALSE; + prev = NULL; - LOCK(gm->memlock) - if (gm->freelist) - { - /* - * Search the memory arena blocks for previous free neighbor. - */ + LOCK(gm->memlock) + if (gm->freelist) + { + /* + * Search the memory arena blocks for previous free neighbor. + */ - curr = gm->freelist; + curr = gm->freelist; - while (curr < pn && curr < endmem) - { - if (curr->cksm != CKSM) - { - fprintf(stderr, "GlobalFree: Invalid checksum in previous node.\n"); - exit(1); - } + while (curr < pn && curr < endmem) + { + if (curr->cksm != CKSM) + { + fprintf(stderr, "GlobalFree: Invalid checksum in previous node.\n"); + exit(1); + } - if (curr->free) - { - prev = curr; - pcom = TRUE; - } - else - pcom = FALSE; + if (curr->free) + { + prev = curr; + pcom = TRUE; + } + else + pcom = FALSE; - curr = NODE_ADD(curr, curr->size + nodesize); - } + curr = NODE_ADD(curr, curr->size + nodesize); + } - /* - * Make sure we found the original node. - */ + /* + * Make sure we found the original node. + */ - if (curr >= endmem) - { - fprintf(stdout, "freelist=0x%p, curr=0x%p, size=0x%lu, pn=0x%p, endmem=0x%p\n", gm->freelist, curr, curr->size, pn, endmem); - fprintf(stderr, "GlobalFree: Search for previous block fell off end of memory.\n"); - exit(1); - } - } + if (curr >= endmem) + { + fprintf(stdout, "freelist=0x%p, curr=0x%p, size=0x%lu, pn=0x%p, endmem=0x%p\n", gm->freelist, curr, curr->size, pn, endmem); + fprintf(stderr, "GlobalFree: Search for previous block fell off end of memory.\n"); + exit(1); + } + } - /* - * Search the memory arena blocks for next free neighbor. - */ + /* + * Search the memory arena blocks for next free neighbor. + */ - ncom = TRUE; - next = NULL; - curr = NODE_ADD(pn, pn->size + nodesize); + ncom = TRUE; + next = NULL; + curr = NODE_ADD(pn, pn->size + nodesize); - while (!next && curr < endmem) - { - if (curr->cksm != CKSM) - { - fprintf(stderr, "GlobalFree: Invalid checksum in next node.\n"); - exit(1); - } + while (!next && curr < endmem) + { + if (curr->cksm != CKSM) + { + fprintf(stderr, "GlobalFree: Invalid checksum in next node.\n"); + exit(1); + } - if (curr->free) - next = curr; - else - ncom = FALSE; + if (curr->free) + next = curr; + else + ncom = FALSE; - curr = NODE_ADD(curr, curr->size + nodesize); - } + curr = NODE_ADD(curr, curr->size + nodesize); + } - if (!next) /* Loop may have fallen thru.*/ - ncom = FALSE; + if (!next) /* Loop may have fallen thru.*/ + ncom = FALSE; - curr = pn; - curr->free = TRUE; /* Mark NODE as free. */ + curr = pn; + curr->free = TRUE; /* Mark NODE as free. */ - /* - * Attempt to combine the three nodes (prev, current, next). - * There are 9 cases to consider (16 total, but 7 are degenerate). - */ + /* + * Attempt to combine the three nodes (prev, current, next). + * There are 9 cases to consider (16 total, but 7 are degenerate). + */ - if (next && !ncom && pcom) - { - prev->next = next; - prev->size += curr->size + nodesize; - } - else - if (next && !ncom && prev && !pcom) - { - prev->next = curr; - curr->next = next; - } - else - if (next && !ncom && !prev) - { - gm->freelist = curr; - curr->next = next; - } - else - if (ncom && pcom) - { - prev->next = next->next; - prev->size += curr->size + next->size + 2*nodesize; - } - else - if (ncom && prev && !pcom) - { - prev->next = curr; - curr->next = next->next; - curr->size += next->size + nodesize; - } - else - if (ncom && !prev) - { - gm->freelist = curr; - curr->next = next->next; - curr->size += next->size + nodesize; - } - else - if (!next && pcom) - { - prev->next = NULL; - prev->size += curr->size + nodesize; - } - else - if (!next && prev && !pcom) - { - prev->next = curr; - curr->next = NULL; - } - else - if (!next && !prev) - { - gm->freelist = curr; - curr->next = NULL; - } + if (next && !ncom && pcom) + { + prev->next = next; + prev->size += curr->size + nodesize; + } + else + if (next && !ncom && prev && !pcom) + { + prev->next = curr; + curr->next = next; + } + else + if (next && !ncom && !prev) + { + gm->freelist = curr; + curr->next = next; + } + else + if (ncom && pcom) + { + prev->next = next->next; + prev->size += curr->size + next->size + 2*nodesize; + } + else + if (ncom && prev && !pcom) + { + prev->next = curr; + curr->next = next->next; + curr->size += next->size + nodesize; + } + else + if (ncom && !prev) + { + gm->freelist = curr; + curr->next = next->next; + curr->size += next->size + nodesize; + } + else + if (!next && pcom) + { + prev->next = NULL; + prev->size += curr->size + nodesize; + } + else + if (!next && prev && !pcom) + { + prev->next = curr; + curr->next = NULL; + } + else + if (!next && !prev) + { + gm->freelist = curr; + curr->next = NULL; + } - UNLOCK(gm->memlock) - return; - } + UNLOCK(gm->memlock) + return; + } @@ -807,25 +808,25 @@ VOID GlobalFree(VOID *p) */ UINT GlobalMemAvl() - { - UINT total; - NODE huge *curr; + { + UINT total; + NODE huge *curr; - LOCK(gm->memlock) - total = 0; - curr = gm->freelist; + LOCK(gm->memlock) + total = 0; + curr = gm->freelist; - while (curr) - { - total += curr->size; - curr = curr->next; - } + while (curr) + { + total += curr->size; + curr = curr->next; + } - total = ROUND_DN(total); + total = ROUND_DN(total); - UNLOCK(gm->memlock) - return (total); - } + UNLOCK(gm->memlock) + return (total); + } @@ -846,25 +847,25 @@ UINT GlobalMemAvl() */ UINT GlobalMemMax() - { - UINT max; - NODE huge *curr; + { + UINT max; + NODE huge *curr; - LOCK(gm->memlock) - max = 0; - curr = gm->freelist; + LOCK(gm->memlock) + max = 0; + curr = gm->freelist; - while (curr) - { - max = (curr->size > max ? curr->size : max); - curr = curr->next; - } + while (curr) + { + max = (curr->size > max ? curr->size : max); + curr = curr->next; + } - max = ROUND_DN(max); + max = ROUND_DN(max); - UNLOCK(gm->memlock) - return (max); - } + UNLOCK(gm->memlock) + return (max); + } @@ -889,86 +890,86 @@ UINT GlobalMemMax() */ VOID *ObjectMalloc(INT ObjectType, INT count) - { - INT n; - VOID *p; + { + INT n; + VOID *p; - switch (ObjectType) - { - case OT_GRID: - n = count*sizeof(GRID); - p = GlobalMalloc(n, "GRID"); + switch (ObjectType) + { + case OT_GRID: + n = count*sizeof(GRID); + p = GlobalMalloc(n, "GRID"); - mem_grid += n; - maxmem_grid = Max(mem_grid, maxmem_grid); - break; + mem_grid += n; + maxmem_grid = Max(mem_grid, maxmem_grid); + break; - case OT_VOXEL: - n = count*sizeof(VOXEL); - p = GlobalMalloc(n, "VOXEL"); + case OT_VOXEL: + n = count*sizeof(VOXEL); + p = GlobalMalloc(n, "VOXEL"); - mem_voxel += n; - maxmem_voxel = Max(mem_voxel, maxmem_voxel); - break; + mem_voxel += n; + maxmem_voxel = Max(mem_voxel, maxmem_voxel); + break; - case OT_HASHTABLE: - { - INT i; - VOXEL **x; + case OT_HASHTABLE: + { + INT i; + VOXEL **x; - n = count*sizeof(VOXEL *); - p = GlobalMalloc(n, "HASHTABLE"); - x = p; + n = count*sizeof(VOXEL *); + p = GlobalMalloc(n, "HASHTABLE"); + x = p; - for (i = 0; i < count; i++) - x[i] = NULL; + for (i = 0; i < count; i++) + x[i] = NULL; - mem_hashtable += n; - maxmem_hashtable = Max(mem_hashtable, maxmem_hashtable); - } - break; + mem_hashtable += n; + maxmem_hashtable = Max(mem_hashtable, maxmem_hashtable); + } + break; - case OT_EMPTYCELLS: - { - INT i, w; - UINT *x; + case OT_EMPTYCELLS: + { + INT i, w; + UINT *x; - w = 1 + count/(8*sizeof(UINT)); - n = w*sizeof(UINT); - p = GlobalMalloc(n, "EMPTYCELLS"); - x = p; + w = 1 + count/(8*sizeof(UINT)); + n = w*sizeof(UINT); + p = GlobalMalloc(n, "EMPTYCELLS"); + x = p; - for (i = 0; i < w; i++) - x[i] = ~0; /* 1 => empty */ + for (i = 0; i < w; i++) + x[i] = ~0; /* 1 => empty */ - mem_emptycells += n; - maxmem_emptycells = Max(mem_emptycells, maxmem_emptycells); - } - break; + mem_emptycells += n; + maxmem_emptycells = Max(mem_emptycells, maxmem_emptycells); + } + break; - case OT_BINTREE: - n = count*sizeof(BTNODE); - p = GlobalMalloc(n, "BINTREE"); + case OT_BINTREE: + n = count*sizeof(BTNODE); + p = GlobalMalloc(n, "BINTREE"); - mem_bintree += n; - maxmem_bintree = Max(mem_bintree, maxmem_bintree); - break; + mem_bintree += n; + maxmem_bintree = Max(mem_bintree, maxmem_bintree); + break; - case OT_PEPARRAY: - n = count*sizeof(ELEMENT *); - p = GlobalMalloc(n, "PEPARRAY"); + case OT_PEPARRAY: + n = count*sizeof(ELEMENT *); + p = GlobalMalloc(n, "PEPARRAY"); - mem_pepArray += n; - maxmem_pepArray = Max(mem_pepArray, maxmem_pepArray); - break; + mem_pepArray += n; + maxmem_pepArray = Max(mem_pepArray, maxmem_pepArray); + break; - default: - printf("ObjectMalloc: Unknown object type: %ld\n", ObjectType); - exit(-1); - } + default: + printf("ObjectMalloc: Unknown object type: %ld\n", ObjectType); + exit(-1); + } - return (p); - } + return (p); + } @@ -991,113 +992,113 @@ VOID *ObjectMalloc(INT ObjectType, INT count) */ VOID ObjectFree(INT ObjectType, INT count, VOID *p) - { - INT n; + { + INT n; - GlobalFree(p); + GlobalFree(p); - switch (ObjectType) - { - case OT_GRID: - n = count*sizeof(GRID); - mem_grid -= n; - break; + switch (ObjectType) + { + case OT_GRID: + n = count*sizeof(GRID); + mem_grid -= n; + break; - case OT_VOXEL: - n = count*sizeof(VOXEL); - mem_voxel -= n; - break; + case OT_VOXEL: + n = count*sizeof(VOXEL); + mem_voxel -= n; + break; - case OT_HASHTABLE: - n = count*sizeof(VOXEL *); - mem_hashtable -= n; - break; + case OT_HASHTABLE: + n = count*sizeof(VOXEL *); + mem_hashtable -= n; + break; - case OT_EMPTYCELLS: - n = 1 + count/(8*sizeof(UINT)); - n = n*sizeof(UINT); - mem_emptycells -= n; - break; + case OT_EMPTYCELLS: + n = 1 + count/(8*sizeof(UINT)); + n = n*sizeof(UINT); + mem_emptycells -= n; + break; - case OT_BINTREE: - n = count*sizeof(BTNODE); - mem_bintree -= n; - break; + case OT_BINTREE: + n = count*sizeof(BTNODE); + mem_bintree -= n; + break; - case OT_PEPARRAY: - n = count*sizeof(ELEMENT *); - mem_pepArray -= n; - break; + case OT_PEPARRAY: + n = count*sizeof(ELEMENT *); + mem_pepArray -= n; + break; - default: - printf("ObjectFree: Unknown object type: %ld\n", ObjectType); - exit(-1); - } - } + default: + printf("ObjectFree: Unknown object type: %ld\n", ObjectType); + exit(-1); + } + } RAYINFO *ma_rayinfo(RAY *r) - { - RAYINFO *p; + { + RAYINFO *p; - if (r->ri_indx + 1 > MAX_RAYINFO + 1) - { - fprintf(stderr, "error ma_rayinfo \n"); - exit(-1); - } + if (r->ri_indx + 1 > MAX_RAYINFO + 1) + { + fprintf(stderr, "error ma_rayinfo \n"); + exit(-1); + } - p = (RAYINFO *)(&(r->rinfo[r->ri_indx])); + p = (RAYINFO *)(&(r->rinfo[r->ri_indx])); - /* - * It is assumed that rayinfos are allocated and released in a - * stack fashion, i.e. the one released is the one most recently - * allocated. - */ + /* + * It is assumed that rayinfos are allocated and released in a + * stack fashion, i.e. the one released is the one most recently + * allocated. + */ - r->ri_indx += 1; + r->ri_indx += 1; - return (p); - } + return (p); + } VOID free_rayinfo(RAY *r) - { - r->ri_indx -= 1; - } + { + r->ri_indx -= 1; + } VOID reset_rayinfo(RAY *r) - { - r->ri_indx = 0; - } + { + r->ri_indx = 0; + } VOID ma_print() - { - INT mem_total; - INT maxmem_total; + { + INT mem_total; + INT maxmem_total; - mem_total = mem_grid + mem_hashtable + mem_emptycells; - mem_total += mem_voxel + mem_bintree; + mem_total = mem_grid + mem_hashtable + mem_emptycells; + mem_total += mem_voxel + mem_bintree; - maxmem_total = maxmem_grid + maxmem_hashtable + maxmem_emptycells; - maxmem_total += maxmem_voxel + maxmem_bintree; + maxmem_total = maxmem_grid + maxmem_hashtable + maxmem_emptycells; + maxmem_total += maxmem_voxel + maxmem_bintree; - fprintf(stdout, "\n****** Hierarchial uniform grid memory allocation summary ******* \n\n"); - fprintf(stdout, " < struct >: < current > < maximum > < sizeof > \n"); - fprintf(stdout, " < bytes >: < bytes > < bytes > < bytes > \n\n"); - fprintf(stdout, " grid: %11ld %11ld %11ld \n", mem_grid, maxmem_grid, sizeof(GRID) ); - fprintf(stdout, " hashtable entries: %11ld %11ld %11ld \n", mem_hashtable, maxmem_hashtable, sizeof(VOXEL**)); - fprintf(stdout, " emptycell entries: %11ld %11ld %11ld \n", mem_emptycells, maxmem_emptycells, sizeof(UINT) ); - fprintf(stdout, " voxel: %11ld %11ld %11ld \n", mem_voxel, maxmem_voxel, sizeof(VOXEL) ); - fprintf(stdout, " bintree_node: %11ld %11ld %11ld \n", mem_bintree, maxmem_bintree, sizeof(BTNODE) ); + fprintf(stdout, "\n****** Hierarchial uniform grid memory allocation summary ******* \n\n"); + fprintf(stdout, " < struct >: < current > < maximum > < sizeof > \n"); + fprintf(stdout, " < bytes >: < bytes > < bytes > < bytes > \n\n"); + fprintf(stdout, " grid: %11ld %11ld %11ld \n", mem_grid, maxmem_grid, sizeof(GRID) ); + fprintf(stdout, " hashtable entries: %11ld %11ld %11ld \n", mem_hashtable, maxmem_hashtable, sizeof(VOXEL**)); + fprintf(stdout, " emptycell entries: %11ld %11ld %11ld \n", mem_emptycells, maxmem_emptycells, sizeof(UINT) ); + fprintf(stdout, " voxel: %11ld %11ld %11ld \n", mem_voxel, maxmem_voxel, sizeof(VOXEL) ); + fprintf(stdout, " bintree_node: %11ld %11ld %11ld \n", mem_bintree, maxmem_bintree, sizeof(BTNODE) ); - fprintf(stdout, "\n"); - fprintf(stdout, " Totals: %11ld %11ld \n\n", mem_total, maxmem_total); - } + fprintf(stdout, "\n"); + fprintf(stdout, " Totals: %11ld %11ld \n\n", mem_total, maxmem_total); + } diff --git a/splash2/codes/apps/raytrace/poly.C b/splash2/codes/apps/raytrace/poly.C index 0d794c7e1..936305296 100644 --- a/splash2/codes/apps/raytrace/poly.C +++ b/splash2/codes/apps/raytrace/poly.C @@ -25,11 +25,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + /* * NAME * PolyName - return the object name @@ -42,9 +43,9 @@ */ CHAR *PolyName() - { - return ("poly"); - } + { + return ("poly"); + } @@ -61,35 +62,35 @@ CHAR *PolyName() */ VOID PolyPrint(OBJECT *po) - { - INT i, j; - INT *vindex; /* Ptr to vertex index. */ - VEC3 *vlist, *vptr; /* Ptr to vertex list. */ - POLY *pp; /* Ptr to polygon data. */ - ELEMENT *pe; /* Ptr to polygon element. */ + { + INT i, j; + INT *vindex; /* Ptr to vertex index. */ + VEC3 *vlist, *vptr; /* Ptr to vertex list. */ + POLY *pp; /* Ptr to polygon data. */ + ELEMENT *pe; /* Ptr to polygon element. */ - pe = po->pelem; - fprintf(stderr, "\tpolygon: %ld polygons.\n", po->numelements); + pe = po->pelem; + fprintf(stderr, "\tpolygon: %ld polygons.\n", po->numelements); - for (i = 0; i < po->numelements; i++) - { - pp = (POLY *)pe->data; + for (i = 0; i < po->numelements; i++) + { + pp = (POLY *)pe->data; - fprintf(stderr, "\t\tVertices: %ld Plane eq: %f %f %f %f\n", pp->nverts, pp->norm[0], pp->norm[1], pp->norm[2], pp->d); + fprintf(stderr, "\t\tVertices: %ld Plane eq: %f %f %f %f\n", pp->nverts, pp->norm[0], pp->norm[1], pp->norm[2], pp->d); - vlist = pp->vptr; - vindex = pp->vindex; + vlist = pp->vptr; + vindex = pp->vindex; - for (j = 0; j < pp->nverts; j++) - { - vptr = vlist + (*vindex); - fprintf(stderr, "\t\t%f %f %f \n", (*vptr)[0], (*vptr)[1], (*vptr)[2]); - vindex++; - } + for (j = 0; j < pp->nverts; j++) + { + vptr = vlist + (*vindex); + fprintf(stderr, "\t\t%f %f %f \n", (*vptr)[0], (*vptr)[1], (*vptr)[2]); + vindex++; + } - pe++; - } - } + pe++; + } + } @@ -107,46 +108,46 @@ VOID PolyPrint(OBJECT *po) */ VOID PolyElementBoundBox(ELEMENT *pe, POLY *pp) - { - INT i; /* Index. */ - INT *vindex; /* Vertex index pointer. */ - BBOX *pbb; /* Ptr to bounding box. */ - VEC3 *vlist, *vptr; /* Vertex list pointer. */ - REAL minx, maxx; - REAL miny, maxy; - REAL minz, maxz; + { + INT i; /* Index. */ + INT *vindex; /* Vertex index pointer. */ + BBOX *pbb; /* Ptr to bounding box. */ + VEC3 *vlist, *vptr; /* Vertex list pointer. */ + REAL minx, maxx; + REAL miny, maxy; + REAL minz, maxz; - pbb = &(pe->bv); + pbb = &(pe->bv); - minx = miny = minz = HUGE_REAL; - maxx = maxy = maxz = -HUGE_REAL; + minx = miny = minz = HUGE_REAL; + maxx = maxy = maxz = -HUGE_REAL; - vlist = pp->vptr; - vindex = pp->vindex; + vlist = pp->vptr; + vindex = pp->vindex; - for (i = 0; i < pp->nverts; i++) - { - vptr = vlist + (*vindex); + for (i = 0; i < pp->nverts; i++) + { + vptr = vlist + (*vindex); - minx = Min(minx, (*vptr)[0]); - miny = Min(miny, (*vptr)[1]); - minz = Min(minz, (*vptr)[2]); + minx = Min(minx, (*vptr)[0]); + miny = Min(miny, (*vptr)[1]); + minz = Min(minz, (*vptr)[2]); - maxx = Max(maxx, (*vptr)[0]); - maxy = Max(maxy, (*vptr)[1]); - maxz = Max(maxz, (*vptr)[2]); + maxx = Max(maxx, (*vptr)[0]); + maxy = Max(maxy, (*vptr)[1]); + maxz = Max(maxz, (*vptr)[2]); - vindex++; - } + vindex++; + } - pbb->dnear[0] = minx; - pbb->dnear[1] = miny; - pbb->dnear[2] = minz; + pbb->dnear[0] = minx; + pbb->dnear[1] = miny; + pbb->dnear[2] = minz; - pbb->dfar[0] = maxx; - pbb->dfar[1] = maxy; - pbb->dfar[2] = maxz; - } + pbb->dfar[0] = maxx; + pbb->dfar[1] = maxy; + pbb->dfar[2] = maxz; + } @@ -163,45 +164,45 @@ VOID PolyElementBoundBox(ELEMENT *pe, POLY *pp) */ VOID PolyBoundBox(OBJECT *po) - { - INT i; - POLY *pp; /* Ptr to polygon data. */ - ELEMENT *pe; /* Ptr to polygon element. */ - BBOX *pbb; /* Ptr to bounding box. */ - REAL minx, maxx; - REAL miny, maxy; - REAL minz, maxz; + { + INT i; + POLY *pp; /* Ptr to polygon data. */ + ELEMENT *pe; /* Ptr to polygon element. */ + BBOX *pbb; /* Ptr to bounding box. */ + REAL minx, maxx; + REAL miny, maxy; + REAL minz, maxz; - pe = po->pelem; - pbb = &(po->bv); + pe = po->pelem; + pbb = &(po->bv); - minx = miny = minz = HUGE_REAL; - maxx = maxy = maxz = -HUGE_REAL; + minx = miny = minz = HUGE_REAL; + maxx = maxy = maxz = -HUGE_REAL; - for (i = 0; i < po->numelements; i++) - { - pp = (POLY *)pe->data; - PolyElementBoundBox(pe, pp); + for (i = 0; i < po->numelements; i++) + { + pp = (POLY *)pe->data; + PolyElementBoundBox(pe, pp); - minx = Min(minx, pe->bv.dnear[0]); - miny = Min(miny, pe->bv.dnear[1]); - minz = Min(minz, pe->bv.dnear[2]); + minx = Min(minx, pe->bv.dnear[0]); + miny = Min(miny, pe->bv.dnear[1]); + minz = Min(minz, pe->bv.dnear[2]); - maxx = Max(maxx, pe->bv.dfar[0]); - maxy = Max(maxy, pe->bv.dfar[1]); - maxz = Max(maxz, pe->bv.dfar[2]); + maxx = Max(maxx, pe->bv.dfar[0]); + maxy = Max(maxy, pe->bv.dfar[1]); + maxz = Max(maxz, pe->bv.dfar[2]); - pe++; - } + pe++; + } - pbb->dnear[0] = minx; - pbb->dnear[1] = miny; - pbb->dnear[2] = minz; + pbb->dnear[0] = minx; + pbb->dnear[1] = miny; + pbb->dnear[2] = minz; - pbb->dfar[0] = maxx; - pbb->dfar[1] = maxy; - pbb->dfar[2] = maxz; - } + pbb->dfar[0] = maxx; + pbb->dfar[1] = maxy; + pbb->dfar[2] = maxz; + } @@ -224,16 +225,16 @@ VOID PolyBoundBox(OBJECT *po) */ VOID PolyNormal(IRECORD *hit, POINT Pi, POINT Ni) - { - ELEMENT *pe; - POLY *pp; + { + ELEMENT *pe; + POLY *pp; - /* Retrieve normal from hit polygon. */ + /* Retrieve normal from hit polygon. */ - pe = hit->pelem; - pp = (POLY *)pe->data; - VecCopy(Ni, pp->norm); - } + pe = hit->pelem; + pp = (POLY *)pe->data; + VecCopy(Ni, pp->norm); + } @@ -251,65 +252,65 @@ VOID PolyNormal(IRECORD *hit, POINT Pi, POINT Ni) */ VOID PolyDataNormalize(OBJECT *po, MATRIX normMat) - { - INT i; - POINT coord; - VEC3 *pv; /* Ptr to vertex list. */ - POLY *pp; /* Ptr to polygon data. */ - ELEMENT *pe; /* Ptr to polygon element. */ + { + INT i; + POINT coord; + VEC3 *pv; /* Ptr to vertex list. */ + POLY *pp; /* Ptr to polygon data. */ + ELEMENT *pe; /* Ptr to polygon element. */ - /* Normalize bounding box. */ + /* Normalize bounding box. */ - pe = po->pelem; - NormalizeBoundBox(&po->bv, normMat); + pe = po->pelem; + NormalizeBoundBox(&po->bv, normMat); - /* Normalize vertex list. */ + /* Normalize vertex list. */ - pp = (POLY *)pe->data; - pv = pp->vptr; + pp = (POLY *)pe->data; + pv = pp->vptr; - coord[0] = (*pv)[0]; - coord[1] = (*pv)[1]; - coord[2] = (*pv)[2]; - coord[3] = 1.0; + coord[0] = (*pv)[0]; + coord[1] = (*pv)[1]; + coord[2] = (*pv)[2]; + coord[3] = 1.0; - /* Transform coordinate by xform matrix. */ + /* Transform coordinate by xform matrix. */ - while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL) - { - VecMatMult(coord, normMat, coord); + while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL) + { + VecMatMult(coord, normMat, coord); - (*pv)[0] = coord[0]; - (*pv)[1] = coord[1]; - (*pv)[2] = coord[2]; + (*pv)[0] = coord[0]; + (*pv)[1] = coord[1]; + (*pv)[2] = coord[2]; - pv++; + pv++; - coord[0] = (*pv)[0]; - coord[1] = (*pv)[1]; - coord[2] = (*pv)[2]; - coord[3] = 1.0; - } + coord[0] = (*pv)[0]; + coord[1] = (*pv)[1]; + coord[2] = (*pv)[2]; + coord[3] = 1.0; + } - /* Normalize bounding boxes of object elements. */ + /* Normalize bounding boxes of object elements. */ - for (i = 0; i < po->numelements; i++) - { - pp = (POLY *)pe->data; - NormalizeBoundBox(&pe->bv, normMat); + for (i = 0; i < po->numelements; i++) + { + pp = (POLY *)pe->data; + NormalizeBoundBox(&pe->bv, normMat); - /* Find new d of plane equation. */ + /* Find new d of plane equation. */ - pv = pp->vptr + (*(pp->vindex)); - pp->d = -(pp->norm[0]*(*pv)[0] + pp->norm[1]*(*pv)[1] + pp->norm[2]*(*pv)[2]); + pv = pp->vptr + (*(pp->vindex)); + pp->d = -(pp->norm[0]*(*pv)[0] + pp->norm[1]*(*pv)[1] + pp->norm[2]*(*pv)[2]); - pe++; - } - } + pe++; + } + } @@ -338,151 +339,151 @@ VOID PolyDataNormalize(OBJECT *po, MATRIX normMat) */ INT PolyPeIntersect(RAY *pr, ELEMENT *pe, IRECORD *hit) - { - INT i; - INT *vindex; /* Vertex index pointer. */ - INT toright; /* Counter. */ - INT sh, nsh; /* Sign holders. */ - REAL Rd_dot_Pn; /* Polygon normal dot ray direction. */ - REAL Ro_dot_Pn; /* Polygon normal dot ray origin. */ - REAL tval; /* Intersection t distance value. */ - REAL x[MAX_VERTS + 1]; /* Projection list. */ - REAL y[MAX_VERTS + 1]; /* Projection list. */ - REAL ix, iy; /* Intersection projection point. */ - REAL dx, dy; /* Deltas between 2 vertices. */ - REAL xint; /* Intersection value. */ - VEC3 I; /* Intersection point. */ - VEC3 *vlist, *vpos; /* Vertex list pointer. */ - POLY *pp; /* Ptr to polygon data. */ + { + INT i; + INT *vindex; /* Vertex index pointer. */ + INT toright; /* Counter. */ + INT sh, nsh; /* Sign holders. */ + REAL Rd_dot_Pn; /* Polygon normal dot ray direction. */ + REAL Ro_dot_Pn; /* Polygon normal dot ray origin. */ + REAL tval; /* Intersection t distance value. */ + REAL x[MAX_VERTS + 1]; /* Projection list. */ + REAL y[MAX_VERTS + 1]; /* Projection list. */ + REAL ix, iy; /* Intersection projection point. */ + REAL dx, dy; /* Deltas between 2 vertices. */ + REAL xint; /* Intersection value. */ + VEC3 I; /* Intersection point. */ + VEC3 *vlist, *vpos; /* Vertex list pointer. */ + POLY *pp; /* Ptr to polygon data. */ - pp = (POLY *)pe->data; + pp = (POLY *)pe->data; - Rd_dot_Pn = VecDot(pp->norm, pr->D); + Rd_dot_Pn = VecDot(pp->norm, pr->D); - if (ABS(Rd_dot_Pn) < RAYEPS) /* Ray is parallel. */ - return (0); + if (ABS(Rd_dot_Pn) < RAYEPS) /* Ray is parallel. */ + return (0); - Ro_dot_Pn = VecDot(pp->norm, pr->P); + Ro_dot_Pn = VecDot(pp->norm, pr->P); - tval = -(pp->d + Ro_dot_Pn)/Rd_dot_Pn; /* Intersection distance. */ - if (tval < RAYEPS) /* Intersects behind ray. */ - return (0); + tval = -(pp->d + Ro_dot_Pn)/Rd_dot_Pn; /* Intersection distance. */ + if (tval < RAYEPS) /* Intersects behind ray. */ + return (0); - RayPoint(I, pr, tval); + RayPoint(I, pr, tval); - /* Polygon containment. */ + /* Polygon containment. */ - /* Project onto plane with greatest normal component. */ + /* Project onto plane with greatest normal component. */ - vlist = pp->vptr; - vindex = pp->vindex; + vlist = pp->vptr; + vindex = pp->vindex; - switch (pp->axis_proj) - { - case X_AXIS: - for (i = 0; i < pp->nverts; i++) - { - vpos = vlist + (*vindex); - x[i] = (*vpos)[1]; - y[i] = (*vpos)[2]; - vindex++; - } + switch (pp->axis_proj) + { + case X_AXIS: + for (i = 0; i < pp->nverts; i++) + { + vpos = vlist + (*vindex); + x[i] = (*vpos)[1]; + y[i] = (*vpos)[2]; + vindex++; + } - ix = I[1]; - iy = I[2]; - break; + ix = I[1]; + iy = I[2]; + break; - case Y_AXIS: - for (i = 0; i < pp->nverts; i++) - { - vpos = vlist + (*vindex); - x[i] = (*vpos)[0]; - y[i] = (*vpos)[2]; - vindex++; - } + case Y_AXIS: + for (i = 0; i < pp->nverts; i++) + { + vpos = vlist + (*vindex); + x[i] = (*vpos)[0]; + y[i] = (*vpos)[2]; + vindex++; + } - ix = I[0]; - iy = I[2]; - break; + ix = I[0]; + iy = I[2]; + break; - case Z_AXIS: - for (i = 0; i < pp->nverts; i++) - { - vpos = vlist + (*vindex); - x[i] = (*vpos)[0]; - y[i] = (*vpos)[1]; - vindex++; - } + case Z_AXIS: + for (i = 0; i < pp->nverts; i++) + { + vpos = vlist + (*vindex); + x[i] = (*vpos)[0]; + y[i] = (*vpos)[1]; + vindex++; + } - ix = I[0]; - iy = I[1]; - break; - } + ix = I[0]; + iy = I[1]; + break; + } - /* Translate to origin. */ + /* Translate to origin. */ - for (i = 0; i < pp->nverts; i++) - { - x[i] -= ix; - y[i] -= iy; + for (i = 0; i < pp->nverts; i++) + { + x[i] -= ix; + y[i] -= iy; - if (ABS(y[i]) < RAYEPS) - y[i] = 0.0; - } + if (ABS(y[i]) < RAYEPS) + y[i] = 0.0; + } - x[pp->nverts] = x[0]; - y[pp->nverts] = y[0]; + x[pp->nverts] = x[0]; + y[pp->nverts] = y[0]; - /* - * If intersection point crosses an odd number of line segments, - * the point is inside the polygon - */ + /* + * If intersection point crosses an odd number of line segments, + * the point is inside the polygon + */ - if (y[0] < 0.0) - sh = 0; - else - sh = 1; + if (y[0] < 0.0) + sh = 0; + else + sh = 1; - toright = 0; + toright = 0; - for (i = 0; i < pp->nverts; i++) - { - /* Check if segment crosses in y. */ + for (i = 0; i < pp->nverts; i++) + { + /* Check if segment crosses in y. */ - if (y[i + 1] < 0.0) - nsh = 0; - else - nsh = 1; + if (y[i + 1] < 0.0) + nsh = 0; + else + nsh = 1; - if (nsh ^ sh) - { - dy = y[i + 1] - y[i]; + if (nsh ^ sh) + { + dy = y[i + 1] - y[i]; - if (ABS(dy) >= RAYEPS) - { - dx = x[i + 1] - x[i]; - xint = x[i] - y[i]*dx / dy; + if (ABS(dy) >= RAYEPS) + { + dx = x[i + 1] - x[i]; + xint = x[i] - y[i]*dx / dy; - if (xint > 0.0) - toright++; - } - } + if (xint > 0.0) + toright++; + } + } - sh = nsh; - } + sh = nsh; + } - if (toright%2 == 1) - { - IsectAdd(hit, tval, pe); - return (1); - } - else - return (0); - } + if (toright%2 == 1) + { + IsectAdd(hit, tval, pe); + return (1); + } + else + return (0); + } @@ -501,35 +502,35 @@ INT PolyPeIntersect(RAY *pr, ELEMENT *pe, IRECORD *hit) */ INT PolyIntersect(RAY *pr, OBJECT *po, IRECORD *hit) - { - INT i; - INT nhits; /* # hits in polyhedra. */ - ELEMENT *pe; /* Ptr to polygon element. */ - IRECORD newhit; /* Hit list. */ + { + INT i; + INT nhits; /* # hits in polyhedra. */ + ELEMENT *pe; /* Ptr to polygon element. */ + IRECORD newhit; /* Hit list. */ - /* Traverse polygon list to find intersections. */ + /* Traverse polygon list to find intersections. */ - nhits = 0; - pe = po->pelem; - hit[0].t = HUGE_REAL; + nhits = 0; + pe = po->pelem; + hit[0].t = HUGE_REAL; - for (i = 0; i < po->numelements; i++) - { - if (PolyPeIntersect(pr, pe, &newhit)) - { - nhits++; - if (newhit.t < hit[0].t) - { - hit[0].t = newhit.t; - hit[0].pelem = newhit.pelem; - } - } + for (i = 0; i < po->numelements; i++) + { + if (PolyPeIntersect(pr, pe, &newhit)) + { + nhits++; + if (newhit.t < hit[0].t) + { + hit[0].t = newhit.t; + hit[0].pelem = newhit.pelem; + } + } - pe++; - } + pe++; + } - return (nhits); - } + return (nhits); + } @@ -554,91 +555,91 @@ INT PolyIntersect(RAY *pr, OBJECT *po, IRECORD *hit) */ VOID PolyTransform(OBJECT *po, MATRIX xtrans, MATRIX xinvT) - { - INT i; /* Indices. */ - INT numelems; /* # of elements. */ - VEC3 *vptr, *vp; /* Vertex list pointers. */ - VEC4 norm, coord; /* Transform 4 vectors. */ - POLY *pp; /* Ptr to polygon data. */ - ELEMENT *pe; /* Ptr to polygon element. */ + { + INT i; /* Indices. */ + INT numelems; /* # of elements. */ + VEC3 *vptr, *vp; /* Vertex list pointers. */ + VEC4 norm, coord; /* Transform 4 vectors. */ + POLY *pp; /* Ptr to polygon data. */ + ELEMENT *pe; /* Ptr to polygon element. */ - pe = po->pelem; - numelems = po->numelements; + pe = po->pelem; + numelems = po->numelements; - /* Get vertex list address and transform vertices. */ + /* Get vertex list address and transform vertices. */ - pp = (POLY *)pe->data; - vptr = pp->vptr; + pp = (POLY *)pe->data; + vptr = pp->vptr; - coord[0] = (*vptr)[0]; - coord[1] = (*vptr)[1]; - coord[2] = (*vptr)[2]; - coord[3] = 1.0; + coord[0] = (*vptr)[0]; + coord[1] = (*vptr)[1]; + coord[2] = (*vptr)[2]; + coord[3] = 1.0; - while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL) - { - /* Transform coordinate by xform matrix. */ + while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL) + { + /* Transform coordinate by xform matrix. */ - VecMatMult(coord, xtrans, coord); + VecMatMult(coord, xtrans, coord); - (*vptr)[0] = coord[0]; - (*vptr)[1] = coord[1]; - (*vptr)[2] = coord[2]; + (*vptr)[0] = coord[0]; + (*vptr)[1] = coord[1]; + (*vptr)[2] = coord[2]; - vptr++; + vptr++; - coord[0] = (*vptr)[0]; - coord[1] = (*vptr)[1]; - coord[2] = (*vptr)[2]; - coord[3] = 1.0; - } + coord[0] = (*vptr)[0]; + coord[1] = (*vptr)[1]; + coord[2] = (*vptr)[2]; + coord[3] = 1.0; + } - /* Transform polygon list. */ + /* Transform polygon list. */ - for (i = 0; i < numelems; i++) - { - pp = (POLY *)pe->data; + for (i = 0; i < numelems; i++) + { + pp = (POLY *)pe->data; - /* Transform face normal by view matrix inverse. */ + /* Transform face normal by view matrix inverse. */ - norm[0] = pp->norm[0]; - norm[1] = pp->norm[1]; - norm[2] = pp->norm[2]; - norm[3] = 0.0; + norm[0] = pp->norm[0]; + norm[1] = pp->norm[1]; + norm[2] = pp->norm[2]; + norm[3] = 0.0; - VecMatMult(norm, xinvT, norm); - VecNorm(norm); + VecMatMult(norm, xinvT, norm); + VecNorm(norm); - pp->norm[0] = norm[0]; - pp->norm[1] = norm[1]; - pp->norm[2] = norm[2]; + pp->norm[0] = norm[0]; + pp->norm[1] = norm[1]; + pp->norm[2] = norm[2]; - /* Calculate plane equation variable d. */ + /* Calculate plane equation variable d. */ - vp = pp->vptr + *(pp->vindex); - pp->d = -(pp->norm[0]*(*vp)[0] + pp->norm[1]*(*vp)[1] + pp->norm[2]*(*vp)[2]); + vp = pp->vptr + *(pp->vindex); + pp->d = -(pp->norm[0]*(*vp)[0] + pp->norm[1]*(*vp)[1] + pp->norm[2]*(*vp)[2]); - /* Set best axis projection. */ + /* Set best axis projection. */ - norm[0] = ABS(pp->norm[0]); - norm[1] = ABS(pp->norm[1]); - norm[2] = ABS(pp->norm[2]); + norm[0] = ABS(pp->norm[0]); + norm[1] = ABS(pp->norm[1]); + norm[2] = ABS(pp->norm[2]); - if (norm[0] >= norm[1] && norm[0] >= norm[2]) - pp->axis_proj = X_AXIS; - else - if (norm[1] >= norm[0] && norm[1] >= norm[2]) - pp->axis_proj = Y_AXIS; - else - pp->axis_proj = Z_AXIS; + if (norm[0] >= norm[1] && norm[0] >= norm[2]) + pp->axis_proj = X_AXIS; + else + if (norm[1] >= norm[0] && norm[1] >= norm[2]) + pp->axis_proj = Y_AXIS; + else + pp->axis_proj = Z_AXIS; - pe++; - } - } + pe++; + } + } @@ -656,172 +657,172 @@ VOID PolyTransform(OBJECT *po, MATRIX xtrans, MATRIX xinvT) */ VOID PolyRead(OBJECT *po, FILE *pf) - { - INT i, j; /* Indices. */ - INT instat; /* Read status. */ - INT *vindex; - INT totalverts; /* Total # of vertices in poly mesh. */ - CHAR normstr[5]; /* Face/vertex normal flag string. */ - BOOL pnormals; /* Face normals present? */ - VEC3 pnorm; /* Polygon normal accumulator. */ - VEC3 *vlist, *vptr, *vp; /* Ptr to vertex list. */ - VEC3 *vptmp, *vptmp2; /* Ptr to vertex list. */ - VEC3 tmppnt, tmppnt2, cross; - POLY *pp; /* Ptr to polygon data. */ - ELEMENT *pe; /* Ptr to polygon element. */ + { + INT i, j; /* Indices. */ + INT instat; /* Read status. */ + INT *vindex; + INT totalverts; /* Total # of vertices in poly mesh. */ + CHAR normstr[5]; /* Face/vertex normal flag string. */ + BOOL pnormals; /* Face normals present? */ + VEC3 pnorm; /* Polygon normal accumulator. */ + VEC3 *vlist, *vptr, *vp; /* Ptr to vertex list. */ + VEC3 *vptmp, *vptmp2; /* Ptr to vertex list. */ + VEC3 tmppnt, tmppnt2, cross; + POLY *pp; /* Ptr to polygon data. */ + ELEMENT *pe; /* Ptr to polygon element. */ - pe = po->pelem; + pe = po->pelem; - /* Allocate space for object data. */ + /* Allocate space for object data. */ - instat = fscanf(pf, "%ld", &totalverts); + instat = fscanf(pf, "%ld", &totalverts); - if (instat != 1) - { - printf("Error in PolyRead: totalverts.\n"); - exit(-1); - } + if (instat != 1) + { + printf("Error in PolyRead: totalverts.\n"); + exit(-1); + } - pp = GlobalMalloc(sizeof(POLY)*po->numelements, "poly.c"); - vlist = GlobalMalloc(sizeof(VEC3)*(totalverts + 1), "poly.c"); - vptr = vlist; + pp = GlobalMalloc(sizeof(POLY)*po->numelements, "poly.c"); + vlist = GlobalMalloc(sizeof(VEC3)*(totalverts + 1), "poly.c"); + vptr = vlist; - /* Are polygon face normals supplied? */ + /* Are polygon face normals supplied? */ - instat = fscanf(pf, "%s\n", normstr); + instat = fscanf(pf, "%s\n", normstr); - if (instat != 1) - { - printf("Error in PolyRead: face normal indicator.\n"); - exit(-1); - } + if (instat != 1) + { + printf("Error in PolyRead: face normal indicator.\n"); + exit(-1); + } - pnormals = (normstr[2] == 'y' ? TRUE : FALSE); + pnormals = (normstr[2] == 'y' ? TRUE : FALSE); - /* Read vertex list. */ + /* Read vertex list. */ - for (i = 0; i < totalverts; i++) - { - instat = fscanf(pf, "%lf %lf %lf", &(*vptr)[0], &(*vptr)[1], &(*vptr)[2]); + for (i = 0; i < totalverts; i++) + { + instat = fscanf(pf, "%lf %lf %lf", &(*vptr)[0], &(*vptr)[1], &(*vptr)[2]); - if (instat != 3) - { - printf("Error in PolyRead: vertex %ld.\n", i); - exit(-1); - } + if (instat != 3) + { + printf("Error in PolyRead: vertex %ld.\n", i); + exit(-1); + } - vptr++; - } + vptr++; + } - (*vptr)[0] = HUGE_REAL; - (*vptr)[1] = HUGE_REAL; - (*vptr)[2] = HUGE_REAL; + (*vptr)[0] = HUGE_REAL; + (*vptr)[1] = HUGE_REAL; + (*vptr)[2] = HUGE_REAL; - /* Read polygon list. */ + /* Read polygon list. */ - for (i = 0; i < po->numelements; i++) - { - instat = fscanf(pf, "%ld", &(pp->nverts)); + for (i = 0; i < po->numelements; i++) + { + instat = fscanf(pf, "%ld", &(pp->nverts)); - if (instat != 1) - { - printf("Error in PolyRead: vertex count.\n"); - exit(-1); - } + if (instat != 1) + { + printf("Error in PolyRead: vertex count.\n"); + exit(-1); + } - if (pp->nverts > MAX_VERTS) - { - printf("Polygon vertex count, %ld, exceeds maximum.\n", pp->nverts); - exit(-1); - } + if (pp->nverts > MAX_VERTS) + { + printf("Polygon vertex count, %ld, exceeds maximum.\n", pp->nverts); + exit(-1); + } - if (pnormals) - { - instat = fscanf(pf, " %lf %lf %lf", &(pp->norm[0]), &(pp->norm[1]), &(pp->norm[2])); + if (pnormals) + { + instat = fscanf(pf, " %lf %lf %lf", &(pp->norm[0]), &(pp->norm[1]), &(pp->norm[2])); - if (instat != 3) - { - printf("Error in PolyRead: face normal %ld.\n", i); - exit(-1); - } - } + if (instat != 3) + { + printf("Error in PolyRead: face normal %ld.\n", i); + exit(-1); + } + } - pp->vptr = vlist; - pp->vindex = GlobalMalloc(sizeof(INT)*pp->nverts, "poly.c"); - vindex = pp->vindex; + pp->vptr = vlist; + pp->vindex = GlobalMalloc(sizeof(INT)*pp->nverts, "poly.c"); + vindex = pp->vindex; - for (j = 0; j < pp->nverts; j++) - { - instat = fscanf(pf, "%ld", vindex++); + for (j = 0; j < pp->nverts; j++) + { + instat = fscanf(pf, "%ld", vindex++); - if (instat != 1) - { - printf("Error in PolyRead: vertex index %ld.\n", i); - exit(-1); - } - } + if (instat != 1) + { + printf("Error in PolyRead: vertex index %ld.\n", i); + exit(-1); + } + } - /* If not supplied, calculate plane normal. */ + /* If not supplied, calculate plane normal. */ - vindex = pp->vindex; - vptr = vlist; + vindex = pp->vindex; + vptr = vlist; - if (!pnormals) - { - vp = vptr + (*vindex); - VecZero(pnorm); + if (!pnormals) + { + vp = vptr + (*vindex); + VecZero(pnorm); - for (j = 0; j < pp->nverts - 2; j++) - { - vptmp = vptr + (*(vindex + 1)); - vptmp2 = vptr + (*(vindex + 2)); + for (j = 0; j < pp->nverts - 2; j++) + { + vptmp = vptr + (*(vindex + 1)); + vptmp2 = vptr + (*(vindex + 2)); - VecSub(tmppnt, (*vptmp), (*vp)); - VecSub(tmppnt2, (*vptmp2), (*vptmp)); + VecSub(tmppnt, (*vptmp), (*vp)); + VecSub(tmppnt2, (*vptmp2), (*vptmp)); - VecCross(cross, tmppnt, tmppnt2); - VecAdd(pnorm, pnorm, cross); + VecCross(cross, tmppnt, tmppnt2); + VecAdd(pnorm, pnorm, cross); - vp = vptmp; - vindex += 1; - } + vp = vptmp; + vindex += 1; + } - VecSub(tmppnt, (*vptmp2), (*vp)); - vindex = pp->vindex; - vp = vptr + (*vindex); + VecSub(tmppnt, (*vptmp2), (*vp)); + vindex = pp->vindex; + vp = vptr + (*vindex); - VecSub(tmppnt2, (*vp), (*vptmp2)); - VecCross(cross, tmppnt, tmppnt2); - VecAdd(pnorm, pnorm, cross); + VecSub(tmppnt2, (*vp), (*vptmp2)); + VecCross(cross, tmppnt, tmppnt2); + VecAdd(pnorm, pnorm, cross); - vp = vptr + (*vindex); - VecSub(tmppnt, (*vp), (*vptmp2)); - vptmp = vptr + (*(vindex + 1)); + vp = vptr + (*vindex); + VecSub(tmppnt, (*vp), (*vptmp2)); + vptmp = vptr + (*(vindex + 1)); - VecSub(tmppnt2, (*vptmp), (*vp)); - VecCross(cross, tmppnt, tmppnt2); - VecAdd(pnorm, pnorm, cross); - VecScale(pp->norm, 1.0/VecLen(pnorm), pnorm); - } + VecSub(tmppnt2, (*vptmp), (*vp)); + VecCross(cross, tmppnt, tmppnt2); + VecAdd(pnorm, pnorm, cross); + VecScale(pp->norm, 1.0/VecLen(pnorm), pnorm); + } - /* Calculate plane equation d. */ + /* Calculate plane equation d. */ - vp = pp->vptr + *(pp->vindex); - pp->d = -(pp->norm[0]*(*vp)[0] + pp->norm[1]*(*vp)[1] + pp->norm[2]*(*vp)[2]); + vp = pp->vptr + *(pp->vindex); + pp->d = -(pp->norm[0]*(*vp)[0] + pp->norm[1]*(*vp)[1] + pp->norm[2]*(*vp)[2]); - pe->data = (CHAR *)pp; - pe->parent = po; + pe->data = (CHAR *)pp; + pe->parent = po; - PolyElementBoundBox(pe, pp); + PolyElementBoundBox(pe, pp); - pp++; - pe++; - } - } + pp++; + pe++; + } + } diff --git a/splash2/codes/apps/raytrace/raystack.C b/splash2/codes/apps/raytrace/raystack.C index 313d3e177..f8d6ff852 100644 --- a/splash2/codes/apps/raytrace/raystack.C +++ b/splash2/codes/apps/raytrace/raystack.C @@ -35,25 +35,24 @@ */ -#include -#include - +#include +#include #include "rt.h" #define PAGE_SIZE 4096 struct r_struct { INT pad1[PAGE_SIZE]; /* This pad is inserted to avoid - false-sharing due to artifacts - of not having a private space - in the sproc model */ + false-sharing due to artifacts + of not having a private space + in the sproc model */ RAY *Stack; /* Ptr to ray tree stack. */ INT StackTop; /* Top of ray tree stack. */ INT StackSize; /* Maximum size of ray tree stack. */ INT pad2[PAGE_SIZE]; /* This pad is inserted to avoid - false-sharing due to artifacts - of not having a private space - in the sproc model */ + false-sharing due to artifacts + of not having a private space + in the sproc model */ } raystruct[MAX_PROCS]; @@ -72,19 +71,19 @@ INT pad2[PAGE_SIZE]; /* This pad is inserted to avoid */ VOID CopyRayMsg(RAY *rdst, RAY *rsrc) - { - rdst->id = rsrc->id; - rdst->x = rsrc->x; - rdst->y = rsrc->y; + { + rdst->id = rsrc->id; + rdst->x = rsrc->x; + rdst->y = rsrc->y; - VecCopy(rdst->P, rsrc->P); - VecCopy(rdst->D, rsrc->D); + VecCopy(rdst->P, rsrc->P); + VecCopy(rdst->D, rsrc->D); - rdst->level = rsrc->level; - rdst->weight = rsrc->weight; + rdst->level = rsrc->level; + rdst->weight = rsrc->weight; - /* Other fields are initialized with InitRay. */ - } + /* Other fields are initialized with InitRay. */ + } @@ -106,12 +105,12 @@ VOID CopyRayMsg(RAY *rdst, RAY *rsrc) */ VOID InitRayTreeStack(INT TreeDepth, INT pid) - { - raystruct[pid].StackSize = powint(2, TreeDepth) - 1; - raystruct[pid].StackSize += NumSubRays; - raystruct[pid].Stack = LocalMalloc(raystruct[pid].StackSize*sizeof(RAY), "raystack.c"); - raystruct[pid].StackTop = -1; /* Empty condition. */ - } + { + raystruct[pid].StackSize = powint(2, TreeDepth) - 1; + raystruct[pid].StackSize += NumSubRays; + raystruct[pid].Stack = LocalMalloc(raystruct[pid].StackSize*sizeof(RAY), "raystack.c"); + raystruct[pid].StackTop = -1; /* Empty condition. */ + } unsigned long powint(long i, long j) @@ -139,17 +138,17 @@ unsigned long powint(long i, long j) */ VOID PushRayTreeStack(RAY *rmsg, INT pid) - { - raystruct[pid].StackTop++; + { + raystruct[pid].StackTop++; - if (raystruct[pid].StackTop == raystruct[pid].StackSize) - { - fprintf(stderr,"%s: Ray tree stack overflow.\n", ProgName); - exit(-1); - } + if (raystruct[pid].StackTop == raystruct[pid].StackSize) + { + fprintf(stderr,"%s: Ray tree stack overflow.\n", ProgName); + exit(-1); + } - CopyRayMsg(&(raystruct[pid].Stack[raystruct[pid].StackTop]), rmsg); - } + CopyRayMsg(&(raystruct[pid].Stack[raystruct[pid].StackTop]), rmsg); + } @@ -167,13 +166,13 @@ VOID PushRayTreeStack(RAY *rmsg, INT pid) */ INT PopRayTreeStack(RAY *rmsg, INT pid) - { - if (raystruct[pid].StackTop < 0) - return (RTS_EMPTY); + { + if (raystruct[pid].StackTop < 0) + return (RTS_EMPTY); - CopyRayMsg(rmsg, &(raystruct[pid].Stack[raystruct[pid].StackTop])); + CopyRayMsg(rmsg, &(raystruct[pid].Stack[raystruct[pid].StackTop])); - raystruct[pid].StackTop--; - return (RTS_VALID); - } + raystruct[pid].StackTop--; + return (RTS_VALID); + } diff --git a/splash2/codes/apps/raytrace/rltotiff/rltotiff.c b/splash2/codes/apps/raytrace/rltotiff/rltotiff.c index cfabe4794..62e742534 100644 --- a/splash2/codes/apps/raytrace/rltotiff/rltotiff.c +++ b/splash2/codes/apps/raytrace/rltotiff/rltotiff.c @@ -14,12 +14,11 @@ /* */ /*************************************************************************/ -#include -#include -#include -#include - #include "tiff_rgba_io.h" +#include +#include +#include +#include typedef short SHORT; typedef long LONG; @@ -38,66 +37,66 @@ typedef unsigned long ULONG; #define TRUE 1 typedef struct - { - SHORT sFileType; /* Mark what kind of file we have. */ - SHORT sBpp; /* Bits per pixel, 1, 4, 8, 24, 32. */ - SHORT sRows; /* Up to 1024. */ - SHORT sCols; /* Up to 1024. */ - SHORT sVectorType; /* So far, 0 = rectangular blocks. */ - SHORT sVectorSize; /* So far, 16 for 4x4 square blocks. */ - LONG lCntVectors; /* Up to 65536. */ - SHORT sBrows; /* Number of block rows. */ - SHORT sBcols; /* Number of block cols. */ - SHORT sVrows; /* Number of vector rows. */ - SHORT sVcols; /* Number of vector cols. */ - CHAR achReserved[104]; /* Pad variable space to 128 bytes. */ - CHAR achUser[128]; /* User application space. */ - CHAR achComment[256]; /* Rest of 1st block for comments. */ - } - ISPHDR; + { + SHORT sFileType; /* Mark what kind of file we have. */ + SHORT sBpp; /* Bits per pixel, 1, 4, 8, 24, 32. */ + SHORT sRows; /* Up to 1024. */ + SHORT sCols; /* Up to 1024. */ + SHORT sVectorType; /* So far, 0 = rectangular blocks. */ + SHORT sVectorSize; /* So far, 16 for 4x4 square blocks. */ + LONG lCntVectors; /* Up to 65536. */ + SHORT sBrows; /* Number of block rows. */ + SHORT sBcols; /* Number of block cols. */ + SHORT sVrows; /* Number of vector rows. */ + SHORT sVcols; /* Number of vector cols. */ + CHAR achReserved[104]; /* Pad variable space to 128 bytes. */ + CHAR achUser[128]; /* User application space. */ + CHAR achComment[256]; /* Rest of 1st block for comments. */ + } + ISPHDR; typedef struct - { - USHORT usRes1; - USHORT usRes2; - USHORT usRes3; - USHORT usRes4; - USHORT usRes5; - USHORT usRes6; - USHORT usResX; - USHORT usResY; - USHORT usRes7; - } - TGAHDR; + { + USHORT usRes1; + USHORT usRes2; + USHORT usRes3; + USHORT usRes4; + USHORT usRes5; + USHORT usRes6; + USHORT usResX; + USHORT usResY; + USHORT usRes7; + } + TGAHDR; typedef struct - { - BYTE b; - BYTE g; - BYTE r; - } - TGAPIX; + { + BYTE b; + BYTE g; + BYTE r; + } + TGAPIX; typedef struct - { - BYTE r; - BYTE g; - BYTE b; - BYTE count; - } - SPAPIX; + { + BYTE r; + BYTE g; + BYTE b; + BYTE count; + } + SPAPIX; /* USHORT ausBase[] = - { - HST_BASE2, - HST_BASE1, - HST_BASE0 - }; + { + HST_BASE2, + HST_BASE1, + HST_BASE0 + }; */ CHAR *pchProgName = "rltotiff"; /* The program name. */ @@ -148,8 +147,8 @@ int main(int argc, char **argv) char *spachfile, *tiffile; if (argc < 3) { - fprintf(stderr, "spachtotiff \n"); - exit(1); + fprintf(stderr, "spachtotiff \n"); + exit(1); } spachfile = argv[1]; tiffile = argv[2]; @@ -157,8 +156,8 @@ int main(int argc, char **argv) fp = fopen(spachfile, "rb"); if (!fp) { - fprintf(stderr, "spachtotiff: could not open file %s\n", spachfile); - exit(1); + fprintf(stderr, "spachtotiff: could not open file %s\n", spachfile); + exit(1); } ProcessSpachFile(fp, spachfile); @@ -180,10 +179,10 @@ void SetPixel24(INT i, INT j, BYTE r, BYTE g, BYTE b) { if (i+j*gbWidth >= gbWidth*gbHeight) - fprintf(stderr, "Bug!\n"); + fprintf(stderr, "Bug!\n"); gbRGBA[i+(gbHeight-j-1)*gbWidth] = - ((UINT)r)*256*256 + ((UINT)g)*256 + ((UINT)b); + ((UINT)r)*256*256 + ((UINT)g)*256 + ((UINT)b); } @@ -201,63 +200,63 @@ SetPixel24(INT i, INT j, BYTE r, BYTE g, BYTE b) */ VOID ProcessSpachFile(FILE *pf, CHAR *pchFileName) - { - INT i; - INT j; - INT k; - INT count; - UINT ui; - LONG lPixCnt; + { + INT i; + INT j; + INT k; + INT count; + UINT ui; + LONG lPixCnt; - ui = getc(pf); - ui = getc(pf); - ui = getc(pf); - iCntResX = ui*256 + (UINT)getc(pf); + ui = getc(pf); + ui = getc(pf); + ui = getc(pf); + iCntResX = ui*256 + (UINT)getc(pf); - ui = getc(pf); - ui = getc(pf); - ui = getc(pf); - iCntResY = ui*256 + (UINT)getc(pf); + ui = getc(pf); + ui = getc(pf); + ui = getc(pf); + iCntResY = ui*256 + (UINT)getc(pf); - gbWidth = iCntResX; - gbHeight = iCntResY; + gbWidth = iCntResX; + gbHeight = iCntResY; - lPixCnt = (ULONG)iCntResX*(ULONG)iCntResY; + lPixCnt = (ULONG)iCntResX*(ULONG)iCntResY; - configRGBABuf(); + configRGBABuf(); - if (fCenter) - { - iOffsetX = (iCntDcX - iCntResX)/2; - iOffsetY = (iCntDcY - iCntResY)/2; - } + if (fCenter) + { + iOffsetX = (iCntDcX - iCntResX)/2; + iOffsetY = (iCntDcY - iCntResY)/2; + } - for (i = 0, j = 0; lPixCnt > 0; lPixCnt -= count) - { - if (fread(&sp, 1, sizeof(sp), pf) != sizeof(sp)) - { - fprintf(stderr, "%s: Unexpected EOF in file \"%s\".\n", pchProgName, pchFileName); - exit(1); - } + for (i = 0, j = 0; lPixCnt > 0; lPixCnt -= count) + { + if (fread(&sp, 1, sizeof(sp), pf) != sizeof(sp)) + { + fprintf(stderr, "%s: Unexpected EOF in file \"%s\".\n", pchProgName, pchFileName); + exit(1); + } - count = (UINT)sp.count + 1; + count = (UINT)sp.count + 1; - for (k = 0; k < count; k++, i++) - { - if (i >= iCntResX) - { - i = 0; - j++; - } + for (k = 0; k < count; k++, i++) + { + if (i >= iCntResX) + { + i = 0; + j++; + } - if (fDebug) - printf("%ld\t%ld\t0x%02X\t0x%02X\t0x%02X\t0x%02X\n", - i, j, sp.count, sp.r, sp.g, sp.b); + if (fDebug) + printf("%ld\t%ld\t0x%02X\t0x%02X\t0x%02X\t0x%02X\n", + i, j, sp.count, sp.r, sp.g, sp.b); - SetPixel24(i, j, sp.r, sp.g, sp.b); - } - } - } + SetPixel24(i, j, sp.r, sp.g, sp.b); + } + } + } diff --git a/splash2/codes/apps/raytrace/rltotiff/tiff_rgba_io.c b/splash2/codes/apps/raytrace/rltotiff/tiff_rgba_io.c index f62c481ec..eabdf1488 100644 --- a/splash2/codes/apps/raytrace/rltotiff/tiff_rgba_io.c +++ b/splash2/codes/apps/raytrace/rltotiff/tiff_rgba_io.c @@ -25,7 +25,6 @@ static char sccsid[] = "@(#)savemap.c 1.3 2/6/9q"; #include #include #include - #include "tiff_rgba_io.h" #define streq(a,b) (strcmp(a,b) == 0) @@ -55,76 +54,76 @@ static long orientation = ORIENTATION_BOTLEFT; long tiff_save_rgba(char *name, long *pixels, long width, long height) { - TIFF *tif; - long xsize, ysize; - long y; - long *pos; + TIFF *tif; + long xsize, ysize; + long y; + long *pos; - xsize = width; - ysize = height; + xsize = width; + ysize = height; - tif = TIFFOpen(name, "w"); - if (tif == NULL) - return 0; + tif = TIFFOpen(name, "w"); + if (tif == NULL) + return 0; - TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, xsize); - TIFFSetField(tif, TIFFTAG_IMAGELENGTH, ysize); - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); - TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4); - TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); - TIFFSetField(tif, TIFFTAG_PLANARCONFIG, config); - TIFFSetField(tif, TIFFTAG_COMPRESSION, compression); - TIFFSetField(tif, TIFFTAG_ORIENTATION, orientation); - if (rowsperstrip <= 0) - rowsperstrip = (8*1024)/TIFFScanlineSize(tif); - TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, - rowsperstrip == 0 ? 1 : rowsperstrip); - if (config == PLANARCONFIG_CONTIG) - scanline = (u_char *)malloc(TIFFScanlineSize(tif)); + TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, xsize); + TIFFSetField(tif, TIFFTAG_IMAGELENGTH, ysize); + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8); + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 4); + TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); + TIFFSetField(tif, TIFFTAG_PLANARCONFIG, config); + TIFFSetField(tif, TIFFTAG_COMPRESSION, compression); + TIFFSetField(tif, TIFFTAG_ORIENTATION, orientation); + if (rowsperstrip <= 0) + rowsperstrip = (8*1024)/TIFFScanlineSize(tif); + TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, + rowsperstrip == 0 ? 1 : rowsperstrip); + if (config == PLANARCONFIG_CONTIG) + scanline = (u_char *)malloc(TIFFScanlineSize(tif)); - for (y = 0, pos = pixels; y < ysize; - y++, pos += xsize) { + for (y = 0, pos = pixels; y < ysize; + y++, pos += xsize) { - if (config == PLANARCONFIG_CONTIG) { + if (config == PLANARCONFIG_CONTIG) { #ifdef BYTESWAP - register char *sp = (char *) pos; - register char *tp = (char *) scanline; - register long x; + register char *sp = (char *) pos; + register char *tp = (char *) scanline; + register long x; - for (x = 0; x < xsize; x++) { - tp[3] = sp[0]; - tp[2] = sp[1]; - tp[1] = sp[2]; - tp[0] = sp[3]; - sp += 4; - tp += 4; - } + for (x = 0; x < xsize; x++) { + tp[3] = sp[0]; + tp[2] = sp[1]; + tp[1] = sp[2]; + tp[0] = sp[3]; + sp += 4; + tp += 4; + } #endif #ifndef BYTESWAP bcopy(pos, scanline, xsize*4); #endif - if (TIFFWriteScanline(tif, scanline, y, 0) < 0) - break; - } - else if (config == PLANARCONFIG_SEPARATE) { + if (TIFFWriteScanline(tif, scanline, y, 0) < 0) + break; + } + else if (config == PLANARCONFIG_SEPARATE) { - register char *pp = (char *) pos; - register long x; + register char *pp = (char *) pos; + register long x; - for (x = 0; x < xsize; x++) { - rbuf[x] = pp[0]; - gbuf[x] = pp[1]; - bbuf[x] = pp[2]; - abuf[x] = pp[3]; - pp += 4; - } - if (TIFFWriteScanline(tif, rbuf, y, 0) < 0 || - TIFFWriteScanline(tif, gbuf, y, 1) < 0 || - TIFFWriteScanline(tif, bbuf, y, 2) < 0 || - TIFFWriteScanline(tif, abuf, y, 3) < 0) - break; - } - } + for (x = 0; x < xsize; x++) { + rbuf[x] = pp[0]; + gbuf[x] = pp[1]; + bbuf[x] = pp[2]; + abuf[x] = pp[3]; + pp += 4; + } + if (TIFFWriteScanline(tif, rbuf, y, 0) < 0 || + TIFFWriteScanline(tif, gbuf, y, 1) < 0 || + TIFFWriteScanline(tif, bbuf, y, 2) < 0 || + TIFFWriteScanline(tif, abuf, y, 3) < 0) + break; + } + } (void) TIFFClose(tif); return 1; } @@ -133,121 +132,121 @@ tiff_save_rgba(char *name, long *pixels, long width, long height) long tiff_load_rgba(char *file, long **pixels, long *width, long *height) { - TIFF *tif; - u_short bitspersample, samplesperpixel; - u_long xsize, ysize; - register long x, y, rowbytes; - u_char *buf; + TIFF *tif; + u_short bitspersample, samplesperpixel; + u_long xsize, ysize; + register long x, y, rowbytes; + u_char *buf; long temp; - ushort orient; + ushort orient; register char *tp ; register char *sp ; - if ((tif = TIFFOpen(file, "r")) == NULL) { - fprintf(stderr, "%s: error opening file.\n", file); - return 0; - } + if ((tif = TIFFOpen(file, "r")) == NULL) { + fprintf(stderr, "%s: error opening file.\n", file); + return 0; + } - TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample); - switch (bitspersample) { - case 8: - break; - default: - fprintf(stderr, "%s: Can not image a %d-bit/sample image.\n", - file, bitspersample); - return 0; - } - TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); + TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bitspersample); + switch (bitspersample) { + case 8: + break; + default: + fprintf(stderr, "%s: Can not image a %d-bit/sample image.\n", + file, bitspersample); + return 0; + } + TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel); switch (samplesperpixel) { - case 3: case 4: - break; - default: - fprintf(stderr, "%s: Can not image a %d samples/pixel image.\n", - file, bitspersample); - return 0; - } - TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &xsize); - TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &ysize); - TIFFGetField(tif, TIFFTAG_ORIENTATION, &orient); - switch (orient) { - case ORIENTATION_TOPLEFT: case ORIENTATION_BOTLEFT: - break; - default: - fprintf(stderr, "%s: Unsupported orientation. Will assume ORIENTATION_TOPLEFT.\n" , file); - break; - } + case 3: case 4: + break; + default: + fprintf(stderr, "%s: Can not image a %d samples/pixel image.\n", + file, bitspersample); + return 0; + } + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &xsize); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &ysize); + TIFFGetField(tif, TIFFTAG_ORIENTATION, &orient); + switch (orient) { + case ORIENTATION_TOPLEFT: case ORIENTATION_BOTLEFT: + break; + default: + fprintf(stderr, "%s: Unsupported orientation. Will assume ORIENTATION_TOPLEFT.\n" , file); + break; + } - rowbytes =TIFFScanlineSize(tif); + rowbytes =TIFFScanlineSize(tif); - *width = xsize; - *height = ysize; - *pixels = (long *) malloc(ysize*xsize*sizeof(long)); + *width = xsize; + *height = ysize; + *pixels = (long *) malloc(ysize*xsize*sizeof(long)); switch (samplesperpixel) { - case 3: - tp = (char *) (*pixels); - if (orient != ORIENTATION_BOTLEFT) - tp += 4 * (*height-1) * *width; - buf = (u_char *) malloc(rowbytes); + case 3: + tp = (char *) (*pixels); + if (orient != ORIENTATION_BOTLEFT) + tp += 4 * (*height-1) * *width; + buf = (u_char *) malloc(rowbytes); - for (y = 0; y < ysize; y++) { - if (TIFFReadScanline(tif, buf, y, 0) < 0) - break; + for (y = 0; y < ysize; y++) { + if (TIFFReadScanline(tif, buf, y, 0) < 0) + break; #ifdef BYTESWAP - sp = (char *) buf; + sp = (char *) buf; - for (x = 0; x < xsize; x++) { - tp[3] = sp[0]; - tp[2] = sp[1]; - tp[1] = sp[2]; - tp[0] = 0; - tp += 4; - sp += 3; - } + for (x = 0; x < xsize; x++) { + tp[3] = sp[0]; + tp[2] = sp[1]; + tp[1] = sp[2]; + tp[0] = 0; + tp += 4; + sp += 3; + } #endif - if (orient != ORIENTATION_BOTLEFT) - tp -= 8* *width; - } - break; + if (orient != ORIENTATION_BOTLEFT) + tp -= 8* *width; + } + break; - case 4: - buf = (u_char *) (*pixels); - if (orient != ORIENTATION_BOTLEFT) - buf += (*height-1) * rowbytes; - for (y = 0; y < ysize; y++) { - if (TIFFReadScanline(tif, buf, y, 0) < 0) - break; + case 4: + buf = (u_char *) (*pixels); + if (orient != ORIENTATION_BOTLEFT) + buf += (*height-1) * rowbytes; + for (y = 0; y < ysize; y++) { + if (TIFFReadScanline(tif, buf, y, 0) < 0) + break; #ifdef BYTESWAP - tp = (char *) buf; - sp = (char *) &temp; + tp = (char *) buf; + sp = (char *) &temp; - for (x = 0; x < xsize; x++) { - temp = *((long *)tp); - tp[3] = sp[0]; - tp[2] = sp[1]; - tp[1] = sp[2]; - tp[0] = sp[3]; - tp += 4; - } + for (x = 0; x < xsize; x++) { + temp = *((long *)tp); + tp[3] = sp[0]; + tp[2] = sp[1]; + tp[1] = sp[2]; + tp[0] = sp[3]; + tp += 4; + } #endif - if (orient != ORIENTATION_BOTLEFT) - buf -= rowbytes; - else - buf += rowbytes; - } - break; + if (orient != ORIENTATION_BOTLEFT) + buf -= rowbytes; + else + buf += rowbytes; + } + break; - default: - fprintf(stderr, "%s: Can not image a %d samples/pixel image.\n", - file, bitspersample); - return 0; - } + default: + fprintf(stderr, "%s: Can not image a %d samples/pixel image.\n", + file, bitspersample); + return 0; + } - (void) TIFFClose(tif); - return 1; + (void) TIFFClose(tif); + return 1; } diff --git a/splash2/codes/apps/raytrace/rt.H b/splash2/codes/apps/raytrace/rt.H index 6d801ab22..ecbeb25db 100644 --- a/splash2/codes/apps/raytrace/rt.H +++ b/splash2/codes/apps/raytrace/rt.H @@ -67,14 +67,14 @@ EXTERN_ENV #define MAX_AA_COL 9 #define INT_PAD_SIZE 256 /* padding size for 32-bit - quantities to avoid false-sharing. Pads are inserted in two - situations: (i) when variables are really private to a processor - but are declared in a shared array owing to the lack of a private - space in the sproc lightweight threads model, and (ii) when - there are simple situations of "control" variables that are written - by only one processor but read by several, and declared in a - shared array indexed by process id, e.g. wpstat and workpool - declared in this file */ + quantities to avoid false-sharing. Pads are inserted in two + situations: (i) when variables are really private to a processor + but are declared in a shared array owing to the lack of a private + space in the sproc lightweight threads model, and (ii) when + there are simple situations of "control" variables that are written + by only one processor but read by several, and declared in a + shared array indexed by process id, e.g. wpstat and workpool + declared in this file */ #define MAX_SUBDIV_LEVEL 3 /* Max HUG subdivision level. */ #define MAX_RAYINFO (MAX_SUBDIV_LEVEL + 1) @@ -210,25 +210,25 @@ EXTERN_ENV #define VecDot(A, B) ( A[0]*B[0] + A[1]*B[1] + A[2]*B[2] ) #define VecCross(C, A, B) { C[0] = A[1]*B[2] - A[2]*B[1]; \ - C[1] = A[2]*B[0] - A[0]*B[2]; \ - C[2] = A[0]*B[1] - A[1]*B[0]; } + C[1] = A[2]*B[0] - A[0]*B[2]; \ + C[2] = A[0]*B[1] - A[1]*B[0]; } #define VecNegate(B, A) { B[0] = -A[0]; B[1] = -A[1]; B[2] = -A[2]; } #define VecCopy(B, A) { B[0] = A[0]; B[1] = A[1]; B[2] = A[2]; } #define VecAdd(C, A, B) { C[0] = A[0] + B[0]; \ - C[1] = A[1] + B[1]; \ - C[2] = A[2] + B[2]; } + C[1] = A[1] + B[1]; \ + C[2] = A[2] + B[2]; } #define VecSub(C, A, B) { C[0] = A[0] - B[0]; \ - C[1] = A[1] - B[1]; \ - C[2] = A[2] - B[2]; } + C[1] = A[1] - B[1]; \ + C[2] = A[2] - B[2]; } #define VecScale(B, scale, A) { B[0] = scale * A[0]; \ - B[1] = scale * A[1]; \ - B[2] = scale * A[2]; } + B[1] = scale * A[1]; \ + B[2] = scale * A[2]; } /* @@ -236,11 +236,11 @@ EXTERN_ENV */ #define IsectAdd(hit, tval, P) { (hit)->t = tval; \ - (hit)->pelem = P; } + (hit)->pelem = P; } #define RayPoint(pi, ray, tval) { pi[0] = ray->P[0] + ray->D[0]*tval; \ - pi[1] = ray->P[1] + ray->D[1]*tval; \ - pi[2] = ray->P[2] + ray->D[2]*tval; } + pi[1] = ray->P[1] + ray->D[1]*tval; \ + pi[2] = ray->P[2] + ray->D[2]*tval; } @@ -289,19 +289,19 @@ typedef VEC3 COLOR; /* An r, g, b color. */ */ typedef struct pprocs - { - CHAR *(*name)(); /* Primitive name. */ - VOID (*print)(); /* Primitive print. */ - VOID (*read)(); /* Read from model file. */ - VOID (*binread)(); /* Binary read from model file. */ - VOID (*transform)(); /* Transform primitive. */ - INT (*intersect)(); /* Intersect object with a ray. */ - INT (*pe_intersect)(); /* Intersect primelement with a ray. */ - VOID (*normal)(); /* Compute normal vector. */ - VOID (*normalize)(); /* Data normalization to unit cube. */ - VOID (*bbox)(); /* Bounding box constructor. */ - } - PPROCS; + { + CHAR *(*name)(); /* Primitive name. */ + VOID (*print)(); /* Primitive print. */ + VOID (*read)(); /* Read from model file. */ + VOID (*binread)(); /* Binary read from model file. */ + VOID (*transform)(); /* Transform primitive. */ + INT (*intersect)(); /* Intersect object with a ray. */ + INT (*pe_intersect)(); /* Intersect primelement with a ray. */ + VOID (*normal)(); /* Compute normal vector. */ + VOID (*normalize)(); /* Data normalization to unit cube. */ + VOID (*bbox)(); /* Bounding box constructor. */ + } + PPROCS; /* @@ -309,16 +309,16 @@ typedef struct pprocs */ typedef struct surf - { - COLOR fcolor; /* Front facing color. */ - COLOR bcolor; /* Back facing color. */ - REAL kdiff; /* Diffuse coefficient. */ - REAL kspec; /* Specular coefficient. */ - REAL ktran; /* Transmission coefficient. */ - REAL refrindex; /* Index of refraction. */ - REAL kspecn; /* Specular distribution coeff. */ - } - SURF; + { + COLOR fcolor; /* Front facing color. */ + COLOR bcolor; /* Back facing color. */ + REAL kdiff; /* Diffuse coefficient. */ + REAL kspec; /* Specular coefficient. */ + REAL ktran; /* Transmission coefficient. */ + REAL refrindex; /* Index of refraction. */ + REAL kspecn; /* Specular distribution coeff. */ + } + SURF; @@ -327,13 +327,13 @@ typedef struct surf */ typedef struct light - { - VEC4 pos; /* Light position. */ - COLOR col; /* Light color. */ - BOOL shadow; /* Send shadow rays? */ - struct light *next; /* Ptr to next light. */ - } - LIGHT; + { + VEC4 pos; /* Light position. */ + COLOR col; /* Light color. */ + BOOL shadow; /* Send shadow rays? */ + struct light *next; /* Ptr to next light. */ + } + LIGHT; @@ -342,12 +342,12 @@ typedef struct light */ typedef struct pixel - { - R32 r; - R32 g; - R32 b; - } - PIXEL; + { + R32 r; + R32 g; + R32 b; + } + PIXEL; @@ -356,17 +356,17 @@ typedef struct pixel */ typedef struct voxel - { - INT id; /* id = index1D */ - INT numelements; /* Number of elements in voxel. */ - struct voxel *next; /* Hashtable bucket list. */ - CHAR *cell; /* Ptr to grid or ptr to ElemPtr list*/ - CHAR celltype; /* 0 => local voxel, 1 => local grid */ - /* 2 => GSM voxel, 3 => GSM grid */ - /* 4 => remote voxel, 5 =>remote grid*/ - CHAR dummy[sizeof(INT) - 1]; - } - VOXEL; + { + INT id; /* id = index1D */ + INT numelements; /* Number of elements in voxel. */ + struct voxel *next; /* Hashtable bucket list. */ + CHAR *cell; /* Ptr to grid or ptr to ElemPtr list*/ + CHAR celltype; /* 0 => local voxel, 1 => local grid */ + /* 2 => GSM voxel, 3 => GSM grid */ + /* 4 => remote voxel, 5 =>remote grid*/ + CHAR dummy[sizeof(INT) - 1]; + } + VOXEL; @@ -375,11 +375,11 @@ typedef struct voxel */ typedef struct bbox - { - REAL dnear[3]; - REAL dfar[3]; - } - BBOX; + { + REAL dnear[3]; + REAL dfar[3]; + } + BBOX; @@ -388,20 +388,20 @@ typedef struct bbox */ typedef struct view - { - POINT eye; /* Eye position. */ - POINT coi; /* Center position */ - MATRIX vtrans; /* Viewing transformation */ - MATRIX vtransInv; /* Inverse viewing transformation */ - MATRIX model; /* Global model transformation */ - COLOR bkg; /* Background color. */ - INT projection; /* Projection type. */ - REAL vang; /* View angle. */ - COLOR ambient; /* Ambient light. */ - BOOL shad; /* Shadow indicator. */ - BOOL shading; /* Shading indicator. */ - } - VIEW; + { + POINT eye; /* Eye position. */ + POINT coi; /* Center position */ + MATRIX vtrans; /* Viewing transformation */ + MATRIX vtransInv; /* Inverse viewing transformation */ + MATRIX model; /* Global model transformation */ + COLOR bkg; /* Background color. */ + INT projection; /* Projection type. */ + REAL vang; /* View angle. */ + COLOR ambient; /* Ambient light. */ + BOOL shad; /* Shadow indicator. */ + BOOL shading; /* Shading indicator. */ + } + VIEW; /* @@ -409,25 +409,25 @@ typedef struct view */ typedef struct display - { - INT maxlevel; /* Maximum raytrace level. */ - INT maxAAsubdiv; /* Maximum antialiasing subdivision. */ - INT aarow; /* Max anti row index for super-sampling. */ - INT aacol; /* Max anti column index for super-sampling. */ - REAL aatolerance; /* Antialiasing tolerance color difference. */ - INT xres,yres; /* Display resolution. */ - INT numpixels; /* Total number of pixels in framebuffer. */ - REAL minweight; /* Minimum ray weight. */ - REAL scrDist; /* Screen distance from eye. */ - REAL scrWidth; /* Screen width. */ - REAL scrHeight; /* Screen height. */ - REAL scrHalfWidth; /* Screen half width. */ - REAL scrHalfHeight; /* Screen half height. */ - REAL vWscale; /* Screen width scale. */ - REAL vHscale; /* Screen height scale. */ - PIXEL *framebuffer; /* Ptr to the framebuffer. */ - } - DISPLAY; + { + INT maxlevel; /* Maximum raytrace level. */ + INT maxAAsubdiv; /* Maximum antialiasing subdivision. */ + INT aarow; /* Max anti row index for super-sampling. */ + INT aacol; /* Max anti column index for super-sampling. */ + REAL aatolerance; /* Antialiasing tolerance color difference. */ + INT xres,yres; /* Display resolution. */ + INT numpixels; /* Total number of pixels in framebuffer. */ + REAL minweight; /* Minimum ray weight. */ + REAL scrDist; /* Screen distance from eye. */ + REAL scrWidth; /* Screen width. */ + REAL scrHeight; /* Screen height. */ + REAL scrHalfWidth; /* Screen half width. */ + REAL scrHalfHeight; /* Screen half height. */ + REAL vWscale; /* Screen width scale. */ + REAL vHscale; /* Screen height scale. */ + PIXEL *framebuffer; /* Ptr to the framebuffer. */ + } + DISPLAY; @@ -436,13 +436,13 @@ typedef struct display */ typedef struct element - { - INT index; - struct object *parent; /* Ptr back to parent object. */ - CHAR *data; /* Pointer to data info. */ - BBOX bv; /* Element bounding volume. */ - } - ELEMENT; + { + INT index; + struct object *parent; /* Ptr back to parent object. */ + CHAR *data; /* Pointer to data info. */ + BBOX bv; /* Element bounding volume. */ + } + ELEMENT; /* @@ -450,17 +450,17 @@ typedef struct element */ typedef struct object - { - INT index; - CHAR name[NAME_LEN]; /* Name of object. */ - BBOX bv; /* Bound volume. */ - ELEMENT *pelem; /* Pointer to prim element list. */ - INT numelements; /* Number of primitive elements. */ - PPROCS *procs; /* Pointer to primitive procs. */ - SURF *surf; /* Pointer to surface properties. */ - struct object *next; /* Next primitive (linked list). */ - } - OBJECT; + { + INT index; + CHAR name[NAME_LEN]; /* Name of object. */ + BBOX bv; /* Bound volume. */ + ELEMENT *pelem; /* Pointer to prim element list. */ + INT numelements; /* Number of primitive elements. */ + PPROCS *procs; /* Pointer to primitive procs. */ + SURF *surf; /* Pointer to surface properties. */ + struct object *next; /* Next primitive (linked list). */ + } + OBJECT; /* @@ -468,14 +468,14 @@ typedef struct object */ typedef struct irecord - { - REAL t; /* Line parameter at intersection. */ - ELEMENT *pelem; /* Primitve element. */ - REAL b1; /* Barycentric coordinates of */ - REAL b2; /* intersection for triangles. */ - REAL b3; - } - IRECORD; + { + REAL t; /* Line parameter at intersection. */ + ELEMENT *pelem; /* Primitve element. */ + REAL b1; /* Barycentric coordinates of */ + REAL b2; /* intersection for triangles. */ + REAL b3; + } + IRECORD; @@ -484,56 +484,56 @@ typedef struct irecord */ typedef struct btnode - { - ELEMENT **pe; /* Array of primitive element ptrs in node. */ - REAL p[3]; /* Lower left corner of bounding box */ - /* of space represented by node. */ - INT nprims; /* # prims in node primElem list. */ - INT n[3]; /* Gridsizes for this box. */ - INT i[3]; /* Indices of cell (lower left corner */ - /* if not a leaf) in grid. */ - INT axis; /* subdiv axis, 0,1,2 => x,y,z */ - INT totalPrimsAllocated; /* This is used for garbage allocation.*/ - struct btnode *btn[2]; /* Ptrs to children. */ - } - BTNODE; + { + ELEMENT **pe; /* Array of primitive element ptrs in node. */ + REAL p[3]; /* Lower left corner of bounding box */ + /* of space represented by node. */ + INT nprims; /* # prims in node primElem list. */ + INT n[3]; /* Gridsizes for this box. */ + INT i[3]; /* Indices of cell (lower left corner */ + /* if not a leaf) in grid. */ + INT axis; /* subdiv axis, 0,1,2 => x,y,z */ + INT totalPrimsAllocated; /* This is used for garbage allocation.*/ + struct btnode *btn[2]; /* Ptrs to children. */ + } + BTNODE; typedef struct grid - { - INT id; - VOXEL **hashtable; /* hashtable[ num_buckets ] is indexed */ - /* by index1D mod num_buckets, */ - /* num_buckets and n, the # of cells/ */ - /* axis, should be relatively prime, */ - /* grids at different levels may */ - /* have different num_buckets. */ - UINT *emptycells; /* emptycells[ ceil( NumCells */ - /* sizeof(unsigned) ) ], a packed */ - /* array of bits indicating for */ - /* each cell if it is empty, */ - /* 1 => empty, */ - /* grids at different levels may */ - /* have different NumCells. */ - ELEMENT **pepa; /* prim element pointer list */ - INT num_prims; /* number of prims on prim element */ - /* list */ - INT indx_inc[3]; /* if n is # of cells per axis, */ - /* NumCells is n**3, */ - /* indx_inc[0,1,2] = 1, n, n**2; */ - /* inc for index1D. */ - INT num_buckets; /* # buckets in hashtable */ - REAL min[3]; /* cell min boundary, world coord */ - REAL cellsize[3]; /* cellsize of voxels in this grid */ - /* in world coord */ - INT subdiv_level; /* # levels of space subdiv */ - /* to reach this grid, */ - /* 0 is top level. */ - BTNODE *bintree; /* root of bintree for this grid */ - struct grid *next; /* grid list */ - } - GRID; + { + INT id; + VOXEL **hashtable; /* hashtable[ num_buckets ] is indexed */ + /* by index1D mod num_buckets, */ + /* num_buckets and n, the # of cells/ */ + /* axis, should be relatively prime, */ + /* grids at different levels may */ + /* have different num_buckets. */ + UINT *emptycells; /* emptycells[ ceil( NumCells */ + /* sizeof(unsigned) ) ], a packed */ + /* array of bits indicating for */ + /* each cell if it is empty, */ + /* 1 => empty, */ + /* grids at different levels may */ + /* have different NumCells. */ + ELEMENT **pepa; /* prim element pointer list */ + INT num_prims; /* number of prims on prim element */ + /* list */ + INT indx_inc[3]; /* if n is # of cells per axis, */ + /* NumCells is n**3, */ + /* indx_inc[0,1,2] = 1, n, n**2; */ + /* inc for index1D. */ + INT num_buckets; /* # buckets in hashtable */ + REAL min[3]; /* cell min boundary, world coord */ + REAL cellsize[3]; /* cellsize of voxels in this grid */ + /* in world coord */ + INT subdiv_level; /* # levels of space subdiv */ + /* to reach this grid, */ + /* 0 is top level. */ + BTNODE *bintree; /* root of bintree for this grid */ + struct grid *next; /* grid list */ + } + GRID; @@ -544,27 +544,27 @@ typedef struct grid */ typedef struct rayinfo - { - GRID *grid; /* Grid for this rayinfo. */ - REAL d[3]; /* Dist along ray from world coord origin to */ - /* next voxel boundary. */ - INT entry_plane; /* Entry plane for current voxel, */ - /* (0,1,2) => (x,y,z). */ - REAL t_in; /* Dist along ray from world coord origin to */ - /* entry point of current voxel. */ - INT exit_plane; /* Exit plane for current voxel, */ - /* (0,1,2) => (x,y,z). */ - REAL t_out; /* Dist along ray from world coord origin to */ - /* exit point of current voxel. */ - REAL delta[3]; /* Dist along ray between voxel boundaries. */ - INT index3D[3]; /* Current cell in cell units wrt grid origin*/ - INT index1D; /* Index1D = i + j * n + k * n**2 */ - /* where index3D[] = i,j,k and n is the */ - /* # of divisions per axis. */ - INT indx_inc1D[3]; /* Including sign of ray direction. */ - struct rayinfo *next; /* Ptr to next structure. */ - } - RAYINFO; + { + GRID *grid; /* Grid for this rayinfo. */ + REAL d[3]; /* Dist along ray from world coord origin to */ + /* next voxel boundary. */ + INT entry_plane; /* Entry plane for current voxel, */ + /* (0,1,2) => (x,y,z). */ + REAL t_in; /* Dist along ray from world coord origin to */ + /* entry point of current voxel. */ + INT exit_plane; /* Exit plane for current voxel, */ + /* (0,1,2) => (x,y,z). */ + REAL t_out; /* Dist along ray from world coord origin to */ + /* exit point of current voxel. */ + REAL delta[3]; /* Dist along ray between voxel boundaries. */ + INT index3D[3]; /* Current cell in cell units wrt grid origin*/ + INT index1D; /* Index1D = i + j * n + k * n**2 */ + /* where index3D[] = i,j,k and n is the */ + /* # of divisions per axis. */ + INT indx_inc1D[3]; /* Including sign of ray direction. */ + struct rayinfo *next; /* Ptr to next structure. */ + } + RAYINFO; @@ -573,20 +573,20 @@ typedef struct rayinfo */ typedef struct ray - { - LONG id; /* Ray id. */ - INT x, y; /* Pixel ray is part of. */ - VEC3 P; /* Position (origin). */ - VEC3 D; /* Direction. */ - INT level; /* Level of ray in ray tree. */ - RAYINFO *ri; /* Grid dependent ray info. */ - INT ri_indx; - INT indx_inc3D[3]; /* Incl sign of ray direction*/ - RAYINFO rinfo[MAX_RAYINFO + 1]; - R32 weight; /* Ray weight. */ - R32 dummy; - } - RAY; + { + LONG id; /* Ray id. */ + INT x, y; /* Pixel ray is part of. */ + VEC3 P; /* Position (origin). */ + VEC3 D; /* Direction. */ + INT level; /* Level of ray in ray tree. */ + RAYINFO *ri; /* Grid dependent ray info. */ + INT ri_indx; + INT indx_inc3D[3]; /* Incl sign of ray direction*/ + RAYINFO rinfo[MAX_RAYINFO + 1]; + R32 weight; /* Ray weight. */ + R32 dummy; + } + RAY; @@ -595,12 +595,12 @@ typedef struct ray */ typedef struct rayjob - { - INT x, y; /* Primary ray pixel start address. */ - INT xlen, ylen; /* Length of scanline bundle. */ - INT xcurr, ycurr; /* Current ray pixel address. */ - } - RAYJOB; + { + INT x, y; /* Primary ray pixel start address. */ + INT xlen, ylen; /* Length of scanline bundle. */ + INT xcurr, ycurr; /* Current ray pixel address. */ + } + RAYJOB; @@ -609,12 +609,12 @@ typedef struct rayjob */ typedef struct wpjob - { - INT ypix, xpix; /* Primary ray pixel address. */ - INT xdim, ydim; /* Pixel bundle size. */ - struct wpjob *next; - } - WPJOB; + { + INT ypix, xpix; /* Primary ray pixel address. */ + INT xdim, ydim; /* Pixel bundle size. */ + struct wpjob *next; + } + WPJOB; @@ -623,13 +623,13 @@ typedef struct wpjob */ typedef struct node - { - struct node huge *next; /* Ptr to next free node. */ - UINT size; /* Size of node in bytes excl header.*/ - BOOL free; /* TRUE = free, FALSE = in use. */ - UINT cksm; /* Arena integrity check. */ - } - NODE; + { + struct node huge *next; /* Ptr to next free node. */ + UINT size; /* Size of node in bytes excl header.*/ + BOOL free; /* TRUE = free, FALSE = in use. */ + UINT cksm; /* Arena integrity check. */ + } + NODE; @@ -638,29 +638,29 @@ typedef struct node */ typedef struct gmem - { - INT nprocs; /* Number of processes. */ - INT pid; /* Global process id counter. */ - INT rid; /* Global ray id counter. */ - OBJECT *modelroot; /* Root of model list. */ - GRID *world_level_grid; /* Zero level grid pointer. */ - NODE huge *freelist; /* Ptr to global free memory heap. */ - INT wpstat[MAX_PROCS][INT_PAD_SIZE]; /* Shared work pool - status hints. Padded to avoid - false-sharing */ - WPJOB *workpool[MAX_PROCS][INT_PAD_SIZE]; /* Ptr to heads of - shared work pools. Padded to - avoid false-sharing */ + { + INT nprocs; /* Number of processes. */ + INT pid; /* Global process id counter. */ + INT rid; /* Global ray id counter. */ + OBJECT *modelroot; /* Root of model list. */ + GRID *world_level_grid; /* Zero level grid pointer. */ + NODE huge *freelist; /* Ptr to global free memory heap. */ + INT wpstat[MAX_PROCS][INT_PAD_SIZE]; /* Shared work pool + status hints. Padded to avoid + false-sharing */ + WPJOB *workpool[MAX_PROCS][INT_PAD_SIZE]; /* Ptr to heads of + shared work pools. Padded to + avoid false-sharing */ - BARDEC(start) /* Barrier for startup sync. */ - LOCKDEC(pidlock) /* Lock to increment pid. */ - LOCKDEC(ridlock) /* Lock to increment rid. */ - LOCKDEC(memlock) /* Lock for memory manager. */ - ALOCKDEC(wplock, MAX_PROCS) /* Locks for shared work pools. */ + BARDEC(start) /* Barrier for startup sync. */ + LOCKDEC(pidlock) /* Lock to increment pid. */ + LOCKDEC(ridlock) /* Lock to increment rid. */ + LOCKDEC(memlock) /* Lock for memory manager. */ + ALOCKDEC(wplock, MAX_PROCS) /* Locks for shared work pools. */ UINT par_start_time; UINT partime[MAX_PROCS]; - } - GMEM; + } + GMEM; diff --git a/splash2/codes/apps/raytrace/shade.C b/splash2/codes/apps/raytrace/shade.C index e03e96949..2dea2d799 100644 --- a/splash2/codes/apps/raytrace/shade.C +++ b/splash2/codes/apps/raytrace/shade.C @@ -28,11 +28,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + /* * NAME * SpecularDirection - compute reflected ray @@ -48,23 +49,23 @@ */ VOID SpecularDirection(POINT R, POINT N, POINT I) - { - REAL I_dot_N; /* I*N */ - POINT N2; /* 2N */ - POINT vprime; /* Scale of I */ + { + REAL I_dot_N; /* I*N */ + POINT N2; /* 2N */ + POINT vprime; /* Scale of I */ - /* Turner's calculation from first paper. */ + /* Turner's calculation from first paper. */ - I_dot_N = VecDot(I,N); - I_dot_N = ABS(I_dot_N); - I_dot_N = 1.0/I_dot_N; + I_dot_N = VecDot(I,N); + I_dot_N = ABS(I_dot_N); + I_dot_N = 1.0/I_dot_N; - VecScale(vprime, I_dot_N, I); - VecScale(N2, 2.0, N); + VecScale(vprime, I_dot_N, I); + VecScale(N2, 2.0, N); - VecAdd(R, vprime, N2); - VecNorm(R); - } + VecAdd(R, vprime, N2); + VecNorm(R); + } @@ -84,41 +85,41 @@ VOID SpecularDirection(POINT R, POINT N, POINT I) */ BOOL TransmissionDirection(POINT T, POINT N, POINT I, REAL kn) - { - POINT vprime; /* Parameters in calculation. */ - POINT vplusn; - REAL I_dot_N; - REAL kf; - REAL vprime_sq; - REAL vplusn_sq; + { + POINT vprime; /* Parameters in calculation. */ + POINT vplusn; + REAL I_dot_N; + REAL kf; + REAL vprime_sq; + REAL vplusn_sq; - /* Turner's calculation from first paper. */ + /* Turner's calculation from first paper. */ - I_dot_N = VecDot(I,N); - I_dot_N = ABS(I_dot_N); - I_dot_N = 1.0/I_dot_N; + I_dot_N = VecDot(I,N); + I_dot_N = ABS(I_dot_N); + I_dot_N = 1.0/I_dot_N; - VecScale(vprime, I_dot_N, I); - VecAdd(vplusn, vprime, N); + VecScale(vprime, I_dot_N, I); + VecAdd(vplusn, vprime, N); - vprime_sq = VecDot(vprime, vprime); - vplusn_sq = VecDot(vplusn, vplusn); + vprime_sq = VecDot(vprime, vprime); + vplusn_sq = VecDot(vplusn, vplusn); - kf = kn*kn*vprime_sq - vplusn_sq; + kf = kn*kn*vprime_sq - vplusn_sq; - if (kf > RAYEPS) - { - kf = 1.0/sqrt(kf); + if (kf > RAYEPS) + { + kf = 1.0/sqrt(kf); - VecScale(vplusn, kf, vplusn); - VecSub(T, vplusn, N); - VecNorm(T); - } - else - return (FALSE); + VecScale(vplusn, kf, vplusn); + VecSub(T, vplusn, N); + VecNorm(T); + } + else + return (FALSE); - return (TRUE); - } + return (TRUE); + } @@ -139,162 +140,162 @@ BOOL TransmissionDirection(POINT T, POINT N, POINT I, REAL kn) */ VOID Shade(VEC3 iP, VEC3 N, RAY *ray, IRECORD *hit, INT pid) - { - VEC3 Lvec; /* Light vector. */ - VEC3 Hvec; /* Highlight vector. */ - VEC3 Evec; /* Eye vector. */ - RAY shad_ray; /* Shadow ray. */ - RAY secondary_ray; /* Secondary ray. */ - COLOR surfcol; /* Primitive surface color. */ - COLOR col; /* Ray color contribution. */ - REAL NdotL; /* Diffuse conritbution. */ - REAL Diff; /* Diffuse variable. */ - REAL NdotH; /* Highlight contribution. */ - REAL spec; /* Highlight variable. */ - OBJECT *po; /* Ptr to object. */ - SURF *s; /* Surface pointer. */ - INT i; /* Index variables. */ - REAL lightlen; /* Length of light vector. */ - REAL shadtrans; /* Shadow transmission. */ - LIGHT *lptr; /* Light pointer. */ + { + VEC3 Lvec; /* Light vector. */ + VEC3 Hvec; /* Highlight vector. */ + VEC3 Evec; /* Eye vector. */ + RAY shad_ray; /* Shadow ray. */ + RAY secondary_ray; /* Secondary ray. */ + COLOR surfcol; /* Primitive surface color. */ + COLOR col; /* Ray color contribution. */ + REAL NdotL; /* Diffuse conritbution. */ + REAL Diff; /* Diffuse variable. */ + REAL NdotH; /* Highlight contribution. */ + REAL spec; /* Highlight variable. */ + OBJECT *po; /* Ptr to object. */ + SURF *s; /* Surface pointer. */ + INT i; /* Index variables. */ + REAL lightlen; /* Length of light vector. */ + REAL shadtrans; /* Shadow transmission. */ + LIGHT *lptr; /* Light pointer. */ - /* Initialize primitive info and ray color. */ + /* Initialize primitive info and ray color. */ - po = hit->pelem->parent; - s = po->surf; - VecCopy(surfcol, s->fcolor); + po = hit->pelem->parent; + s = po->surf; + VecCopy(surfcol, s->fcolor); - /* Initialize color to ambient. */ + /* Initialize color to ambient. */ - col[0] = View.ambient[0] * surfcol[0]; - col[1] = View.ambient[1] * surfcol[1]; - col[2] = View.ambient[2] * surfcol[2]; + col[0] = View.ambient[0] * surfcol[0]; + col[1] = View.ambient[1] * surfcol[1]; + col[2] = View.ambient[2] * surfcol[2]; - /* Set shadow ray origin. */ + /* Set shadow ray origin. */ - VecCopy(shad_ray.P, iP); - VecNegate(Evec, ray->D); + VecCopy(shad_ray.P, iP); + VecNegate(Evec, ray->D); - /* Account for all lights. */ + /* Account for all lights. */ - lptr = lights; - for (i = 0; i < nlights; i++) - { - VecSub(Lvec, lptr->pos, iP); - lightlen = VecLen(Lvec); - VecNorm(Lvec); - VecCopy(shad_ray.D, Lvec); + lptr = lights; + for (i = 0; i < nlights; i++) + { + VecSub(Lvec, lptr->pos, iP); + lightlen = VecLen(Lvec); + VecNorm(Lvec); + VecCopy(shad_ray.D, Lvec); - LOCK(gm->ridlock); - shad_ray.id = gm->rid++; - UNLOCK(gm->ridlock); + LOCK(gm->ridlock); + shad_ray.id = gm->rid++; + UNLOCK(gm->ridlock); - NdotL = VecDot(N, Lvec); + NdotL = VecDot(N, Lvec); - if (NdotL > 0.0) - { - /* Test to see if point shadowed. */ + if (NdotL > 0.0) + { + /* Test to see if point shadowed. */ - if (View.shad && !lptr->shadow) - { - switch (TraversalType) - { - case TT_LIST: - shadtrans = ShadowIntersect(&shad_ray, lightlen, hit->pelem); - break; + if (View.shad && !lptr->shadow) + { + switch (TraversalType) + { + case TT_LIST: + shadtrans = ShadowIntersect(&shad_ray, lightlen, hit->pelem); + break; - case TT_HUG: - shadtrans = HuniformShadowIntersect(&shad_ray, lightlen, hit->pelem, pid); - break; - } - } - else - shadtrans = 1.0; + case TT_HUG: + shadtrans = HuniformShadowIntersect(&shad_ray, lightlen, hit->pelem, pid); + break; + } + } + else + shadtrans = 1.0; - /* Compute non-shadowed shades. */ + /* Compute non-shadowed shades. */ - if (shadtrans > 0.0) - { - Diff = po->surf->kdiff * NdotL * shadtrans; + if (shadtrans > 0.0) + { + Diff = po->surf->kdiff * NdotL * shadtrans; - col[0] += surfcol[0] * lptr->col[0] * Diff; - col[1] += surfcol[1] * lptr->col[1] * Diff; - col[2] += surfcol[2] * lptr->col[2] * Diff; + col[0] += surfcol[0] * lptr->col[0] * Diff; + col[1] += surfcol[1] * lptr->col[1] * Diff; + col[2] += surfcol[2] * lptr->col[2] * Diff; - /* Add specular. */ + /* Add specular. */ - if (s->kspec > 0.0) - { - VecAdd(Hvec,Lvec,Evec); - VecNorm(Hvec); - NdotH = VecDot(N,Hvec); + if (s->kspec > 0.0) + { + VecAdd(Hvec,Lvec,Evec); + VecNorm(Hvec); + NdotH = VecDot(N,Hvec); - if (NdotH > 0.0) - { - spec = pow(NdotH, s->kspecn); - spec *= s->kspec; + if (NdotH > 0.0) + { + spec = pow(NdotH, s->kspecn); + spec *= s->kspec; - col[0] += lptr->col[0]*spec; - col[1] += lptr->col[1]*spec; - col[2] += lptr->col[2]*spec; - } - } - } - } + col[0] += lptr->col[0]*spec; + col[1] += lptr->col[1]*spec; + col[2] += lptr->col[2]*spec; + } + } + } + } - lptr = lptr->next; - } + lptr = lptr->next; + } - /* Add color to pixel frame buffer. */ + /* Add color to pixel frame buffer. */ - VecScale(col, ray->weight, col); - AddPixelColor(col, ray->x, ray->y); + VecScale(col, ray->weight, col); + AddPixelColor(col, ray->x, ray->y); - /* Recurse if not at maximum level. */ + /* Recurse if not at maximum level. */ - if ((ray->level) + 1 < Display.maxlevel) - { - VecCopy(secondary_ray.P, iP); + if ((ray->level) + 1 < Display.maxlevel) + { + VecCopy(secondary_ray.P, iP); - /* Specular. */ - secondary_ray.weight = po->surf->kspec * ray->weight; + /* Specular. */ + secondary_ray.weight = po->surf->kspec * ray->weight; - if (secondary_ray.weight > Display.minweight) - { - SpecularDirection(secondary_ray.D, N, ray->D); - secondary_ray.level = ray->level + 1; + if (secondary_ray.weight > Display.minweight) + { + SpecularDirection(secondary_ray.D, N, ray->D); + secondary_ray.level = ray->level + 1; - LOCK(gm->ridlock); - secondary_ray.id = gm->rid++; - UNLOCK(gm->ridlock); + LOCK(gm->ridlock); + secondary_ray.id = gm->rid++; + UNLOCK(gm->ridlock); - secondary_ray.x = ray->x; - secondary_ray.y = ray->y; + secondary_ray.x = ray->x; + secondary_ray.y = ray->y; - PushRayTreeStack(&secondary_ray, pid); + PushRayTreeStack(&secondary_ray, pid); - } + } - /* Transmission. */ - secondary_ray.weight = po->surf->ktran * ray->weight; + /* Transmission. */ + secondary_ray.weight = po->surf->ktran * ray->weight; - if (secondary_ray.weight > Display.minweight) - { - if (TransmissionDirection(secondary_ray.D, N, ray->D, po->surf->refrindex)) - { - secondary_ray.level = ray->level + 1; + if (secondary_ray.weight > Display.minweight) + { + if (TransmissionDirection(secondary_ray.D, N, ray->D, po->surf->refrindex)) + { + secondary_ray.level = ray->level + 1; - LOCK(gm->ridlock); - secondary_ray.id = gm->rid++; - UNLOCK(gm->ridlock); + LOCK(gm->ridlock); + secondary_ray.id = gm->rid++; + UNLOCK(gm->ridlock); - secondary_ray.x = ray->x; - secondary_ray.y = ray->y; + secondary_ray.x = ray->x; + secondary_ray.y = ray->y; - PushRayTreeStack(&secondary_ray, pid); + PushRayTreeStack(&secondary_ray, pid); - } - } - } - } + } + } + } + } diff --git a/splash2/codes/apps/raytrace/sph.C b/splash2/codes/apps/raytrace/sph.C index d50a0881c..28247f2a9 100644 --- a/splash2/codes/apps/raytrace/sph.C +++ b/splash2/codes/apps/raytrace/sph.C @@ -25,11 +25,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + /* * NAME * SphName - return the object name @@ -42,9 +43,9 @@ */ CHAR *SphName() - { - return ("sphere"); - } + { + return ("sphere"); + } @@ -61,22 +62,22 @@ CHAR *SphName() */ VOID SphPrint(OBJECT *po) - { - INT i; - SPHERE *ps; /* Ptr to sphere data. */ - ELEMENT *pe; /* Ptr to sphere element. */ + { + INT i; + SPHERE *ps; /* Ptr to sphere data. */ + ELEMENT *pe; /* Ptr to sphere element. */ - pe = po->pelem; - fprintf(stderr,"\tSphere object\n"); + pe = po->pelem; + fprintf(stderr,"\tSphere object\n"); - for (i = 0; i < po->numelements; i++) - { - ps = (SPHERE *)(pe->data); - fprintf(stderr,"\t\tcenter %f %f %f\n", ps->center[0], ps->center[1], ps->center[2]); - fprintf(stderr,"\t\t radius %f %f\n\n", ps->rad, ps->rad2); - pe++; - } - } + for (i = 0; i < po->numelements; i++) + { + ps = (SPHERE *)(pe->data); + fprintf(stderr,"\t\tcenter %f %f %f\n", ps->center[0], ps->center[1], ps->center[2]); + fprintf(stderr,"\t\t radius %f %f\n\n", ps->rad, ps->rad2); + pe++; + } + } @@ -94,19 +95,19 @@ VOID SphPrint(OBJECT *po) */ VOID SphElementBoundBox(ELEMENT *pe, SPHERE *ps) - { - BBOX *pbb; /* Ptr to bounding box. */ + { + BBOX *pbb; /* Ptr to bounding box. */ - pbb = &(pe->bv); + pbb = &(pe->bv); - pbb->dnear[0] = ps->center[0] - ps->rad; - pbb->dnear[1] = ps->center[1] - ps->rad; - pbb->dnear[2] = ps->center[2] - ps->rad; + pbb->dnear[0] = ps->center[0] - ps->rad; + pbb->dnear[1] = ps->center[1] - ps->rad; + pbb->dnear[2] = ps->center[2] - ps->rad; - pbb->dfar[0] = ps->center[0] + ps->rad; - pbb->dfar[1] = ps->center[1] + ps->rad; - pbb->dfar[2] = ps->center[2] + ps->rad; - } + pbb->dfar[0] = ps->center[0] + ps->rad; + pbb->dfar[1] = ps->center[1] + ps->rad; + pbb->dfar[2] = ps->center[2] + ps->rad; + } @@ -123,45 +124,45 @@ VOID SphElementBoundBox(ELEMENT *pe, SPHERE *ps) */ VOID SphBoundBox(OBJECT *po) - { - INT i; - SPHERE *ps; /* Ptr to sphere data. */ - ELEMENT *pe; /* Ptr to sphere element. */ - BBOX *pbb; /* Ptr to bounding box. */ - REAL minx, maxx; - REAL miny, maxy; - REAL minz, maxz; + { + INT i; + SPHERE *ps; /* Ptr to sphere data. */ + ELEMENT *pe; /* Ptr to sphere element. */ + BBOX *pbb; /* Ptr to bounding box. */ + REAL minx, maxx; + REAL miny, maxy; + REAL minz, maxz; - pe = po->pelem; - pbb = &(po->bv); + pe = po->pelem; + pbb = &(po->bv); - minx = miny = minz = HUGE_REAL; - maxx = maxy = maxz = -HUGE_REAL; + minx = miny = minz = HUGE_REAL; + maxx = maxy = maxz = -HUGE_REAL; - for (i = 0; i < po->numelements; i++) - { - ps = (SPHERE *)(pe->data); - SphElementBoundBox(pe, ps); + for (i = 0; i < po->numelements; i++) + { + ps = (SPHERE *)(pe->data); + SphElementBoundBox(pe, ps); - minx = Min(minx, pe->bv.dnear[0]); - miny = Min(miny, pe->bv.dnear[1]); - minz = Min(minz, pe->bv.dnear[2]); + minx = Min(minx, pe->bv.dnear[0]); + miny = Min(miny, pe->bv.dnear[1]); + minz = Min(minz, pe->bv.dnear[2]); - maxx = Max(maxx, pe->bv.dfar[0]); - maxy = Max(maxy, pe->bv.dfar[1]); - maxz = Max(maxz, pe->bv.dfar[2]); + maxx = Max(maxx, pe->bv.dfar[0]); + maxy = Max(maxy, pe->bv.dfar[1]); + maxz = Max(maxz, pe->bv.dfar[2]); - pe++; - } + pe++; + } - pbb->dnear[0] = minx; - pbb->dnear[1] = miny; - pbb->dnear[2] = minz; + pbb->dnear[0] = minx; + pbb->dnear[1] = miny; + pbb->dnear[2] = minz; - pbb->dfar[0] = maxx; - pbb->dfar[1] = maxy; - pbb->dfar[2] = maxz; - } + pbb->dfar[0] = maxx; + pbb->dfar[1] = maxy; + pbb->dfar[2] = maxz; + } @@ -184,20 +185,20 @@ VOID SphBoundBox(OBJECT *po) */ VOID SphNormal(IRECORD *hit, POINT Pi, POINT Ni) - { - ELEMENT *pe; - SPHERE *ps; /* Ptr to sphere data. */ + { + ELEMENT *pe; + SPHERE *ps; /* Ptr to sphere data. */ - /* Compute normal and make it a unit vector. */ + /* Compute normal and make it a unit vector. */ - pe = hit->pelem; - ps = (SPHERE *)pe->data; - VecSub(Ni, Pi, ps->center); + pe = hit->pelem; + ps = (SPHERE *)pe->data; + VecSub(Ni, Pi, ps->center); - Ni[0] /= ps->rad; - Ni[1] /= ps->rad; - Ni[2] /= ps->rad; - } + Ni[0] /= ps->rad; + Ni[1] /= ps->rad; + Ni[2] /= ps->rad; + } @@ -215,52 +216,52 @@ VOID SphNormal(IRECORD *hit, POINT Pi, POINT Ni) */ VOID SphDataNormalize(OBJECT *po, MATRIX normMat) - { - INT i; - SPHERE *ps; /* Ptr to sphere data. */ - ELEMENT *pe; /* Ptr to sphere element. */ - POINT surf_point; /* Point on surface. */ - POINT center_point; /* Center point. */ - POINT rad_vector; /* Radius vector. */ + { + INT i; + SPHERE *ps; /* Ptr to sphere data. */ + ELEMENT *pe; /* Ptr to sphere element. */ + POINT surf_point; /* Point on surface. */ + POINT center_point; /* Center point. */ + POINT rad_vector; /* Radius vector. */ - NormalizeBoundBox(&po->bv, normMat); + NormalizeBoundBox(&po->bv, normMat); - pe = po->pelem; + pe = po->pelem; - for (i = 0; i < po->numelements; i++) - { - ps = (SPHERE *)pe->data; + for (i = 0; i < po->numelements; i++) + { + ps = (SPHERE *)pe->data; - NormalizeBoundBox(&pe->bv, normMat); + NormalizeBoundBox(&pe->bv, normMat); - surf_point[0] = ps->center[0] + ps->rad; - surf_point[1] = ps->center[1]; - surf_point[2] = ps->center[2]; - surf_point[3] = 1.0; + surf_point[0] = ps->center[0] + ps->rad; + surf_point[1] = ps->center[1]; + surf_point[2] = ps->center[2]; + surf_point[3] = 1.0; - center_point[0] = ps->center[0]; - center_point[1] = ps->center[1]; - center_point[2] = ps->center[2]; - center_point[3] = 1.0; + center_point[0] = ps->center[0]; + center_point[1] = ps->center[1]; + center_point[2] = ps->center[2]; + center_point[3] = 1.0; - /* Transform center point. */ + /* Transform center point. */ - VecMatMult(center_point, normMat, center_point); - VecMatMult(surf_point, normMat, surf_point); + VecMatMult(center_point, normMat, center_point); + VecMatMult(surf_point, normMat, surf_point); - /* Find new radius. */ + /* Find new radius. */ - VecSub(rad_vector, surf_point, center_point); - VecCopy(ps->center, center_point); + VecSub(rad_vector, surf_point, center_point); + VecCopy(ps->center, center_point); - ps->rad = VecLen(rad_vector); - ps->rad2 = ps->rad * ps->rad; + ps->rad = VecLen(rad_vector); + ps->rad2 = ps->rad * ps->rad; - pe++; - } - } + pe++; + } + } @@ -286,47 +287,47 @@ VOID SphDataNormalize(OBJECT *po, MATRIX normMat) */ INT SphPeIntersect(RAY *pr, ELEMENT *pe, IRECORD *hit) - { - INT nhits; /* Number of hits. */ - REAL b, disc, t1, t2, vsq; /* Formula variables. */ - SPHERE *ps; /* Ptr to sphere data. */ - POINT V; /* C - P */ - IRECORD *sphhit; + { + INT nhits; /* Number of hits. */ + REAL b, disc, t1, t2, vsq; /* Formula variables. */ + SPHERE *ps; /* Ptr to sphere data. */ + POINT V; /* C - P */ + IRECORD *sphhit; - ps = (SPHERE *)(pe->data); - sphhit = hit; + ps = (SPHERE *)(pe->data); + sphhit = hit; - VecSub(V, ps->center, pr->P); /* Ray from origin to center.*/ - vsq = VecDot(V, V); /* Length sq of V. */ - b = VecDot(V, pr->D); /* Perpendicular scale of V. */ + VecSub(V, ps->center, pr->P); /* Ray from origin to center.*/ + vsq = VecDot(V, V); /* Length sq of V. */ + b = VecDot(V, pr->D); /* Perpendicular scale of V. */ - if (vsq > ps->rad2 && b < RAYEPS) /* Behind ray origin. */ - return (0); + if (vsq > ps->rad2 && b < RAYEPS) /* Behind ray origin. */ + return (0); - disc = b*b - vsq + ps->rad2; /* Discriminate. */ - if (disc < 0.0) /* Misses ray. */ - return (0); + disc = b*b - vsq + ps->rad2; /* Discriminate. */ + if (disc < 0.0) /* Misses ray. */ + return (0); - disc = sqrt(disc); /* Find intersection param. */ - t2 = b + disc; - t1 = b - disc; + disc = sqrt(disc); /* Find intersection param. */ + t2 = b + disc; + t1 = b - disc; - if (t2 <= RAYEPS) /* Behind ray origin. */ - return (0); + if (t2 <= RAYEPS) /* Behind ray origin. */ + return (0); - nhits = 0; - if (t1 > RAYEPS) /* Entering sphere. */ - { - IsectAdd(sphhit, t1, pe); - sphhit++; - nhits++; - } + nhits = 0; + if (t1 > RAYEPS) /* Entering sphere. */ + { + IsectAdd(sphhit, t1, pe); + sphhit++; + nhits++; + } - IsectAdd(sphhit, t2, pe); /* Exiting sphere */ - nhits++; + IsectAdd(sphhit, t2, pe); /* Exiting sphere */ + nhits++; - return (nhits); - } + return (nhits); + } @@ -345,32 +346,32 @@ INT SphPeIntersect(RAY *pr, ELEMENT *pe, IRECORD *hit) */ INT SphIntersect(RAY *pr, OBJECT *po, IRECORD *hit) - { - INT i; - INT nhits; /* # hits in sphere. */ - ELEMENT *pe; /* Ptr to sphere element. */ - IRECORD newhit[2]; /* Hit list. */ + { + INT i; + INT nhits; /* # hits in sphere. */ + ELEMENT *pe; /* Ptr to sphere element. */ + IRECORD newhit[2]; /* Hit list. */ - /* Traverse sphere list to find intersections. */ + /* Traverse sphere list to find intersections. */ - nhits = 0; - pe = po->pelem; - hit[0].t = HUGE_REAL; + nhits = 0; + pe = po->pelem; + hit[0].t = HUGE_REAL; - for (i = 0; i < po->numelements; i++) - { - if (SphPeIntersect(pr, pe, newhit)) - if (newhit[0].t < hit[0].t) - { - nhits++; - hit[0].t = newhit[0].t; - hit[0].pelem = newhit[0].pelem; - } - pe++; - } + for (i = 0; i < po->numelements; i++) + { + if (SphPeIntersect(pr, pe, newhit)) + if (newhit[0].t < hit[0].t) + { + nhits++; + hit[0].t = newhit[0].t; + hit[0].pelem = newhit[0].pelem; + } + pe++; + } - return (nhits); - } + return (nhits); + } @@ -389,56 +390,56 @@ INT SphIntersect(RAY *pr, OBJECT *po, IRECORD *hit) */ VOID SphTransform(OBJECT *po, MATRIX xtrans, MATRIX xinvT) - { - INT i; - INT numelems; /* Number of object elements. */ - REAL new_rad; - SPHERE *ps; /* Ptr to sphere data. */ - ELEMENT *pe; /* Ptr to sphere element. */ - POINT surf_point; /* Point on surface. */ - POINT center_point; /* Center_point. */ - POINT rad_vector; /* Radius vector. */ + { + INT i; + INT numelems; /* Number of object elements. */ + REAL new_rad; + SPHERE *ps; /* Ptr to sphere data. */ + ELEMENT *pe; /* Ptr to sphere element. */ + POINT surf_point; /* Point on surface. */ + POINT center_point; /* Center_point. */ + POINT rad_vector; /* Radius vector. */ - pe = po->pelem; - numelems = po->numelements; + pe = po->pelem; + numelems = po->numelements; - for (i = 0; i < numelems; i++) - { - ps = (SPHERE *)pe->data; + for (i = 0; i < numelems; i++) + { + ps = (SPHERE *)pe->data; - /* See if radius has changed with a scale. */ + /* See if radius has changed with a scale. */ - surf_point[0] = ps->center[0] + ps->rad; - surf_point[1] = ps->center[1]; - surf_point[2] = ps->center[2]; - surf_point[3] = 1.0; + surf_point[0] = ps->center[0] + ps->rad; + surf_point[1] = ps->center[1]; + surf_point[2] = ps->center[2]; + surf_point[3] = 1.0; - center_point[0] = ps->center[0]; - center_point[1] = ps->center[1]; - center_point[2] = ps->center[2]; - center_point[3] = 1.0; + center_point[0] = ps->center[0]; + center_point[1] = ps->center[1]; + center_point[2] = ps->center[2]; + center_point[3] = 1.0; - /* Transform center point. */ + /* Transform center point. */ - VecMatMult(center_point, xtrans, center_point); - VecMatMult(surf_point, xtrans, surf_point); + VecMatMult(center_point, xtrans, center_point); + VecMatMult(surf_point, xtrans, surf_point); - /* Find radius. */ + /* Find radius. */ - VecSub(rad_vector, surf_point, center_point); - VecCopy(ps->center, center_point); + VecSub(rad_vector, surf_point, center_point); + VecCopy(ps->center, center_point); - new_rad = VecLen(rad_vector); + new_rad = VecLen(rad_vector); - if (new_rad != ps->rad) - { - ps->rad = new_rad; - ps->rad2 = ps->rad * ps->rad; - } + if (new_rad != ps->rad) + { + ps->rad = new_rad; + ps->rad2 = ps->rad * ps->rad; + } - pe++; - } - } + pe++; + } + } @@ -456,35 +457,35 @@ VOID SphTransform(OBJECT *po, MATRIX xtrans, MATRIX xinvT) */ VOID SphRead(OBJECT *po, FILE *pf) - { - INT i; - INT instat; /* Input counter */ - SPHERE *ps; /* Ptr to sphere data. */ - ELEMENT *pe; /* Ptr to sphere element. */ + { + INT i; + INT instat; /* Input counter */ + SPHERE *ps; /* Ptr to sphere data. */ + ELEMENT *pe; /* Ptr to sphere element. */ - pe = po->pelem; - ps = GlobalMalloc(sizeof(SPHERE)*po->numelements, "sph.c"); + pe = po->pelem; + ps = GlobalMalloc(sizeof(SPHERE)*po->numelements, "sph.c"); - for (i = 0; i < po->numelements; i++) - { - instat = fscanf(pf,"%lf %lf %lf %lf", &(ps->center[0]), &(ps->center[1]), &(ps->center[2]), &(ps->rad)); + for (i = 0; i < po->numelements; i++) + { + instat = fscanf(pf,"%lf %lf %lf %lf", &(ps->center[0]), &(ps->center[1]), &(ps->center[2]), &(ps->rad)); - if (instat != 4) - { - printf("Error in SphRead: sphere %ld.\n", i); - exit(1); - } + if (instat != 4) + { + printf("Error in SphRead: sphere %ld.\n", i); + exit(1); + } - ps->center[3] = 1.0; /* w initialization. */ - ps->rad2 = ps->rad*ps->rad; + ps->center[3] = 1.0; /* w initialization. */ + ps->rad2 = ps->rad*ps->rad; - pe->data = (CHAR *)ps; - pe->parent = po; + pe->data = (CHAR *)ps; + pe->parent = po; - SphElementBoundBox(pe, ps); + SphElementBoundBox(pe, ps); - ps++; - pe++; - } - } + ps++; + pe++; + } + } diff --git a/splash2/codes/apps/raytrace/trace.C b/splash2/codes/apps/raytrace/trace.C index cce72a905..05270a123 100644 --- a/splash2/codes/apps/raytrace/trace.C +++ b/splash2/codes/apps/raytrace/trace.C @@ -25,9 +25,8 @@ */ -#include -#include - +#include +#include #include "rt.h" /* @@ -43,14 +42,14 @@ */ REAL frand() - { - REAL r; - static LONG lLastRand = 0; + { + REAL r; + static LONG lLastRand = 0; - lLastRand = lLastRand*214013L + 2531011L; - r = (REAL)((lLastRand >> 16) & 0x7FFF)/32768.0; - return (r); - } + lLastRand = lLastRand*214013L + 2531011L; + r = (REAL)((lLastRand >> 16) & 0x7FFF)/32768.0; + return (r); + } @@ -77,22 +76,22 @@ REAL frand() */ BOOL GetRayJobFromBundle(RAYJOB *job, INT *x, INT *y) - { - *x = job->xcurr; /* Set pixel address first. */ - *y = job->ycurr; + { + *x = job->xcurr; /* Set pixel address first. */ + *y = job->ycurr; - if ((job->y + job->ylen) == job->ycurr) /* All done? */ - return (FALSE); + if ((job->y + job->ylen) == job->ycurr) /* All done? */ + return (FALSE); - job->xcurr++; /* Update to next pixel. */ - if ((job->x +job->xlen) == job->xcurr ) - { - job->xcurr = job->x; /* Go to new scanline. */ - job->ycurr++; - } + job->xcurr++; /* Update to next pixel. */ + if ((job->x +job->xlen) == job->xcurr ) + { + job->xcurr = job->x; /* Go to new scanline. */ + job->ycurr++; + } - return (TRUE); - } + return (TRUE); + } @@ -125,66 +124,66 @@ BOOL GetRayJobFromBundle(RAYJOB *job, INT *x, INT *y) */ VOID ConvertPrimRayJobToRayMsg(RAY *ray, REAL x, REAL y) - { - VEC4 dir; - VEC4 origin; + { + VEC4 dir; + VEC4 origin; - if (View.projection == PT_PERSP) - { - dir[0] = -Display.scrHalfWidth + (x*Display.vWscale); - dir[1] = Display.scrHalfHeight - (y*Display.vHscale); - dir[2] = Display.scrDist; - dir[3] = 0.0; + if (View.projection == PT_PERSP) + { + dir[0] = -Display.scrHalfWidth + (x*Display.vWscale); + dir[1] = Display.scrHalfHeight - (y*Display.vHscale); + dir[2] = Display.scrDist; + dir[3] = 0.0; - /* Transform ray back to world. */ - TransformViewRay(dir); + /* Transform ray back to world. */ + TransformViewRay(dir); - VecNorm(dir); - VecCopy(ray->D, dir); - VecCopy(ray->P, View.eye); - } - else - { - /* Orthographic projection. */ + VecNorm(dir); + VecCopy(ray->D, dir); + VecCopy(ray->P, View.eye); + } + else + { + /* Orthographic projection. */ - dir[0] = 0.0; - dir[1] = 0.0; - dir[2] = 1.0; - dir[3] = 0.0; + dir[0] = 0.0; + dir[1] = 0.0; + dir[2] = 1.0; + dir[3] = 0.0; - /* Transform ray back to world. */ - TransformViewRay(dir); - VecNorm(dir); + /* Transform ray back to world. */ + TransformViewRay(dir); + VecNorm(dir); - VecCopy(ray->D, dir); + VecCopy(ray->D, dir); - /* Calculate origin. */ + /* Calculate origin. */ - origin[0] = -Display.scrHalfWidth + (x*Display.vWscale); - origin[1] = Display.scrHalfHeight - (y*Display.vHscale); - origin[2] = 0.0; - origin[3] = 1.0; + origin[0] = -Display.scrHalfWidth + (x*Display.vWscale); + origin[1] = Display.scrHalfHeight - (y*Display.vHscale); + origin[2] = 0.0; + origin[3] = 1.0; - /* Transform origin back to world. */ + /* Transform origin back to world. */ - TransformViewRay(origin); - VecCopy(ray->P, origin); - } + TransformViewRay(origin); + VecCopy(ray->P, origin); + } - /* Initialize other fields of ray message. */ + /* Initialize other fields of ray message. */ - ray->level = 0; - ray->weight = 1.0/(REAL)NumSubRays; + ray->level = 0; + ray->weight = 1.0/(REAL)NumSubRays; - LOCK(gm->ridlock); - ray->id = gm->rid++; - UNLOCK(gm->ridlock); + LOCK(gm->ridlock); + ray->id = gm->rid++; + UNLOCK(gm->ridlock); - ray->x = (INT)x; - ray->y = (INT)y; + ray->x = (INT)x; + ray->y = (INT)y; - } + } @@ -218,97 +217,97 @@ VOID ConvertPrimRayJobToRayMsg(RAY *ray, REAL x, REAL y) */ VOID RayTrace(INT pid) - { - INT j; - INT x, y; /* Pixel address. */ - REAL xx, yy; - VEC3 N; /* Normal at intersection. */ - VEC3 Ipoint; /* Intersection point. */ - COLOR c; /* Color for storing background. */ - RAY *ray; /* Ray pointer. */ - RAY rmsg; /* Ray message. */ - RAYJOB job; /* Ray job from work pool. */ - OBJECT *po; /* Ptr to object. */ - BOOL hit; /* An object hit? */ - IRECORD hitrecord; /* Intersection record. */ + { + INT j; + INT x, y; /* Pixel address. */ + REAL xx, yy; + VEC3 N; /* Normal at intersection. */ + VEC3 Ipoint; /* Intersection point. */ + COLOR c; /* Color for storing background. */ + RAY *ray; /* Ray pointer. */ + RAY rmsg; /* Ray message. */ + RAYJOB job; /* Ray job from work pool. */ + OBJECT *po; /* Ptr to object. */ + BOOL hit; /* An object hit? */ + IRECORD hitrecord; /* Intersection record. */ - ray = &rmsg; + ray = &rmsg; - while (GetJobs(&job, pid) != WPS_EMPTY) - { - while (GetRayJobFromBundle(&job, &x, &y)) - { - /* Convert the ray job to the ray message format. */ + while (GetJobs(&job, pid) != WPS_EMPTY) + { + while (GetRayJobFromBundle(&job, &x, &y)) + { + /* Convert the ray job to the ray message format. */ - xx = (REAL)x; - yy = (REAL)y; + xx = (REAL)x; + yy = (REAL)y; - if (AntiAlias) - for (j = 0; j < NumSubRays; j++) - { - ConvertPrimRayJobToRayMsg(ray, xx + frand(), yy + frand()); - PushRayTreeStack(ray, pid); - } - else - { - ConvertPrimRayJobToRayMsg(ray, xx, yy); - PushRayTreeStack(ray, pid); - } + if (AntiAlias) + for (j = 0; j < NumSubRays; j++) + { + ConvertPrimRayJobToRayMsg(ray, xx + frand(), yy + frand()); + PushRayTreeStack(ray, pid); + } + else + { + ConvertPrimRayJobToRayMsg(ray, xx, yy); + PushRayTreeStack(ray, pid); + } - while (PopRayTreeStack(ray, pid) != RTS_EMPTY) - { - /* Find which object is closest along the ray. */ + while (PopRayTreeStack(ray, pid) != RTS_EMPTY) + { + /* Find which object is closest along the ray. */ - switch (TraversalType) - { - case TT_LIST: - hit = Intersect(ray, &hitrecord); - break; + switch (TraversalType) + { + case TT_LIST: + hit = Intersect(ray, &hitrecord); + break; - case TT_HUG: - hit = TraverseHierarchyUniform(ray, &hitrecord, pid); - break; - } + case TT_HUG: + hit = TraverseHierarchyUniform(ray, &hitrecord, pid); + break; + } - /* Process the object ray hit. */ + /* Process the object ray hit. */ - if (hit) - { - /* - * Get parent object to be able to access - * object operations. - */ + if (hit) + { + /* + * Get parent object to be able to access + * object operations. + */ - po = hitrecord.pelem->parent; + po = hitrecord.pelem->parent; - /* Calculate intersection point. */ - RayPoint(Ipoint, ray, hitrecord.t); + /* Calculate intersection point. */ + RayPoint(Ipoint, ray, hitrecord.t); - /* Calculate normal at this point. */ - (*po->procs->normal)(&hitrecord, Ipoint, N); + /* Calculate normal at this point. */ + (*po->procs->normal)(&hitrecord, Ipoint, N); - /* Make sure normal is pointing toward ray origin. */ - if ((VecDot(ray->D, N)) > 0.0) - VecNegate(N, N); + /* Make sure normal is pointing toward ray origin. */ + if ((VecDot(ray->D, N)) > 0.0) + VecNegate(N, N); - /* - * Compute shade at this point - will process - * shadow rays and add secondary reflection - * and refraction rays to ray tree stack - */ + /* + * Compute shade at this point - will process + * shadow rays and add secondary reflection + * and refraction rays to ray tree stack + */ - Shade(Ipoint, N, ray, &hitrecord, pid); - } - else - { - /* Add background as pixel contribution. */ + Shade(Ipoint, N, ray, &hitrecord, pid); + } + else + { + /* Add background as pixel contribution. */ - VecCopy(c, View.bkg); - VecScale(c, ray->weight, c); - AddPixelColor(c, ray->x, ray->y); - } - } - } - } - } + VecCopy(c, View.bkg); + VecScale(c, ray->weight, c); + AddPixelColor(c, ray->x, ray->y); + } + } + } + } + } diff --git a/splash2/codes/apps/raytrace/tri.C b/splash2/codes/apps/raytrace/tri.C index ae680954e..3598ea6b7 100644 --- a/splash2/codes/apps/raytrace/tri.C +++ b/splash2/codes/apps/raytrace/tri.C @@ -25,11 +25,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + #define X_NORM 1 #define Y_NORM 2 #define Z_NORM 3 @@ -38,7 +39,7 @@ #define COUNTER_CLOCKWISE 2 #define INSIDE(x, a) (((a) <= 0.0 && (x) >= (a) && (x) <= 0.0) || \ - ((a) > 0.0 && (x) >= 0.0 && (x) <= (a))) + ((a) > 0.0 && (x) >= 0.0 && (x) <= (a))) /* @@ -53,9 +54,9 @@ */ CHAR *TriName() - { - return ("poly"); - } + { + return ("poly"); + } @@ -72,35 +73,35 @@ CHAR *TriName() */ VOID TriPrint(OBJECT *po) - { - INT i, j; - INT *vindex; /* Ptr to vertex index. */ - VEC3 *vlist, *vptr; /* Ptr to vertex list. */ - TRI *pt; /* Ptr to triangle data. */ - ELEMENT *pe; /* Ptr to triangle element. */ + { + INT i, j; + INT *vindex; /* Ptr to vertex index. */ + VEC3 *vlist, *vptr; /* Ptr to vertex list. */ + TRI *pt; /* Ptr to triangle data. */ + ELEMENT *pe; /* Ptr to triangle element. */ - pe = po->pelem; - fprintf(stderr, "\ttriangle: %ld triangles.\n", po->numelements); + pe = po->pelem; + fprintf(stderr, "\ttriangle: %ld triangles.\n", po->numelements); - for (i = 0; i < po->numelements; i++) - { - pt = (TRI *)pe->data; + for (i = 0; i < po->numelements; i++) + { + pt = (TRI *)pe->data; - fprintf(stderr, "\t\tVertices: 3 Plane eq: %f %f %f %f\n", pt->norm[0], pt->norm[1], pt->norm[2], pt->d); + fprintf(stderr, "\t\tVertices: 3 Plane eq: %f %f %f %f\n", pt->norm[0], pt->norm[1], pt->norm[2], pt->d); - vlist = pt->vptr; - vindex = pt->vindex; + vlist = pt->vptr; + vindex = pt->vindex; - for (j = 0; j < 3; j++) - { - vptr = vlist + (*vindex); - fprintf(stderr, "\t\t%f %f %f \n", (*vptr)[0], (*vptr)[1], (*vptr)[2]); - vindex++; - } + for (j = 0; j < 3; j++) + { + vptr = vlist + (*vindex); + fprintf(stderr, "\t\t%f %f %f \n", (*vptr)[0], (*vptr)[1], (*vptr)[2]); + vindex++; + } - pe++; - } - } + pe++; + } + } @@ -118,46 +119,46 @@ VOID TriPrint(OBJECT *po) */ VOID TriElementBoundBox(ELEMENT *pe, TRI *pt) - { - INT i; /* Index. */ - INT *vindex; /* Vertex index pointer. */ - BBOX *pbb; /* Ptr to bounding box. */ - VEC3 *vlist, *vptr; /* Vertex list pointer. */ - REAL minx, maxx; - REAL miny, maxy; - REAL minz, maxz; + { + INT i; /* Index. */ + INT *vindex; /* Vertex index pointer. */ + BBOX *pbb; /* Ptr to bounding box. */ + VEC3 *vlist, *vptr; /* Vertex list pointer. */ + REAL minx, maxx; + REAL miny, maxy; + REAL minz, maxz; - pbb = &(pe->bv); + pbb = &(pe->bv); - minx = miny = minz = HUGE_REAL; - maxx = maxy = maxz = -HUGE_REAL; + minx = miny = minz = HUGE_REAL; + maxx = maxy = maxz = -HUGE_REAL; - vlist = pt->vptr; - vindex = pt->vindex; + vlist = pt->vptr; + vindex = pt->vindex; - for (i = 0; i < 3; i++) - { - vptr = vlist + (*vindex); + for (i = 0; i < 3; i++) + { + vptr = vlist + (*vindex); - minx = Min(minx, (*vptr)[0]); - miny = Min(miny, (*vptr)[1]); - minz = Min(minz, (*vptr)[2]); + minx = Min(minx, (*vptr)[0]); + miny = Min(miny, (*vptr)[1]); + minz = Min(minz, (*vptr)[2]); - maxx = Max(maxx, (*vptr)[0]); - maxy = Max(maxy, (*vptr)[1]); - maxz = Max(maxz, (*vptr)[2]); + maxx = Max(maxx, (*vptr)[0]); + maxy = Max(maxy, (*vptr)[1]); + maxz = Max(maxz, (*vptr)[2]); - vindex++; - } + vindex++; + } - pbb->dnear[0] = minx; - pbb->dnear[1] = miny; - pbb->dnear[2] = minz; + pbb->dnear[0] = minx; + pbb->dnear[1] = miny; + pbb->dnear[2] = minz; - pbb->dfar[0] = maxx; - pbb->dfar[1] = maxy; - pbb->dfar[2] = maxz; - } + pbb->dfar[0] = maxx; + pbb->dfar[1] = maxy; + pbb->dfar[2] = maxz; + } @@ -174,45 +175,45 @@ VOID TriElementBoundBox(ELEMENT *pe, TRI *pt) */ VOID TriBoundBox(OBJECT *po) - { - INT i; - TRI *pt; /* Ptr to triangle data. */ - ELEMENT *pe; /* Ptr to triangle element. */ - BBOX *pbb; /* Ptr to bounding box. */ - REAL minx, maxx; - REAL miny, maxy; - REAL minz, maxz; + { + INT i; + TRI *pt; /* Ptr to triangle data. */ + ELEMENT *pe; /* Ptr to triangle element. */ + BBOX *pbb; /* Ptr to bounding box. */ + REAL minx, maxx; + REAL miny, maxy; + REAL minz, maxz; - pe = po->pelem; - pbb = &(po->bv); + pe = po->pelem; + pbb = &(po->bv); - minx = miny = minz = HUGE_REAL; - maxx = maxy = maxz = -HUGE_REAL; + minx = miny = minz = HUGE_REAL; + maxx = maxy = maxz = -HUGE_REAL; - for (i = 0; i < po->numelements; i++) - { - pt = (TRI *)pe->data; - TriElementBoundBox(pe, pt); + for (i = 0; i < po->numelements; i++) + { + pt = (TRI *)pe->data; + TriElementBoundBox(pe, pt); - minx = Min(minx, pe->bv.dnear[0]); - miny = Min(miny, pe->bv.dnear[1]); - minz = Min(minz, pe->bv.dnear[2]); + minx = Min(minx, pe->bv.dnear[0]); + miny = Min(miny, pe->bv.dnear[1]); + minz = Min(minz, pe->bv.dnear[2]); - maxx = Max(maxx, pe->bv.dfar[0]); - maxy = Max(maxy, pe->bv.dfar[1]); - maxz = Max(maxz, pe->bv.dfar[2]); + maxx = Max(maxx, pe->bv.dfar[0]); + maxy = Max(maxy, pe->bv.dfar[1]); + maxz = Max(maxz, pe->bv.dfar[2]); - pe++; - } + pe++; + } - pbb->dnear[0] = minx; - pbb->dnear[1] = miny; - pbb->dnear[2] = minz; + pbb->dnear[0] = minx; + pbb->dnear[1] = miny; + pbb->dnear[2] = minz; - pbb->dfar[0] = maxx; - pbb->dfar[1] = maxy; - pbb->dfar[2] = maxz; - } + pbb->dfar[0] = maxx; + pbb->dfar[1] = maxy; + pbb->dfar[2] = maxz; + } @@ -235,63 +236,63 @@ VOID TriBoundBox(OBJECT *po) */ VOID TriNormal(IRECORD *hit, POINT Pi, POINT Ni) - { - ELEMENT *pe; - TRI *pt; /* Ptr to triangle data. */ - VEC3 *pn; /* Ptr to normal. */ - VEC3 *n0, *n1, *n2; + { + ELEMENT *pe; + TRI *pt; /* Ptr to triangle data. */ + VEC3 *pn; /* Ptr to normal. */ + VEC3 *n0, *n1, *n2; - /* Retrieve normal from hit triangle. */ + /* Retrieve normal from hit triangle. */ - pe = hit->pelem; - pt = (TRI *)pe->data; - pn = pt->nptr; + pe = hit->pelem; + pt = (TRI *)pe->data; + pn = pt->nptr; - if (pt->norminterp) - { - if (pt->vorder == CLOCKWISE) - { - n0 = pn + pt->vindex[0]; - n1 = pn + pt->vindex[1]; - n2 = pn + pt->vindex[2]; - } - else - { - n0 = pn + pt->vindex[0]; - n1 = pn + pt->vindex[2]; - n2 = pn + pt->vindex[1]; - } + if (pt->norminterp) + { + if (pt->vorder == CLOCKWISE) + { + n0 = pn + pt->vindex[0]; + n1 = pn + pt->vindex[1]; + n2 = pn + pt->vindex[2]; + } + else + { + n0 = pn + pt->vindex[0]; + n1 = pn + pt->vindex[2]; + n2 = pn + pt->vindex[1]; + } - switch (pt->indx) - { - case X_NORM: - hit->b1 /= pt->norm[0]; - hit->b2 /= pt->norm[0]; - hit->b3 /= pt->norm[0]; - break; + switch (pt->indx) + { + case X_NORM: + hit->b1 /= pt->norm[0]; + hit->b2 /= pt->norm[0]; + hit->b3 /= pt->norm[0]; + break; - case Y_NORM: - hit->b1 /= pt->norm[1]; - hit->b2 /= pt->norm[1]; - hit->b3 /= pt->norm[1]; - break; + case Y_NORM: + hit->b1 /= pt->norm[1]; + hit->b2 /= pt->norm[1]; + hit->b3 /= pt->norm[1]; + break; - case Z_NORM: - hit->b1 /= pt->norm[2]; - hit->b2 /= pt->norm[2]; - hit->b3 /= pt->norm[2]; - break; - } + case Z_NORM: + hit->b1 /= pt->norm[2]; + hit->b2 /= pt->norm[2]; + hit->b3 /= pt->norm[2]; + break; + } - Ni[0] = hit->b1 * (*n0)[0] + hit->b2 * (*n1)[0] + hit->b3 * (*n2)[0]; - Ni[1] = hit->b1 * (*n0)[1] + hit->b2 * (*n1)[1] + hit->b3 * (*n2)[1]; - Ni[2] = hit->b1 * (*n0)[2] + hit->b2 * (*n1)[2] + hit->b3 * (*n2)[2]; + Ni[0] = hit->b1 * (*n0)[0] + hit->b2 * (*n1)[0] + hit->b3 * (*n2)[0]; + Ni[1] = hit->b1 * (*n0)[1] + hit->b2 * (*n1)[1] + hit->b3 * (*n2)[1]; + Ni[2] = hit->b1 * (*n0)[2] + hit->b2 * (*n1)[2] + hit->b3 * (*n2)[2]; - VecNorm(Ni); - } - else - VecCopy(Ni, pt->norm); - } + VecNorm(Ni); + } + else + VecCopy(Ni, pt->norm); + } @@ -309,65 +310,65 @@ VOID TriNormal(IRECORD *hit, POINT Pi, POINT Ni) */ VOID TriDataNormalize(OBJECT *po, MATRIX normMat) - { - INT i; - POINT coord; - VEC3 *pv; /* Ptr to vertex list. */ - TRI *pt; /* Ptr to triangle data. */ - ELEMENT *pe; /* Ptr to triangle element. */ + { + INT i; + POINT coord; + VEC3 *pv; /* Ptr to vertex list. */ + TRI *pt; /* Ptr to triangle data. */ + ELEMENT *pe; /* Ptr to triangle element. */ - /* Normalize bounding box. */ + /* Normalize bounding box. */ - pe = po->pelem; - NormalizeBoundBox(&po->bv, normMat); + pe = po->pelem; + NormalizeBoundBox(&po->bv, normMat); - /* Normalize vertex list. */ + /* Normalize vertex list. */ - pt = (TRI *)pe->data; - pv = pt->vptr; + pt = (TRI *)pe->data; + pv = pt->vptr; - coord[0] = (*pv)[0]; - coord[1] = (*pv)[1]; - coord[2] = (*pv)[2]; - coord[3] = 1.0; + coord[0] = (*pv)[0]; + coord[1] = (*pv)[1]; + coord[2] = (*pv)[2]; + coord[3] = 1.0; - /* Transform coordinate by xform matrix. */ + /* Transform coordinate by xform matrix. */ - while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL) - { - VecMatMult(coord, normMat, coord); + while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL) + { + VecMatMult(coord, normMat, coord); - (*pv)[0] = coord[0]; - (*pv)[1] = coord[1]; - (*pv)[2] = coord[2]; + (*pv)[0] = coord[0]; + (*pv)[1] = coord[1]; + (*pv)[2] = coord[2]; - pv++; + pv++; - coord[0] = (*pv)[0]; - coord[1] = (*pv)[1]; - coord[2] = (*pv)[2]; - coord[3] = 1.0; - } + coord[0] = (*pv)[0]; + coord[1] = (*pv)[1]; + coord[2] = (*pv)[2]; + coord[3] = 1.0; + } - /* Normalize bounding boxes of object elements. */ + /* Normalize bounding boxes of object elements. */ - for (i = 0; i < po->numelements; i++) - { - pt = (TRI *)pe->data; - NormalizeBoundBox(&pe->bv, normMat); + for (i = 0; i < po->numelements; i++) + { + pt = (TRI *)pe->data; + NormalizeBoundBox(&pe->bv, normMat); - /* Find new d of plane equation. */ + /* Find new d of plane equation. */ - pv = pt->vptr + (*(pt->vindex)); - pt->d = -(pt->norm[0]*(*pv)[0] + pt->norm[1]*(*pv)[1] + pt->norm[2]*(*pv)[2]); + pv = pt->vptr + (*(pt->vindex)); + pt->d = -(pt->norm[0]*(*pv)[0] + pt->norm[1]*(*pv)[1] + pt->norm[2]*(*pv)[2]); - pe++; - } - } + pe++; + } + } @@ -390,121 +391,121 @@ VOID TriDataNormalize(OBJECT *po, MATRIX normMat) */ INT TriPeIntersect(RAY *pr, ELEMENT *pe, IRECORD *hit) - { - REAL Rd_dot_Pn; /* Polygon normal dot ray direction. */ - REAL Ro_dot_Pn; /* Polygon normal dot ray origin. */ - REAL q1, q2; - REAL tval; /* Intersection t distance value. */ - VEC3 *v1, *v2, *v3; /* Vertex list pointers. */ - VEC3 e1, e2, e3; /* Edge vectors. */ - TRI *pt; /* Ptr to triangle data. */ + { + REAL Rd_dot_Pn; /* Polygon normal dot ray direction. */ + REAL Ro_dot_Pn; /* Polygon normal dot ray origin. */ + REAL q1, q2; + REAL tval; /* Intersection t distance value. */ + VEC3 *v1, *v2, *v3; /* Vertex list pointers. */ + VEC3 e1, e2, e3; /* Edge vectors. */ + TRI *pt; /* Ptr to triangle data. */ - pt = (TRI *)pe->data; + pt = (TRI *)pe->data; - Rd_dot_Pn = VecDot(pt->norm, pr->D); + Rd_dot_Pn = VecDot(pt->norm, pr->D); - if (ABS(Rd_dot_Pn) < RAYEPS) /* Ray is parallel. */ - return (0); + if (ABS(Rd_dot_Pn) < RAYEPS) /* Ray is parallel. */ + return (0); - Ro_dot_Pn = VecDot(pt->norm, pr->P); + Ro_dot_Pn = VecDot(pt->norm, pr->P); - tval = -(pt->d + Ro_dot_Pn)/Rd_dot_Pn; /* Intersection distance. */ - if (tval < RAYEPS) /* Intersects behind ray. */ - return (0); + tval = -(pt->d + Ro_dot_Pn)/Rd_dot_Pn; /* Intersection distance. */ + if (tval < RAYEPS) /* Intersects behind ray. */ + return (0); - /* - * This algorithm works for vertices in counter-clockwise order, - * so reverse the vertices if they are clockwise. - */ + /* + * This algorithm works for vertices in counter-clockwise order, + * so reverse the vertices if they are clockwise. + */ - v1 = pt->vptr + pt->vindex[0]; /* Compute first vertex pointer. */ + v1 = pt->vptr + pt->vindex[0]; /* Compute first vertex pointer. */ - if (pt->vorder == COUNTER_CLOCKWISE) - { - v2 = pt->vptr + pt->vindex[2]; - v3 = pt->vptr + pt->vindex[1]; - } - else - { - v2 = pt->vptr + pt->vindex[1]; - v3 = pt->vptr + pt->vindex[2]; - } + if (pt->vorder == COUNTER_CLOCKWISE) + { + v2 = pt->vptr + pt->vindex[2]; + v3 = pt->vptr + pt->vindex[1]; + } + else + { + v2 = pt->vptr + pt->vindex[1]; + v3 = pt->vptr + pt->vindex[2]; + } - e1[0] = (*v2)[0] - (*v1)[0]; - e1[1] = (*v2)[1] - (*v1)[1]; - e1[2] = (*v2)[2] - (*v1)[2]; + e1[0] = (*v2)[0] - (*v1)[0]; + e1[1] = (*v2)[1] - (*v1)[1]; + e1[2] = (*v2)[2] - (*v1)[2]; - e2[0] = (*v3)[0] - (*v2)[0]; - e2[1] = (*v3)[1] - (*v2)[1]; - e2[2] = (*v3)[2] - (*v2)[2]; + e2[0] = (*v3)[0] - (*v2)[0]; + e2[1] = (*v3)[1] - (*v2)[1]; + e2[2] = (*v3)[2] - (*v2)[2]; - e3[0] = (*v1)[0] - (*v3)[0]; - e3[1] = (*v1)[1] - (*v3)[1]; - e3[2] = (*v1)[2] - (*v3)[2]; + e3[0] = (*v1)[0] - (*v3)[0]; + e3[1] = (*v1)[1] - (*v3)[1]; + e3[2] = (*v1)[2] - (*v3)[2]; - /* Triangle containment. */ + /* Triangle containment. */ - switch (pt->indx) - { - case X_NORM: - q1 = pr->P[1] + tval*pr->D[1]; - q2 = pr->P[2] + tval*pr->D[2]; + switch (pt->indx) + { + case X_NORM: + q1 = pr->P[1] + tval*pr->D[1]; + q2 = pr->P[2] + tval*pr->D[2]; - hit->b1 = e2[1] * (q2 - (*v2)[2]) - e2[2] * (q1 - (*v2)[1]); - if (!INSIDE(hit->b1, pt->norm[0])) - return (0); + hit->b1 = e2[1] * (q2 - (*v2)[2]) - e2[2] * (q1 - (*v2)[1]); + if (!INSIDE(hit->b1, pt->norm[0])) + return (0); - hit->b2 = e3[1] * (q2 - (*v3)[2]) - e3[2] * (q1 - (*v3)[1]); - if (!INSIDE(hit->b2, pt->norm[0])) - return (0); + hit->b2 = e3[1] * (q2 - (*v3)[2]) - e3[2] * (q1 - (*v3)[1]); + if (!INSIDE(hit->b2, pt->norm[0])) + return (0); - hit->b3 = e1[1] * (q2 - (*v1)[2]) - e1[2] * (q1 - (*v1)[1]); - if (!INSIDE(hit->b3, pt->norm[0])) - return (0); - break; + hit->b3 = e1[1] * (q2 - (*v1)[2]) - e1[2] * (q1 - (*v1)[1]); + if (!INSIDE(hit->b3, pt->norm[0])) + return (0); + break; - case Y_NORM: - q1 = pr->P[0] + tval*pr->D[0]; - q2 = pr->P[2] + tval*pr->D[2]; + case Y_NORM: + q1 = pr->P[0] + tval*pr->D[0]; + q2 = pr->P[2] + tval*pr->D[2]; - hit->b1 = e2[2] * (q1 - (*v2)[0]) - e2[0] * (q2 - (*v2)[2]); - if (!INSIDE(hit->b1, pt->norm[1])) - return (0); + hit->b1 = e2[2] * (q1 - (*v2)[0]) - e2[0] * (q2 - (*v2)[2]); + if (!INSIDE(hit->b1, pt->norm[1])) + return (0); - hit->b2 = e3[2] * (q1 - (*v3)[0]) - e3[0] * (q2 - (*v3)[2]); - if (!INSIDE(hit->b2, pt->norm[1])) - return (0); + hit->b2 = e3[2] * (q1 - (*v3)[0]) - e3[0] * (q2 - (*v3)[2]); + if (!INSIDE(hit->b2, pt->norm[1])) + return (0); - hit->b3 = e1[2] * (q1 - (*v1)[0]) - e1[0] * (q2 - (*v1)[2]); - if (!INSIDE(hit->b3, pt->norm[1])) - return (0); - break; + hit->b3 = e1[2] * (q1 - (*v1)[0]) - e1[0] * (q2 - (*v1)[2]); + if (!INSIDE(hit->b3, pt->norm[1])) + return (0); + break; - case Z_NORM: - q1 = pr->P[0] + tval*pr->D[0]; - q2 = pr->P[1] + tval*pr->D[1]; + case Z_NORM: + q1 = pr->P[0] + tval*pr->D[0]; + q2 = pr->P[1] + tval*pr->D[1]; - hit->b1 = e2[0] * (q2 - (*v2)[1]) - e2[1] * (q1 - (*v2)[0]); - if (!INSIDE(hit->b1, pt->norm[2])) - return (0); + hit->b1 = e2[0] * (q2 - (*v2)[1]) - e2[1] * (q1 - (*v2)[0]); + if (!INSIDE(hit->b1, pt->norm[2])) + return (0); - hit->b2 = e3[0] * (q2 - (*v3)[1]) - e3[1] * (q1 - (*v3)[0]); - if (!INSIDE(hit->b2, pt->norm[2])) - return (0); + hit->b2 = e3[0] * (q2 - (*v3)[1]) - e3[1] * (q1 - (*v3)[0]); + if (!INSIDE(hit->b2, pt->norm[2])) + return (0); - hit->b3 = e1[0] * (q2 - (*v1)[1]) - e1[1] * (q1 - (*v1)[0]); - if (!INSIDE(hit->b3, pt->norm[2])) - return (0); - break; - } + hit->b3 = e1[0] * (q2 - (*v1)[1]) - e1[1] * (q1 - (*v1)[0]); + if (!INSIDE(hit->b3, pt->norm[2])) + return (0); + break; + } - IsectAdd(hit, tval, pe); - return (1); - } + IsectAdd(hit, tval, pe); + return (1); + } @@ -523,32 +524,32 @@ INT TriPeIntersect(RAY *pr, ELEMENT *pe, IRECORD *hit) */ INT TriIntersect(RAY *pr, OBJECT *po, IRECORD *hit) - { - INT i; - INT nhits; /* # hits in polyhedra. */ - ELEMENT *pe; /* Ptr to triangle element. */ - IRECORD newhit; /* Hit list. */ + { + INT i; + INT nhits; /* # hits in polyhedra. */ + ELEMENT *pe; /* Ptr to triangle element. */ + IRECORD newhit; /* Hit list. */ - /* Traverse triangle list to find intersections. */ + /* Traverse triangle list to find intersections. */ - nhits = 0; - pe = po->pelem; - hit[0].t = HUGE_REAL; + nhits = 0; + pe = po->pelem; + hit[0].t = HUGE_REAL; - for (i = 0; i < po->numelements; i++) - { - if (TriPeIntersect(pr, pe, &newhit)) - { - nhits++; - if (newhit.t < hit[0].t) - hit[0] = newhit; - } + for (i = 0; i < po->numelements; i++) + { + if (TriPeIntersect(pr, pe, &newhit)) + { + nhits++; + if (newhit.t < hit[0].t) + hit[0] = newhit; + } - pe++; - } + pe++; + } - return (nhits); - } + return (nhits); + } @@ -573,131 +574,131 @@ INT TriIntersect(RAY *pr, OBJECT *po, IRECORD *hit) */ VOID TriTransform(OBJECT *po, MATRIX xtrans, MATRIX xinvT) - { - INT i; /* Indices. */ - INT numelems; /* # of elements. */ - INT *vindex; /* Vertex index pointer. */ - VEC3 *vptr, *vp; /* Vertex list pointers. */ - VEC3 *nptr, *np; /* Normal list pointers. */ - VEC3 *vp1, *vp2, *vp3; - VEC3 vec1, vec2; - VEC4 pnorm; - VEC4 norm, coord; /* Transform 4 vectors. */ - TRI *pt; /* Ptr to triangle data. */ - ELEMENT *pe; /* Ptr to triangle element. */ + { + INT i; /* Indices. */ + INT numelems; /* # of elements. */ + INT *vindex; /* Vertex index pointer. */ + VEC3 *vptr, *vp; /* Vertex list pointers. */ + VEC3 *nptr, *np; /* Normal list pointers. */ + VEC3 *vp1, *vp2, *vp3; + VEC3 vec1, vec2; + VEC4 pnorm; + VEC4 norm, coord; /* Transform 4 vectors. */ + TRI *pt; /* Ptr to triangle data. */ + ELEMENT *pe; /* Ptr to triangle element. */ - pe = po->pelem; - numelems = po->numelements; + pe = po->pelem; + numelems = po->numelements; - /* Get vertex list address and transform vertices. */ + /* Get vertex list address and transform vertices. */ - pt = (TRI *)pe->data; - vptr = pt->vptr; - nptr = pt->nptr; + pt = (TRI *)pe->data; + vptr = pt->vptr; + nptr = pt->nptr; - coord[0] = (*vptr)[0]; - coord[1] = (*vptr)[1]; - coord[2] = (*vptr)[2]; - coord[3] = 1.0; + coord[0] = (*vptr)[0]; + coord[1] = (*vptr)[1]; + coord[2] = (*vptr)[2]; + coord[3] = 1.0; - while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL) - { - /* Transform coordinate by xform matrix. */ + while (coord[0] != HUGE_REAL && coord[1] != HUGE_REAL && coord[2] != HUGE_REAL) + { + /* Transform coordinate by xform matrix. */ - VecMatMult(coord, xtrans, coord); + VecMatMult(coord, xtrans, coord); - (*vptr)[0] = coord[0]; - (*vptr)[1] = coord[1]; - (*vptr)[2] = coord[2]; + (*vptr)[0] = coord[0]; + (*vptr)[1] = coord[1]; + (*vptr)[2] = coord[2]; - vptr++; + vptr++; - coord[0] = (*vptr)[0]; - coord[1] = (*vptr)[1]; - coord[2] = (*vptr)[2]; - coord[3] = 1.0; + coord[0] = (*vptr)[0]; + coord[1] = (*vptr)[1]; + coord[2] = (*vptr)[2]; + coord[3] = 1.0; - /* Transform normals. */ + /* Transform normals. */ - norm[0] = (*nptr)[0]; - norm[1] = (*nptr)[1]; - norm[2] = (*nptr)[2]; - norm[3] = 0.0; + norm[0] = (*nptr)[0]; + norm[1] = (*nptr)[1]; + norm[2] = (*nptr)[2]; + norm[3] = 0.0; - VecMatMult(norm, xinvT, norm); - VecNorm(norm); + VecMatMult(norm, xinvT, norm); + VecNorm(norm); - (*nptr)[0] = norm[0]; - (*nptr)[1] = norm[1]; - (*nptr)[2] = norm[2]; + (*nptr)[0] = norm[0]; + (*nptr)[1] = norm[1]; + (*nptr)[2] = norm[2]; - nptr++; - } + nptr++; + } - /* Transform triangle list. */ + /* Transform triangle list. */ - for (i = 0; i < numelems; i++) - { - pt = (TRI *)pe->data; + for (i = 0; i < numelems; i++) + { + pt = (TRI *)pe->data; - vindex = pt->vindex; - vptr = pt->vptr; - vp1 = vptr + (*vindex); + vindex = pt->vindex; + vptr = pt->vptr; + vp1 = vptr + (*vindex); - vindex++; - vp2 = vptr + (*vindex); - VecSub(vec1, (*vp2), (*vp1)); + vindex++; + vp2 = vptr + (*vindex); + VecSub(vec1, (*vp2), (*vp1)); - vindex++; - vp3 = vptr + (*vindex); - VecSub(vec2, (*vp3), (*vp1)); + vindex++; + vp3 = vptr + (*vindex); + VecSub(vec2, (*vp3), (*vp1)); - VecCross(pt->norm, vec1, vec2); + VecCross(pt->norm, vec1, vec2); - /* Calculate plane equation variable D. */ + /* Calculate plane equation variable D. */ - vp = pt->vptr + *(pt->vindex); + vp = pt->vptr + *(pt->vindex); - pt->d = -(pt->norm[0]*(*vp)[0] + pt->norm[1]*(*vp)[1] + pt->norm[2]*(*vp)[2]); + pt->d = -(pt->norm[0]*(*vp)[0] + pt->norm[1]*(*vp)[1] + pt->norm[2]*(*vp)[2]); - if (pt->norminterp) - { - vindex = pt->vindex; - np = pt->nptr + (*vindex); + if (pt->norminterp) + { + vindex = pt->vindex; + np = pt->nptr + (*vindex); - VecCopy(pnorm, pt->norm); - VecNorm(pnorm); + VecCopy(pnorm, pt->norm); + VecNorm(pnorm); - if (VecDot(pnorm, (*np)) >= 0.0) - pt->vorder = CLOCKWISE; - else - { - pt->vorder = COUNTER_CLOCKWISE; - VecScale(pt->norm, -1.0, pt->norm); - pt->d = -pt->d; - } - } + if (VecDot(pnorm, (*np)) >= 0.0) + pt->vorder = CLOCKWISE; + else + { + pt->vorder = COUNTER_CLOCKWISE; + VecScale(pt->norm, -1.0, pt->norm); + pt->d = -pt->d; + } + } - /* Set best axis projection. */ + /* Set best axis projection. */ - norm[0] = ABS(pt->norm[0]); - norm[1] = ABS(pt->norm[1]); - norm[2] = ABS(pt->norm[2]); + norm[0] = ABS(pt->norm[0]); + norm[1] = ABS(pt->norm[1]); + norm[2] = ABS(pt->norm[2]); - if (norm[0] >= norm[1] && norm[0] >= norm[2]) - pt->indx = X_NORM; - else - if (norm[1] >= norm[0] && norm[1] >= norm[2]) - pt->indx = Y_NORM; - else - pt->indx = Z_NORM; + if (norm[0] >= norm[1] && norm[0] >= norm[2]) + pt->indx = X_NORM; + else + if (norm[1] >= norm[0] && norm[1] >= norm[2]) + pt->indx = Y_NORM; + else + pt->indx = Z_NORM; - pe++; - } - } + pe++; + } + } @@ -715,136 +716,136 @@ VOID TriTransform(OBJECT *po, MATRIX xtrans, MATRIX xinvT) */ VOID TriRead(OBJECT *po, FILE *pf) - { - INT i; /* Indices. */ - INT instat; /* Read status. */ - INT totalverts; /* Total # of vertices in tri mesh. */ - CHAR normstr[5]; /* Face/vertex normal flag string. */ - BOOL pnormals; /* Face normals present? */ - BOOL vnormals; /* Vertex normals present? */ - VEC3 *vlist, *vptr; /* Ptr to vertex list. */ - VEC3 *nlist, *nptr; /* Ptr to normal list. */ - TRI *pt; /* Ptr to triangle data. */ - ELEMENT *pe; /* Ptr to triangle element. */ + { + INT i; /* Indices. */ + INT instat; /* Read status. */ + INT totalverts; /* Total # of vertices in tri mesh. */ + CHAR normstr[5]; /* Face/vertex normal flag string. */ + BOOL pnormals; /* Face normals present? */ + BOOL vnormals; /* Vertex normals present? */ + VEC3 *vlist, *vptr; /* Ptr to vertex list. */ + VEC3 *nlist, *nptr; /* Ptr to normal list. */ + TRI *pt; /* Ptr to triangle data. */ + ELEMENT *pe; /* Ptr to triangle element. */ - pe = po->pelem; + pe = po->pelem; - /* Allocate space for object data. */ + /* Allocate space for object data. */ - instat = fscanf(pf, "%ld", &totalverts); + instat = fscanf(pf, "%ld", &totalverts); - if (instat != 1) - { - printf("Error in TriRead: totalverts.\n"); - exit(-1); - } + if (instat != 1) + { + printf("Error in TriRead: totalverts.\n"); + exit(-1); + } - pt = GlobalMalloc(sizeof(TRI )*po->numelements, "tri.c"); - vlist = GlobalMalloc(sizeof(VEC3)*(totalverts + 1), "tri.c"); - nlist = GlobalMalloc(sizeof(VEC3)*totalverts, "tri.c"); + pt = GlobalMalloc(sizeof(TRI )*po->numelements, "tri.c"); + vlist = GlobalMalloc(sizeof(VEC3)*(totalverts + 1), "tri.c"); + nlist = GlobalMalloc(sizeof(VEC3)*totalverts, "tri.c"); - vptr = vlist; - nptr = nlist; + vptr = vlist; + nptr = nlist; - /* Are triangle face normals supplied? */ + /* Are triangle face normals supplied? */ - instat = fscanf(pf, "%s\n", normstr); + instat = fscanf(pf, "%s\n", normstr); - if (instat != 1) - { - printf("Error in TriRead: face normal indicator.\n"); - exit(-1); - } + if (instat != 1) + { + printf("Error in TriRead: face normal indicator.\n"); + exit(-1); + } - pnormals = (normstr[2] == 'y' ? TRUE : FALSE); + pnormals = (normstr[2] == 'y' ? TRUE : FALSE); - /* Are vertex normal supplied? */ + /* Are vertex normal supplied? */ - instat = fscanf(pf, "%s\n", normstr); - if (instat != 1) - { - printf("Error in TriRead: vertex normal indicator.\n"); - exit(-1); - } + instat = fscanf(pf, "%s\n", normstr); + if (instat != 1) + { + printf("Error in TriRead: vertex normal indicator.\n"); + exit(-1); + } - vnormals = (normstr[2] == 'y' ? TRUE : FALSE); + vnormals = (normstr[2] == 'y' ? TRUE : FALSE); - /* Read vertex list. */ + /* Read vertex list. */ - for (i = 0; i < totalverts; i++) - { - instat = fscanf(pf, "%lf %lf %lf", &(*vptr)[0], &(*vptr)[1], &(*vptr)[2]); + for (i = 0; i < totalverts; i++) + { + instat = fscanf(pf, "%lf %lf %lf", &(*vptr)[0], &(*vptr)[1], &(*vptr)[2]); - if (instat != 3) - { - printf("Error in TriRead: vertex %ld.\n", i); - exit(-1); - } + if (instat != 3) + { + printf("Error in TriRead: vertex %ld.\n", i); + exit(-1); + } - if (vnormals) - { - instat = fscanf(pf, "%lf %lf %lf", &(*nptr)[0], &(*nptr)[1], &(*nptr)[2]); + if (vnormals) + { + instat = fscanf(pf, "%lf %lf %lf", &(*nptr)[0], &(*nptr)[1], &(*nptr)[2]); - if (instat != 3) - { - printf("Error in TriRead: vertex normal %ld.\n", i); - exit(-1); - } + if (instat != 3) + { + printf("Error in TriRead: vertex normal %ld.\n", i); + exit(-1); + } - nptr++; - } + nptr++; + } - vptr++; - } + vptr++; + } - (*vptr)[0] = HUGE_REAL; - (*vptr)[1] = HUGE_REAL; - (*vptr)[2] = HUGE_REAL; + (*vptr)[0] = HUGE_REAL; + (*vptr)[1] = HUGE_REAL; + (*vptr)[2] = HUGE_REAL; - /* Read triangle list. */ + /* Read triangle list. */ - for (i = 0; i < po->numelements; i++) - { - if (pnormals) - { - instat = fscanf(pf, " %lf %lf %lf", &(pt->norm[0]), &(pt->norm[1]), &(pt->norm[2])); + for (i = 0; i < po->numelements; i++) + { + if (pnormals) + { + instat = fscanf(pf, " %lf %lf %lf", &(pt->norm[0]), &(pt->norm[1]), &(pt->norm[2])); - if (instat != 3) - { - printf("Error in TriRead: face normal %ld.\n", i); - exit(-1); - } - } + if (instat != 3) + { + printf("Error in TriRead: face normal %ld.\n", i); + exit(-1); + } + } - pt->vptr = vlist; - pt->nptr = nlist; - pt->norminterp = vnormals; + pt->vptr = vlist; + pt->nptr = nlist; + pt->norminterp = vnormals; - instat = fscanf(pf, "%ld %ld %ld", &(pt->vindex[0]), &(pt->vindex[1]), &(pt->vindex[2])); + instat = fscanf(pf, "%ld %ld %ld", &(pt->vindex[0]), &(pt->vindex[1]), &(pt->vindex[2])); - if (instat != 3) - { - printf("Error in TriRead: vertex index %ld.\n", i); - exit(-1); - } + if (instat != 3) + { + printf("Error in TriRead: vertex index %ld.\n", i); + exit(-1); + } - pe->data = (CHAR *)pt; - pe->parent = po; + pe->data = (CHAR *)pt; + pe->parent = po; - TriElementBoundBox(pe, pt); + TriElementBoundBox(pe, pt); - pt++; - pe++; - } + pt++; + pe++; + } - /* Free normal storage if not interpolating. */ + /* Free normal storage if not interpolating. */ - if (!vnormals) - GlobalFree(nlist); - } + if (!vnormals) + GlobalFree(nlist); + } diff --git a/splash2/codes/apps/raytrace/workpool.C b/splash2/codes/apps/raytrace/workpool.C index 4363094d2..31bc4154f 100644 --- a/splash2/codes/apps/raytrace/workpool.C +++ b/splash2/codes/apps/raytrace/workpool.C @@ -30,11 +30,12 @@ */ -#include -#include - +#include +#include #include "rt.h" + + /* * NAME * PutJob - put another job into pid's work pool @@ -64,65 +65,65 @@ */ VOID PutJob(INT xs, INT ys, INT xe, INT ye, INT xbe, INT ybe, INT pid) - { - INT i, j; - INT xb_addr, yb_addr; /* Bundle pixel address. */ - INT xb_end, yb_end; /* End bundle pixels. */ - INT xb_size, yb_size; /* Bundle size. */ - WPJOB *wpentry; /* New work pool entry. */ + { + INT i, j; + INT xb_addr, yb_addr; /* Bundle pixel address. */ + INT xb_end, yb_end; /* End bundle pixels. */ + INT xb_size, yb_size; /* Bundle size. */ + WPJOB *wpentry; /* New work pool entry. */ - /* Starting block pixel address (upper left pixel). */ + /* Starting block pixel address (upper left pixel). */ - xb_addr = xs; - yb_addr = ys; + xb_addr = xs; + yb_addr = ys; - /* Ending block pixel address (lower right pixel). */ + /* Ending block pixel address (lower right pixel). */ - xb_end = xb_addr + xe - 1; - yb_end = yb_addr + ye - 1; + xb_end = xb_addr + xe - 1; + yb_end = yb_addr + ye - 1; - for (i = 0; i < ye; i += ybe) - { - for (j = 0; j < xe; j += xbe) - { - /* Determine bundle size. */ + for (i = 0; i < ye; i += ybe) + { + for (j = 0; j < xe; j += xbe) + { + /* Determine bundle size. */ - if ((xb_addr + xbe - 1) <= xb_end) - xb_size = xbe; - else - xb_size = xb_end - xb_addr + 1; + if ((xb_addr + xbe - 1) <= xb_end) + xb_size = xbe; + else + xb_size = xb_end - xb_addr + 1; - if ((yb_addr + ybe - 1) <= yb_end) - yb_size = ybe; - else - yb_size = yb_end - yb_addr + 1; + if ((yb_addr + ybe - 1) <= yb_end) + yb_size = ybe; + else + yb_size = yb_end - yb_addr + 1; - /* Initialize work pool entry. */ + /* Initialize work pool entry. */ - wpentry = GlobalMalloc(sizeof(WPJOB), "workpool.c"); + wpentry = GlobalMalloc(sizeof(WPJOB), "workpool.c"); - wpentry->xpix = xb_addr; - wpentry->ypix = yb_addr; - wpentry->xdim = xb_size; - wpentry->ydim = yb_size; + wpentry->xpix = xb_addr; + wpentry->ypix = yb_addr; + wpentry->xdim = xb_size; + wpentry->ydim = yb_size; - /* Add to top of work pool stack. */ + /* Add to top of work pool stack. */ - if (!gm->workpool[pid][0]) - wpentry->next = NULL; - else - wpentry->next = gm->workpool[pid][0]; + if (!gm->workpool[pid][0]) + wpentry->next = NULL; + else + wpentry->next = gm->workpool[pid][0]; - gm->workpool[pid][0] = wpentry; - xb_addr += xbe; - } + gm->workpool[pid][0] = wpentry; + xb_addr += xbe; + } - xb_addr = xs; - yb_addr += ybe; - } - } + xb_addr = xs; + yb_addr += ybe; + } + } @@ -145,34 +146,34 @@ VOID PutJob(INT xs, INT ys, INT xe, INT ye, INT xbe, INT ybe, INT pid) */ INT GetJob(RAYJOB *job, INT pid) - { - WPJOB *wpentry; /* Work pool entry. */ + { + WPJOB *wpentry; /* Work pool entry. */ - ALOCK(gm->wplock, pid) - wpentry = gm->workpool[pid][0]; + ALOCK(gm->wplock, pid) + wpentry = gm->workpool[pid][0]; - if (!wpentry) - { - gm->wpstat[pid][0] = WPS_EMPTY; - AULOCK(gm->wplock, pid) - return (WPS_EMPTY); - } + if (!wpentry) + { + gm->wpstat[pid][0] = WPS_EMPTY; + AULOCK(gm->wplock, pid) + return (WPS_EMPTY); + } - gm->workpool[pid][0] = wpentry->next; - AULOCK(gm->wplock, pid) + gm->workpool[pid][0] = wpentry->next; + AULOCK(gm->wplock, pid) - /* Set up ray job information. */ + /* Set up ray job information. */ - job->x = wpentry->xpix; - job->y = wpentry->ypix; - job->xcurr = wpentry->xpix; - job->ycurr = wpentry->ypix; - job->xlen = wpentry->xdim; - job->ylen = wpentry->ydim; + job->x = wpentry->xpix; + job->y = wpentry->ypix; + job->xcurr = wpentry->xpix; + job->ycurr = wpentry->ypix; + job->xlen = wpentry->xdim; + job->ylen = wpentry->ydim; - GlobalFree(wpentry); - return (WPS_VALID); - } + GlobalFree(wpentry); + return (WPS_VALID); + } @@ -192,40 +193,40 @@ INT GetJob(RAYJOB *job, INT pid) */ INT GetJobs(RAYJOB *job, INT pid) - { - INT i; + { + INT i; - i = pid; + i = pid; - /* First, try to get job from pid's own pool (or pool 0). */ + /* First, try to get job from pid's own pool (or pool 0). */ - if (gm->wpstat[i][0] == WPS_VALID) - if (GetJob(job, i) == WPS_VALID) - { - return (WPS_VALID); - } + if (gm->wpstat[i][0] == WPS_VALID) + if (GetJob(job, i) == WPS_VALID) + { + return (WPS_VALID); + } - /* - * If that failed, try to get job from another pid's work - * pool. - */ + /* + * If that failed, try to get job from another pid's work + * pool. + */ - i = (pid + 1) % gm->nprocs; + i = (pid + 1) % gm->nprocs; - while (i != pid) - { - if (gm->wpstat[i][0] == WPS_VALID) - if (GetJob(job, i) == WPS_VALID) - { - return (WPS_VALID); - } + while (i != pid) + { + if (gm->wpstat[i][0] == WPS_VALID) + if (GetJob(job, i) == WPS_VALID) + { + return (WPS_VALID); + } - i = (i + 1) % gm->nprocs; - } + i = (i + 1) % gm->nprocs; + } - return (WPS_EMPTY); - } + return (WPS_EMPTY); + } @@ -242,17 +243,17 @@ INT GetJobs(RAYJOB *job, INT pid) */ VOID PrintWorkPool(INT pid) - { - WPJOB *j; + { + WPJOB *j; - j = gm->workpool[pid][0]; + j = gm->workpool[pid][0]; - while (j) - { - printf("Workpool entry: pid=%3ld xs=%3ld ys=%3ld xe=%3ld ye=%3ld\n", pid, j->xpix, j->ypix, j->xdim, j->ydim); - j = j->next; - } - } + while (j) + { + printf("Workpool entry: pid=%3ld xs=%3ld ys=%3ld xe=%3ld ye=%3ld\n", pid, j->xpix, j->ypix, j->xdim, j->ydim); + j = j->next; + } + } @@ -269,39 +270,39 @@ VOID PrintWorkPool(INT pid) */ VOID InitWorkPool(INT pid) - { - INT i; - INT x, y; - INT xe, ye; - INT xsize, ysize; + { + INT i; + INT x, y; + INT xe, ye; + INT xsize, ysize; - gm->wpstat[pid][0] = WPS_VALID; - gm->workpool[pid][0] = NULL; + gm->wpstat[pid][0] = WPS_VALID; + gm->workpool[pid][0] = NULL; - i = 0; - xsize = Display.xres/blockx; - ysize = Display.yres/blocky; + i = 0; + xsize = Display.xres/blockx; + ysize = Display.yres/blocky; - for (y = 0; y < Display.yres; y += ysize) - { - if (y + ysize > Display.yres) - ye = Display.yres - y; - else - ye = ysize; + for (y = 0; y < Display.yres; y += ysize) + { + if (y + ysize > Display.yres) + ye = Display.yres - y; + else + ye = ysize; - for (x = 0; x < Display.xres; x += xsize) - { - if (x + xsize > Display.xres) - xe = Display.xres - x; - else - xe = xsize; + for (x = 0; x < Display.xres; x += xsize) + { + if (x + xsize > Display.xres) + xe = Display.xres - x; + else + xe = xsize; - if (i == pid) - PutJob(x, y, xe, ye, bundlex, bundley, pid); + if (i == pid) + PutJob(x, y, xe, ye, bundlex, bundley, pid); - i = (i + 1)%gm->nprocs; - } - } + i = (i + 1)%gm->nprocs; + } + } - } + } diff --git a/splash2/codes/apps/volrend/adaptive.C b/splash2/codes/apps/volrend/adaptive.C index 53182468e..f17c49433 100644 --- a/splash2/codes/apps/volrend/adaptive.C +++ b/splash2/codes/apps/volrend/adaptive.C @@ -23,10 +23,10 @@ #include "incl.h" float invjacobian[NM][NM]; /* Jacobian matrix showing object space */ - /* d{x,y,z} per image space d{x,y,z} */ - /* [0][0] is dx(object)/dx(image) */ - /* [0][2] is dz(object)/dx(image) */ - /* [2][0] is dx(object)/dz(image) */ + /* d{x,y,z} per image space d{x,y,z} */ + /* [0][0] is dx(object)/dx(image) */ + /* [0][2] is dz(object)/dx(image) */ + /* [2][0] is dx(object)/dz(image) */ float invinvjacobian[NM][NM]; /* [i][j] = 1.0 / invjacobian[i][j] */ /* For gathering statistics: */ long num_rays_traced; /* number of calls to Trace_Ray */ @@ -75,7 +75,7 @@ void Ray_Trace(long my_node) for (i=0; i SMALL) - invinvjacobian[i][j] = 1.0 / invjacobian[i][j]; + invinvjacobian[i][j] = 1.0 / invjacobian[i][j]; } } @@ -149,8 +149,8 @@ void Ray_Trace(long my_node) LOCK(Global->CountLock); printf("%3ld\t%3ld\t%6ld\t%6ld\t%6ld\t%6ld\t%8ld\n",my_node,frame,exectime, - exectime1,num_rays_traced,num_traced_rays_hit_volume, - num_samples_trilirped); + exectime1,num_rays_traced,num_traced_rays_hit_volume, + num_samples_trilirped); UNLOCK(Global->CountLock); @@ -192,14 +192,14 @@ void Ray_Trace_Adaptively(long my_node) xindex = xstart + (work%lnum_xblocks)*block_xlen; yindex = ystart + (work/lnum_xblocks)*block_ylen; for (outy=yindex; outyQLock,local_node); work = Global->Queue[local_node][0]; @@ -213,7 +213,7 @@ void Ray_Trace_Adaptively(long my_node) } local_node = (local_node+1)%num_nodes; while (Global->Queue[local_node][0] >= lnum_blocks && - Global->Queue[num_nodes][0] > 0) + Global->Queue[num_nodes][0] > 0) local_node = (local_node+1)%num_nodes; } @@ -264,21 +264,21 @@ void Ray_Trace_Adaptive_Box(long outx, long outy, long boxlen) /*reschedule processes here if rescheduling only at synch points on simulator*/ - MASK_IMAGE(outy+i,outx+j) = START_RAY; + MASK_IMAGE(outy+i,outx+j) = START_RAY; /*reschedule processes here if rescheduling only at synch points on simulator*/ - foutx = (float)(outx+j); - fouty = (float)(outy+i); - pixel_address = IMAGE_ADDRESS(outy+i,outx+j); + foutx = (float)(outx+j); + fouty = (float)(outy+i); + pixel_address = IMAGE_ADDRESS(outy+i,outx+j); /*reschedule processes here if rescheduling only at synch points on simulator*/ - Trace_Ray(foutx,fouty,pixel_address); + Trace_Ray(foutx,fouty,pixel_address); /*reschedule processes here if rescheduling only at synch points on simulator*/ - MASK_IMAGE(outy+i,outx+j) = RAY_TRACED; + MASK_IMAGE(outy+i,outx+j) = RAY_TRACED; } } } @@ -292,7 +292,7 @@ void Ray_Trace_Adaptive_Box(long outx, long outy, long boxlen) /*reschedule processes here if rescheduling only at synch points on simulator*/ - imask = MASK_IMAGE(outy+i,outx+j); + imask = MASK_IMAGE(outy+i,outx+j); /*reschedule processes here if rescheduling only at synch points on simulator*/ @@ -318,7 +318,7 @@ void Ray_Trace_Adaptive_Box(long outx, long outy, long boxlen) half_boxlen = boxlen >> 1; for (i=0; iQLock,local_node); work = Global->Queue[local_node][0]++; @@ -375,7 +375,7 @@ void Ray_Trace_Non_Adaptively(long my_node) } local_node = (local_node+1)%num_nodes; while (Global->Queue[local_node][0] >= lnum_blocks && - Global->Queue[num_nodes][0] > 0) + Global->Queue[num_nodes][0] > 0) local_node = (local_node+1)%num_nodes; } } @@ -396,14 +396,14 @@ void Ray_Trace_Fast_Non_Adaptively(long my_node) for (outx=xindex; outx 1) { for (i=0; i>3)) + (pyr_offset1=\ + ((IZ)*pyr_len[ILEVEL][Y]+(IY))*\ + pyr_len[ILEVEL][X]+(IX),\ + pyr_offset2=pyr_offset1&7,\ + pyr_address2=pyr_address[ILEVEL]+\ + (pyr_offset1>>3)) #define PYR(ILEVEL,IZ,IY,IX)\ - (PYR_ADDRESS(ILEVEL,IZ,IY,IX),\ - (*pyr_address2>>pyr_offset2)&1) + (PYR_ADDRESS(ILEVEL,IZ,IY,IX),\ + (*pyr_address2>>pyr_offset2)&1) #define IMAGE_ADDRESS(IY,IX) (image_address+(IY)*image_len[X]+(IX)) #define IMAGE(IY,IX) (*IMAGE_ADDRESS(IY,IX)) - /* Access to mask image */ + /* Access to mask image */ #define MASK_IMAGE_ADDRESS(IY,IX) \ - (mask_image_address+\ - (IY)*mask_image_len[X]+(IX)) + (mask_image_address+\ + (IY)*mask_image_len[X]+(IX)) #define MASK_IMAGE(IY,IX) (*MASK_IMAGE_ADDRESS(IY,IX)) diff --git a/splash2/codes/apps/volrend/const.H b/splash2/codes/apps/volrend/const.H index 58089db6c..59e9644e5 100644 --- a/splash2/codes/apps/volrend/const.H +++ b/splash2/codes/apps/volrend/const.H @@ -44,13 +44,13 @@ #define YES 1 #define NO 0 - /* Definition of object space coordinates: */ + /* Definition of object space coordinates: */ #define NM 3 /* number of coordinates */ #define X 0 /* x-coordinate */ #define Y 1 /* y-coordinate */ #define Z 2 /* z-coordinate */ - /* Definition of pixel image coordinates: */ + /* Definition of pixel image coordinates: */ #define NI 2 /* number of coordinates */ /* NORMAL constant using 16-bit signed short */ @@ -71,11 +71,11 @@ #define NULL_PIXEL 0 /* initialization value for pixel */ #define PIX_CUR_VERSION 1 /* version of .pix file used */ - /* Definition of string sizes: */ + /* Definition of string sizes: */ #define FILENAME_SIZE 80 /* max user filename */ #define FILENAME_STRING_SIZE (FILENAME_SIZE+1) /* + 1 for null char */ - /* Definition of minimum and maximum values: */ + /* Definition of minimum and maximum values: */ #define MIN_DENSITY 0 /* density */ #define MAX_DENSITY 255 /* density */ #define MIN_MAGNITUDE 0 /* magnitude of density gradient */ @@ -99,5 +99,5 @@ /* operator not 5x5 */ #define MAX_PYRLEVEL 9 /* Maximum level in binary pyramid */ - /* (allows 1x1x1..512x512x512 voxels) */ + /* (allows 1x1x1..512x512x512 voxels) */ diff --git a/splash2/codes/apps/volrend/file.C b/splash2/codes/apps/volrend/file.C index 0af4245d9..cd5f0b780 100644 --- a/splash2/codes/apps/volrend/file.C +++ b/splash2/codes/apps/volrend/file.C @@ -17,7 +17,6 @@ /********** storing/loading of large arrays to/from files **********/ #include - #include "incl.h" #define PMODE 0644 /* RW for owner, R for group, R for others */ @@ -53,7 +52,7 @@ void Write_Bytes(int fd, unsigned char array[], long length) if (n_written != -1) { while (n_written < length) { more_written = write(fd,&array[n_written], - MIN(length-n_written,32766)); + MIN(length-n_written,32766)); if (more_written == -1) break; n_written += more_written; } @@ -80,7 +79,7 @@ void Write_Shorts(int fd, unsigned char array[], long length) if (n_written != -1) { while (n_written < length) { more_written = write(fd,&array[n_written], - MIN(length-n_written,32766)); + MIN(length-n_written,32766)); if (more_written == -1) break; n_written += more_written; } @@ -117,7 +116,7 @@ void Write_Longs(int fd, unsigned char array[], long length) if (n_written != -1) { while (n_written < length) { more_written = write(fd,&array[n_written], - MIN(length-n_written,32766)); + MIN(length-n_written,32766)); if (more_written == -1) break; n_written += more_written; } @@ -147,7 +146,7 @@ void Read_Bytes(int fd, unsigned char array[], long length) if (n_read != -1 && n_read != 0) { while (n_read < length) { more_read = read(fd,&array[n_read], - MIN(length-n_read,32766)); + MIN(length-n_read,32766)); if (more_read == -1 || more_read == 0) break; n_read += more_read; } @@ -167,7 +166,7 @@ void Read_Shorts(int fd, unsigned char array[], long length) if (n_read != -1 && n_read != 0) { while (n_read < length) { more_read = read(fd,&array[n_read], - MIN(length-n_read,32766)); + MIN(length-n_read,32766)); if (more_read == -1 || more_read == 0) break; n_read += more_read; } @@ -194,7 +193,7 @@ void Read_Longs(int fd, unsigned char array[], long length) if (n_read != -1 && n_read != 0) { while (n_read < length) { more_read = read(fd,&array[n_read], - MIN(length-n_read,32766)); + MIN(length-n_read,32766)); if (more_read == -1 || more_read == 0) break; n_read += more_read; } diff --git a/splash2/codes/apps/volrend/global.H b/splash2/codes/apps/volrend/global.H index 5ecc521d4..a9973526c 100644 --- a/splash2/codes/apps/volrend/global.H +++ b/splash2/codes/apps/volrend/global.H @@ -40,9 +40,9 @@ extern float density_opacity[MAX_DENSITY+1]; extern float magnitude_opacity[MAX_MAGNITUDE+1]; /* opacity as function of magnitude */ extern long density_epsilon; /* minimum (density*map_divisor) */ - /* (>= MIN_DENSITY) */ + /* (>= MIN_DENSITY) */ extern long magnitude_epsilon; /* minimum (magnitude*grd_divisor)**2 */ - /* (> MIN_MAGNITUDE) */ + /* (> MIN_MAGNITUDE) */ extern PIXEL background; /* color of background */ extern float light[NM]; /* normalized vector from object to light */ extern float ambient_color; /* color of ambient reflection */ @@ -53,31 +53,31 @@ extern float depth_hither; /* percentage of full intensity at hither */ extern float depth_yon; /* percentage of full intensity at yon */ extern float depth_exponent; /* exponent of falloff from hither to yon */ extern float opacity_epsilon; /* minimum opacity */ - /* (usually >= MIN_OPACITY, */ - /* < MIN_OPACITY during shading shades */ - /* all voxels for generation of mipmap) */ + /* (usually >= MIN_OPACITY, */ + /* < MIN_OPACITY during shading shades */ + /* all voxels for generation of mipmap) */ extern float opacity_cutoff; /* cutoff opacity */ - /* (<= MAX_OPACITY) */ + /* (<= MAX_OPACITY) */ extern long highest_sampling_boxlen; /* highest boxlen for adaptive sampling */ - /* (>= 1) */ + /* (>= 1) */ extern long lowest_volume_boxlen;/* lowest boxlen for volume data */ - /* (>= 1) */ + /* (>= 1) */ extern long volume_color_difference; - /* minimum color diff for volume data */ - /* (>= MIN_PIXEL) */ + /* minimum color diff for volume data */ + /* (>= MIN_PIXEL) */ extern float angle[NM]; /* initial viewing angle */ extern long pyr_highest_level; /* highest level of pyramid to look at */ - /* (<= MAX_PYRLEVEL) */ + /* (<= MAX_PYRLEVEL) */ extern long pyr_lowest_level; /* lowest level of pyramid to look at */ - /* (>= 0) */ + /* (>= 0) */ /* Pre_View Globals */ extern long frust_len; /* Size of clipping frustum */ - /* (mins will be 0 in this program, */ - /* {x,y}len will be <= IK{X,Y}SIZE) */ + /* (mins will be 0 in this program, */ + /* {x,y}len will be <= IK{X,Y}SIZE) */ extern float depth_cueing[MAX_OUTLEN]; - /* Pre-computed table of depth cueing */ + /* Pre-computed table of depth cueing */ extern long image_zlen; /* number of samples along viewing ray */ extern float in_max[NM]; /* Pre-computed clipping aids */ extern long opc_xlen,opc_xylen; @@ -103,47 +103,47 @@ extern float uout_invvertex[2][2][2][NM]; extern float obslight[NM]; /* observer transformed light vector */ extern float obshighlight[NM]; /* observer transformed highlight vector */ extern float invjacobian[NM][NM]; - /* Jacobian matrix showing object space */ - /* d{x,y,z} per image space d{x,y,z} */ - /* [0][0] is dx(object)/dx(image) */ - /* [0][2] is dz(object)/dx(image) */ - /* [2][0] is dx(object)/dz(image) */ + /* Jacobian matrix showing object space */ + /* d{x,y,z} per image space d{x,y,z} */ + /* [0][0] is dx(object)/dx(image) */ + /* [0][2] is dz(object)/dx(image) */ + /* [2][0] is dx(object)/dz(image) */ extern float invinvjacobian[NM][NM]; - /* [i][j] = 1.0 / invjacobian[i][j] */ + /* [i][j] = 1.0 / invjacobian[i][j] */ /* Density map globals */ extern short map_len[NM]; /* Size of this density map */ extern int map_length; /* Total number of densities in map */ - /* (= product of lens) */ + /* (= product of lens) */ extern DENSITY *map_address; /* Pointer to map */ /* Normal and gradient magnitude map globals */ extern short norm_len[NM]; /* Size of this normal map */ extern int norm_length; /* Total number of normals in map */ - /* (= NM * product of lens) */ + /* (= NM * product of lens) */ extern NORMAL *norm_address; /* Pointer to normal map */ extern float nmag_epsilon; /* Opacity map globals */ extern short opc_len[NM]; /* Size of this opacity map */ extern int opc_length; /* Total number of opacities in map */ - /* (= product of lens) */ + /* (= product of lens) */ extern OPACITY *opc_address; /* Pointer to opacity map */ /* Octree globals */ extern short pyr_levels; /* Number of levels in this pyramid */ extern short pyr_len[MAX_PYRLEVEL+1][NM]; - /* Number of voxels on each level */ + /* Number of voxels on each level */ extern short pyr_voxlen[MAX_PYRLEVEL+1][NM]; - /* Size of voxels on each level */ + /* Size of voxels on each level */ extern int pyr_length[MAX_PYRLEVEL+1]; /* Total number of bytes on this level */ - /* (= (long)((product of lens+7)/8)) */ + /* (= (long)((product of lens+7)/8)) */ extern BYTE *pyr_address[MAX_PYRLEVEL+1]; /* Pointer to binary pyramid */ - /* (only pyr_levels sets of lens, lengths, */ - /* and 3-D arrays are written to file) */ + /* (only pyr_levels sets of lens, lengths, */ + /* and 3-D arrays are written to file) */ extern long pyr_offset1; /* Bit offset of desired bit within pyramid */ extern long pyr_offset2; /* Bit offset of bit within byte */ extern BYTE *pyr_address2; /* Pointer to byte containing bit */ diff --git a/splash2/codes/apps/volrend/incl.H b/splash2/codes/apps/volrend/incl.H index da0946ac4..36be658c1 100644 --- a/splash2/codes/apps/volrend/incl.H +++ b/splash2/codes/apps/volrend/incl.H @@ -21,15 +21,13 @@ *************************************************************************/ -#include - -#include -#include /* Definitions for mathematical library */ -#include /* Definitions for standard I/O library */ - -#include "address.h" /* Map address macros */ +#include "user_options.h" /* User options defined at compile time */ #include "const.h" /* Constant definitions */ +#include "my_types.h" /* User defined type */ #include "global.h" /* Global variables */ #include "macros.h" /* Definition of general C macros */ -#include "my_types.h" /* User defined type */ -#include "user_options.h" /* User options defined at compile time */ +#include "address.h" /* Map address macros */ +#include /* Definitions for standard I/O library */ +#include /* Definitions for mathematical library */ +#include +#include diff --git a/splash2/codes/apps/volrend/main.C b/splash2/codes/apps/volrend/main.C index 4dcce66e5..f647a7701 100644 --- a/splash2/codes/apps/volrend/main.C +++ b/splash2/codes/apps/volrend/main.C @@ -26,13 +26,11 @@ *************************************************************************/ -#include -#include - -#include -#include - #include "incl.h" +#include +#include +#include +#include #include "tiffio.h" #define SH_MEM_AMT 60000000 @@ -259,35 +257,35 @@ void Render_Loop() for (step=0; stepSlaveBarrier,num_nodes); if (my_node == num_nodes-1) { - for (i=image_partition*my_node; i 1) { + if (ROTATE_STEPS > 1) { #ifdef DIM - sprintf(outfile, "%s_%ld",filename, 1000+dim*ROTATE_STEPS+step); + sprintf(outfile, "%s_%ld",filename, 1000+dim*ROTATE_STEPS+step); #else - sprintf(outfile, "%s_%ld.tiff",filename, 1000+step); + sprintf(outfile, "%s_%ld.tiff",filename, 1000+step); #endif /* Store_Image(outfile); p = image_address; for (zz = 0;zz < image_length;zz++) { tiff_image[zz] = (long) ((*p)*256*256*256 + (*p)*256*256 + - (*p)*256 + (*p)); - p++; + (*p)*256 + (*p)); + p++; } tiff_save_rgba(outfile,tiff_image,image_len[X],image_len[Y]); */ WriteGrayscaleTIFF(outfile, image_len[X],image_len[Y],image_len[X], image_address); - } else { + } else { /* Store_Image(filename); - p = image_address; + p = image_address; for (zz = 0;zz < image_length;zz++) { tiff_image[zz] = (long) ((*p)*256*256*256 + (*p)*256*256 + - (*p)*256 + (*p)); - p++; + (*p)*256 + (*p)); + p++; } tiff_save_rgba(filename,tiff_image,image_len[X],image_len[Y]); */ strcat(filename,".tiff"); WriteGrayscaleTIFF(filename, image_len[X],image_len[Y],image_len[X], image_address); - } + } } } #ifdef DIM @@ -345,21 +343,21 @@ void Error(char string[], char *arg1, char *arg2, char *arg3, char *arg4, char * #else void Error(char string[], ...) { - va_list ap; - char *arg1 = NULL, *arg2 = NULL, *arg3 = NULL, *arg4 = NULL, *arg5 = NULL, *arg6 = NULL, *arg7 = NULL, *arg8 = NULL; + va_list ap; + char *arg1 = NULL, *arg2 = NULL, *arg3 = NULL, *arg4 = NULL, *arg5 = NULL, *arg6 = NULL, *arg7 = NULL, *arg8 = NULL; - va_start(ap, string); - arg1 = va_arg(ap, char *); - arg1 = va_arg(ap, char *); - arg1 = va_arg(ap, char *); - arg1 = va_arg(ap, char *); - arg1 = va_arg(ap, char *); - arg1 = va_arg(ap, char *); - arg1 = va_arg(ap, char *); - arg1 = va_arg(ap, char *); - va_end(ap); - fprintf(stderr,string,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8); - exit(1); + va_start(ap, string); + arg1 = va_arg(ap, char *); + arg1 = va_arg(ap, char *); + arg1 = va_arg(ap, char *); + arg1 = va_arg(ap, char *); + arg1 = va_arg(ap, char *); + arg1 = va_arg(ap, char *); + arg1 = va_arg(ap, char *); + arg1 = va_arg(ap, char *); + va_end(ap); + fprintf(stderr,string,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8); + exit(1); } #endif @@ -372,7 +370,7 @@ void Allocate_Image(PIXEL **address, long length) *address = (PIXEL *)NU_MALLOC(length*sizeof(PIXEL),0); if (*address == NULL) - Error(" No space available for image.\n", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + Error(" No space available for image.\n", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); for (i=0; i - +#include #include "incl.h" /* The following declarations show the layout of the .den file. */ /* If changed, the version number must be incremented and code */ /* written to handle loading of both old and current versions. */ - /* Version for new .den files: */ + /* Version for new .den files: */ #define MAP_CUR_VERSION 1 /* Initial release */ short map_version; /* Version of this .den file */ @@ -45,10 +44,10 @@ short map_min[NM], /* Dimensions of this map */ map_len[NM]; /* lens may be != extr if warps > 0) */ short map_warps; /* Number of warps since extraction */ - /* (0 = none) */ + /* (0 = none) */ int map_length; /* Total number of densities in map */ - /* (= product of lens) */ + /* (= product of lens) */ DENSITY *map_address; /* Pointer to map */ /* End of layout of .den file. */ @@ -100,7 +99,7 @@ void Allocate_Map(address, length) long i; printf(" Allocating density map of %ld bytes...\n", - length*sizeof(DENSITY)); + length*sizeof(DENSITY)); *address = (DENSITY *)NU_MALLOC(length*sizeof(DENSITY),0); diff --git a/splash2/codes/apps/volrend/my_types.H b/splash2/codes/apps/volrend/my_types.H index 917bffd57..7008f1896 100644 --- a/splash2/codes/apps/volrend/my_types.H +++ b/splash2/codes/apps/volrend/my_types.H @@ -21,7 +21,7 @@ ******************************************************************************/ - /* Definition of user-defined types: */ + /* Definition of user-defined types: */ typedef unsigned char DENSITY; /* density */ typedef unsigned char BYTE; /* general purpose byte */ typedef signed short NORMAL; /* density normal */ diff --git a/splash2/codes/apps/volrend/normal.C b/splash2/codes/apps/volrend/normal.C index cbeeaafc9..eac2dd4da 100644 --- a/splash2/codes/apps/volrend/normal.C +++ b/splash2/codes/apps/volrend/normal.C @@ -21,22 +21,21 @@ * * ******************************************************************************/ -#include - +#include #include "incl.h" /* The following declarations show the layout of the .norm file. */ /* If changed, the version number must be incremented and code */ /* written to handle loading of both old and current versions. */ - /* Version for new .norm files: */ + /* Version for new .norm files: */ #define NORM_CUR_VERSION 1 /* Initial release */ short norm_version; /* Version of this .norm file */ short norm_len[NM]; /* Size of this normal map */ int norm_length; /* Total number of normals in map */ - /* (= NM * product of lens) */ + /* (= NM * product of lens) */ NORMAL *norm_address; /* Pointer to normal map */ /* End of layout of .norm file. */ @@ -78,7 +77,7 @@ void Allocate_Normal(address, length) long i; printf(" Allocating normal map of %ld bytes...\n", - length*sizeof(NORMAL)); + length*sizeof(NORMAL)); *address = (NORMAL *)NU_MALLOC(length*sizeof(NORMAL),0); @@ -144,32 +143,32 @@ void Normal_Compute() for (outy=ystart; outy SMALL) { - inv_mag_shift = norm_lshift/sqrt(magnitude); - if (grd_x*inv_mag_shift > 0.0) xnorm = 1; - else xnorm = 0; - ynorm = (long)(grd_y*inv_mag_shift); - znorm = (long)(grd_z*inv_mag_shift); - *local_norm_address = TADDR(znorm,ynorm,xnorm); - } - else { - *local_norm_address = TADDR(norm0,2,1); - } + local_norm_address = NORM_ADDRESS(outz,outy,outx,X); + if (magnitude > SMALL) { + inv_mag_shift = norm_lshift/sqrt(magnitude); + if (grd_x*inv_mag_shift > 0.0) xnorm = 1; + else xnorm = 0; + ynorm = (long)(grd_y*inv_mag_shift); + znorm = (long)(grd_z*inv_mag_shift); + *local_norm_address = TADDR(znorm,ynorm,xnorm); + } + else { + *local_norm_address = TADDR(norm0,2,1); + } } } } diff --git a/splash2/codes/apps/volrend/octree.C b/splash2/codes/apps/volrend/octree.C index fa6221379..07a46c860 100644 --- a/splash2/codes/apps/volrend/octree.C +++ b/splash2/codes/apps/volrend/octree.C @@ -20,19 +20,18 @@ * * ******************************************************************************/ -#include - +#include #include "incl.h" #define WRITE_PYR(IBIT,ILEVEL,IZ,IY,IX)\ - (PYR_ADDRESS(ILEVEL,IZ,IY,IX),\ - *pyr_address2|=(IBIT)< 1) { - pyr_len[level][i] = - (pyr_len[level-1][i]+1)>>1; - pyr_voxlen[level][i] = - pyr_voxlen[level-1][i]<<1; + pyr_len[level][i] = + (pyr_len[level-1][i]+1)>>1; + pyr_voxlen[level][i] = + pyr_voxlen[level-1][i]<<1; } else { - pyr_len[level][i] = - pyr_len[level-1][i]; - pyr_voxlen[level][i] = - pyr_voxlen[level-1][i]; + pyr_len[level][i] = + pyr_len[level-1][i]; + pyr_voxlen[level][i] = + pyr_voxlen[level-1][i]; } } pyr_length[level] = (pyr_len[level][X]* - pyr_len[level][Y]*pyr_len[level][Z]+7)/8; + pyr_len[level][Y]*pyr_len[level][Z]+7)/8; Allocate_Pyramid_Level(&pyr_address[level], pyr_length[level]); Compute_Pyramid_Level(level); } @@ -187,10 +186,10 @@ on all processors, then execute what's in the SERIAL_PREPROC ifdef below. for (outz=zstart; outz - +#include #include "incl.h" /* The following declarations show the layout of the .opc file. */ /* If changed, the version number must be incremented and code */ /* written to handle loading of both old and current versions. */ - /* Version for new .opc files: */ + /* Version for new .opc files: */ #define OPC_CUR_VERSION 1 /* Initial release */ short opc_version; /* Version of this .opc file */ short opc_len[NM]; /* Size of this opacity map */ int opc_length; /* Total number of opacities in map */ - /* (= product of lens) */ + /* (= product of lens) */ OPACITY *opc_address; /* Pointer to opacity map */ /* End of layout of .opc file. */ @@ -77,7 +76,7 @@ void Allocate_Opacity(address, length) long i; printf(" Allocating opacity map of %ld bytes...\n", - length*sizeof(OPACITY)); + length*sizeof(OPACITY)); *address = (OPACITY *)NU_MALLOC(length*sizeof(OPACITY),0); @@ -138,34 +137,34 @@ void Opacity_Compute() for (outy=ystart; outy density_epsilon) { + density = MAP(inz,iny,inx); + if (density > density_epsilon) { - grd_x = (float)((long)MAP(inz,iny,inx+1) - (long)MAP(inz,iny,inx-1)); - grd_y = (float)((long)MAP(inz,iny+1,inx) - (long)MAP(inz,iny-1,inx)); - grd_z = (float)((long)MAP(inz+1,iny,inx) - (long)MAP(inz-1,iny,inx)); - magnitude = grd_x*grd_x+grd_y*grd_y+grd_z*grd_z; + grd_x = (float)((long)MAP(inz,iny,inx+1) - (long)MAP(inz,iny,inx-1)); + grd_y = (float)((long)MAP(inz,iny+1,inx) - (long)MAP(inz,iny-1,inx)); + grd_z = (float)((long)MAP(inz+1,iny,inx) - (long)MAP(inz-1,iny,inx)); + magnitude = grd_x*grd_x+grd_y*grd_y+grd_z*grd_z; - /* If (magnitude*grd_divisor)**2 is small, skip voxel */ - if (magnitude > nmag_epsilon) { - magnitude = .5*sqrt(magnitude); - /* For density * magnitude (d*m) operator: */ - /* Set opacity of surface to the product of user-specified */ - /* functions of local density and gradient magnitude. */ - /* Detects both front and rear-facing surfaces. */ - opacity = density_opacity[density] * - magnitude_opacity[(long)magnitude]; - /* If opacity is small, skip shading and compositing of sample */ - if (opacity > opacity_epsilon) - OPC(outz,outy,outx) = NINT(opacity*MAX_OPC); - } - } - else - OPC(outz,outy,outx) = MIN_OPC; + /* If (magnitude*grd_divisor)**2 is small, skip voxel */ + if (magnitude > nmag_epsilon) { + magnitude = .5*sqrt(magnitude); + /* For density * magnitude (d*m) operator: */ + /* Set opacity of surface to the product of user-specified */ + /* functions of local density and gradient magnitude. */ + /* Detects both front and rear-facing surfaces. */ + opacity = density_opacity[density] * + magnitude_opacity[(long)magnitude]; + /* If opacity is small, skip shading and compositing of sample */ + if (opacity > opacity_epsilon) + OPC(outz,outy,outx) = NINT(opacity*MAX_OPC); + } + } + else + OPC(outz,outy,outx) = MIN_OPC; } } } diff --git a/splash2/codes/apps/volrend/option.C b/splash2/codes/apps/volrend/option.C index 2eeb20e23..6bb49def4 100644 --- a/splash2/codes/apps/volrend/option.C +++ b/splash2/codes/apps/volrend/option.C @@ -25,54 +25,54 @@ long block_xlen,block_ylen; BOOLEAN adaptive; /* adaptive ray tracing? */ - /* During shading: */ + /* During shading: */ long density_epsilon; /* minimum (density*map_divisor) */ - /* (>= MIN_DENSITY) */ + /* (>= MIN_DENSITY) */ long magnitude_epsilon; /* minimum (magnitude*grd_divisor)**2 */ - /* (> MIN_MAGNITUDE) */ + /* (> MIN_MAGNITUDE) */ /* Shading parameters of reflective surface: */ float density_opacity[MAX_DENSITY+1]; /* opacity as function of density */ float magnitude_opacity[MAX_MAGNITUDE+1];/* opacity as function of magnitude*/ - /* Global lighting parameters: */ + /* Global lighting parameters: */ PIXEL background; /* color of background assumed to be zero */ /* because of hack for producing final */ /* image on host from node images */ float light[NM]; /* normalized vector from object to light */ - /* Lighting parameters of reflective surface:*/ + /* Lighting parameters of reflective surface:*/ float ambient_color; /* color of ambient reflection */ float diffuse_color; /* color of diffuse reflection */ float specular_color; /* color of specular reflection */ float specular_exponent; /* exponent of specular reflection */ - /* Depth cueing parameters: */ + /* Depth cueing parameters: */ float depth_hither; /* percentage of full intensity at hither */ float depth_yon; /* percentage of full intensity at yon */ float depth_exponent; /* exponent of falloff from hither to yon */ - /* During shading, rendering, ray tracing: */ + /* During shading, rendering, ray tracing: */ float opacity_epsilon; /* minimum opacity */ - /* (usually >= MIN_OPACITY, */ - /* < MIN_OPACITY during shading shades */ - /* all voxels for generation of mipmap) */ + /* (usually >= MIN_OPACITY, */ + /* < MIN_OPACITY during shading shades */ + /* all voxels for generation of mipmap) */ - /* During rendering and ray tracing: */ + /* During rendering and ray tracing: */ float opacity_cutoff; /* cutoff opacity */ - /* (<= MAX_OPACITY) */ + /* (<= MAX_OPACITY) */ - /* During ray tracing: */ + /* During ray tracing: */ long highest_sampling_boxlen; /* highest boxlen for adaptive sampling */ - /* (>= 1) */ + /* (>= 1) */ long lowest_volume_boxlen; /* lowest boxlen for volume data */ - /* (>= 1) */ + /* (>= 1) */ long volume_color_difference; /* minimum color diff for volume data */ - /* (>= MIN_PIXEL) */ + /* (>= MIN_PIXEL) */ long pyr_highest_level; /* highest level of pyramid to look at */ - /* (<= MAX_PYRLEVEL) */ + /* (<= MAX_PYRLEVEL) */ long pyr_lowest_level; /* lowest level of pyramid to look at */ - /* (>= 0) */ + /* (>= 0) */ float angle[NM]; /* initial viewing angle */ @@ -145,8 +145,8 @@ void Init_Lighting() light[Y] = 0.7; light[Z] = -1.0; inv_magnitude = 1.0/sqrt(light[X]*light[X] + - light[Y]*light[Y] + - light[Z]*light[Z]); + light[Y]*light[Y] + + light[Z]*light[Z]); light[X] = light[X]*inv_magnitude; light[Y] = light[Y]*inv_magnitude; light[Z] = light[Z]*inv_magnitude; diff --git a/splash2/codes/apps/volrend/raytrace.C b/splash2/codes/apps/volrend/raytrace.C index 54b9019a5..347ff59f1 100644 --- a/splash2/codes/apps/volrend/raytrace.C +++ b/splash2/codes/apps/volrend/raytrace.C @@ -27,8 +27,8 @@ extern long num_samples_trilirped; extern long traversal_time,trilirp_time,init_time,composite_time; #define VXEL(X,SIGN) ((SIGN) > 0 ? \ - (long)((X)+SMALL) : \ - (long)((X)-SMALL)) + (long)((X)+SMALL) : \ + (long)((X)-SMALL)) #define SBIT_ADDRESS(TA) (sbit_address+(TA)) #define SHD_ADDRESS(TA) (shd_address+(TA)) @@ -96,7 +96,7 @@ void Trace_Ray(foutx, fouty, pixel_address) for (i=0; i (float)(opc_len[i]-1) && - ray[1][i] > (float)(opc_len[i]-1))) - return; + ray[1][i] < 0.0) || + (ray[0][i] > (float)(opc_len[i]-1) && + ray[1][i] > (float)(opc_len[i]-1))) + return; else - continue; + continue; } rmin = (0.0 - ray[0][i]) / (ray[1][i] - ray[0][i]); rmax = ((float)(opc_len[i]-1) - ray[0][i]) / (ray[1][i] - ray[0][i]); @@ -178,8 +178,8 @@ void Trace_Ray(foutx, fouty, pixel_address) /* but use of un-OR'ed pyramid and trilirp is invalid. */ bit = PYR(level,ivoxel[Z]>>level, - ivoxel[Y]>>level, - ivoxel[X]>>level); + ivoxel[Y]>>level, + ivoxel[X]>>level); if (bit && level > pyr_lowest_level) { /* This pyramid box contains something interesting, */ @@ -199,38 +199,38 @@ void Trace_Ray(foutx, fouty, pixel_address) min_jump = BIG; if (invjacobian[Z][X] > SMALL) { jump[X] = invinvjacobian[Z][X] * - (((ROUNDDOWN(voxel[X])>>level)+1)* - pyr_voxlen[level][X]-voxel[X]); + (((ROUNDDOWN(voxel[X])>>level)+1)* + pyr_voxlen[level][X]-voxel[X]); min_jump = MIN(min_jump,jump[X]); } else if (invjacobian[Z][X] < -SMALL) { jump[X] = invinvjacobian[Z][X] * - ((STEPDOWN(voxel[X])>>level)* - pyr_voxlen[level][X]-voxel[X]); + ((STEPDOWN(voxel[X])>>level)* + pyr_voxlen[level][X]-voxel[X]); min_jump = MIN(min_jump,jump[X]); } if (invjacobian[Z][Y] > SMALL) { jump[Y] = invinvjacobian[Z][Y] * - (((ROUNDDOWN(voxel[Y])>>level)+1)* - pyr_voxlen[level][Y]-voxel[Y]); + (((ROUNDDOWN(voxel[Y])>>level)+1)* + pyr_voxlen[level][Y]-voxel[Y]); min_jump = MIN(min_jump,jump[Y]); } else if (invjacobian[Z][Y] < -SMALL) { jump[Y] = invinvjacobian[Z][Y] * - ((STEPDOWN(voxel[Y])>>level)* - pyr_voxlen[level][Y]-voxel[Y]); + ((STEPDOWN(voxel[Y])>>level)* + pyr_voxlen[level][Y]-voxel[Y]); min_jump = MIN(min_jump,jump[Y]); } if (invjacobian[Z][Z] > SMALL) { jump[Z] = invinvjacobian[Z][Z] * - (((ROUNDDOWN(voxel[Z])>>level)+1)* - pyr_voxlen[level][Z]-voxel[Z]); + (((ROUNDDOWN(voxel[Z])>>level)+1)* + pyr_voxlen[level][Z]-voxel[Z]); min_jump = MIN(min_jump,jump[Z]); } else if (invjacobian[Z][Z] < -SMALL) { jump[Z] = invinvjacobian[Z][Z] * - ((STEPDOWN(voxel[Z])>>level)* - pyr_voxlen[level][Z]-voxel[Z]); + ((STEPDOWN(voxel[Z])>>level)* + pyr_voxlen[level][Z]-voxel[Z]); min_jump = MIN(min_jump,jump[Z]); } box_zmax = box_zmin + min_jump; @@ -268,16 +268,16 @@ void Trace_Ray(foutx, fouty, pixel_address) /* Popping can be repeated until parent boxes match */ /* or until next box is at starting level. */ while (level < starting_level) { - if (next_ivoxel[X]>>(level+1) != - ivoxel[X]>>(level+1) || - next_ivoxel[Y]>>(level+1) != - ivoxel[Y]>>(level+1) || - next_ivoxel[Z]>>(level+1) != - ivoxel[Z]>>(level+1)) { - level++; + if(next_ivoxel[X]>>(level+1) != + ivoxel[X]>>(level+1) || + next_ivoxel[Y]>>(level+1) != + ivoxel[Y]>>(level+1) || + next_ivoxel[Z]>>(level+1) != + ivoxel[Z]>>(level+1)) { + level++; } else - break; + break; } /* Advance voxel coordinates to near boundary of next box */ @@ -509,37 +509,37 @@ of the frame. normal[Y] = (float)ynorm * NORM_RSHIFT; mag = 1.0 - normal[Z] * normal[Z] - normal[Y] * normal[Y]; if (mag > error) { - mag = MAX(mag,0.0); - normal[X] = sqrt(mag); - xnorm = (long)normal[X]; - dpartial_product1 = normal[Z] * obslight[Z] + normal[Y] * obslight[Y]; - dpartial_product2 = normal[X] * obslight[X]; - spartial_product1 = normal[Z] * obshighlight[Z] + - normal[Y] * obshighlight[Y]; - spartial_product2 = normal[X] * obshighlight[X]; - table_addr = LOOKUP_HSIZE+(znorm*LOOKUP_PREC+ynorm)*2; - dot_product = dpartial_product1 + dpartial_product2; - diffuse = MAX(dot_product,0.0); - dot_product = spartial_product1 + spartial_product2; - specular = MAX(dot_product,0.0); - specular = pow(specular,specular_exponent); - color = ambient_color + diffuse*diffuse_color + - specular*specular_color; - color = NINT(MIN(color,MAX_PIXEL)); - temp = (long) color; - SHD(table_addr+1) = (unsigned char) temp; - if (normal[X] > 0.0) { - dot_product = dpartial_product1 - dpartial_product2; - diffuse = MAX(dot_product,0.0); - dot_product = spartial_product1 - spartial_product2; - specular = MAX(dot_product,0.0); - specular = pow(specular,specular_exponent); - color = ambient_color + diffuse*diffuse_color + - specular*specular_color; - color = NINT(MIN(color,MAX_PIXEL)); - } - temp = (long) color; - SHD(table_addr) = (unsigned char) temp; + mag = MAX(mag,0.0); + normal[X] = sqrt(mag); + xnorm = (long)normal[X]; + dpartial_product1 = normal[Z] * obslight[Z] + normal[Y] * obslight[Y]; + dpartial_product2 = normal[X] * obslight[X]; + spartial_product1 = normal[Z] * obshighlight[Z] + + normal[Y] * obshighlight[Y]; + spartial_product2 = normal[X] * obshighlight[X]; + table_addr = LOOKUP_HSIZE+(znorm*LOOKUP_PREC+ynorm)*2; + dot_product = dpartial_product1 + dpartial_product2; + diffuse = MAX(dot_product,0.0); + dot_product = spartial_product1 + spartial_product2; + specular = MAX(dot_product,0.0); + specular = pow(specular,specular_exponent); + color = ambient_color + diffuse*diffuse_color + + specular*specular_color; + color = NINT(MIN(color,MAX_PIXEL)); + temp = (long) color; + SHD(table_addr+1) = (unsigned char) temp; + if (normal[X] > 0.0) { + dot_product = dpartial_product1 - dpartial_product2; + diffuse = MAX(dot_product,0.0); + dot_product = spartial_product1 - spartial_product2; + specular = MAX(dot_product,0.0); + specular = pow(specular,specular_exponent); + color = ambient_color + diffuse*diffuse_color + + specular*specular_color; + color = NINT(MIN(color,MAX_PIXEL)); + } + temp = (long) color; + SHD(table_addr) = (unsigned char) temp; } } } diff --git a/splash2/codes/apps/volrend/render.C b/splash2/codes/apps/volrend/render.C index 1ad19d66e..b772d5cf0 100644 --- a/splash2/codes/apps/volrend/render.C +++ b/splash2/codes/apps/volrend/render.C @@ -22,7 +22,7 @@ #include "incl.h" - /* Derived values: */ + /* Derived values: */ float obslight[NM]; /* observer transformed light vector */ float obshighlight[NM]; /* observer transformed highlight vector */ @@ -51,12 +51,12 @@ void Observer_Transform_Light_Vector() /* scaling and rotation is used during shading and ray tracing, */ /* light source will appear fixed relative to observer. */ Transform_Point(light[X],light[Y],light[Z], - &obslight[X],&obslight[Y],&obslight[Z]); + &obslight[X],&obslight[Y],&obslight[Z]); /* Normalize transformed light vector */ inv_magnitude = 1.0/sqrt(obslight[X]*obslight[X] + - obslight[Y]*obslight[Y] + - obslight[Z]*obslight[Z]); + obslight[Y]*obslight[Y] + + obslight[Z]*obslight[Z]); obslight[X] = obslight[X] * inv_magnitude; obslight[Y] = obslight[Y] * inv_magnitude; obslight[Z] = obslight[Z] * inv_magnitude; @@ -81,8 +81,8 @@ void Compute_Observer_Transformed_Highlight_Vector() /* Normalize transformed eye vector */ inv_magnitude = 1.0/sqrt(obseye[X]*obseye[X] + - obseye[Y]*obseye[Y] + - obseye[Z]*obseye[Z]); + obseye[Y]*obseye[Y] + + obseye[Z]*obseye[Z]); obseye[X] = obseye[X] * inv_magnitude; obseye[Y] = obseye[Y] * inv_magnitude; obseye[Z] = obseye[Z] * inv_magnitude; @@ -96,8 +96,8 @@ void Compute_Observer_Transformed_Highlight_Vector() /* Normalize transformed highlight vector */ inv_magnitude = 1.0/sqrt(obshighlight[X]*obshighlight[X] + - obshighlight[Y]*obshighlight[Y] + - obshighlight[Z]*obshighlight[Z]); + obshighlight[Y]*obshighlight[Y] + + obshighlight[Z]*obshighlight[Z]); obshighlight[X] = obshighlight[X] * inv_magnitude * brightness; obshighlight[Y] = obshighlight[Y] * inv_magnitude * brightness; obshighlight[Z] = obshighlight[Z] * inv_magnitude * brightness; diff --git a/splash2/codes/apps/volrend/view.C b/splash2/codes/apps/volrend/view.C index 0caa9021c..8e210f41d 100644 --- a/splash2/codes/apps/volrend/view.C +++ b/splash2/codes/apps/volrend/view.C @@ -245,7 +245,7 @@ void Compute_Input_Unit_Vector() void Load_Transformation_Matrix(matrix) float matrix[4][4]; { - Copy_Matrix(matrix,transformation_matrix); + Copy_Matrix(matrix,transformation_matrix); } @@ -253,20 +253,20 @@ void Transform_Point(xold,yold,zold,xnew,ynew,znew) float xold,yold,zold; float *xnew,*ynew,*znew; { - *xnew = - xold * transformation_matrix[0][0] + + *xnew = + xold * transformation_matrix[0][0] + yold * transformation_matrix[1][0] + zold * transformation_matrix[2][0] + transformation_matrix[3][0]; - *ynew = - xold * transformation_matrix[0][1] + + *ynew = + xold * transformation_matrix[0][1] + yold * transformation_matrix[1][1] + zold * transformation_matrix[2][1] + transformation_matrix[3][1]; - *znew = - xold * transformation_matrix[0][2] + + *znew = + xold * transformation_matrix[0][2] + yold * transformation_matrix[1][2] + zold * transformation_matrix[2][2] + transformation_matrix[3][2]; @@ -276,18 +276,18 @@ void Transform_Point(xold,yold,zold,xnew,ynew,znew) void Inverse_Concatenate_Translation(matrix,xoffset,yoffset,zoffset) float matrix[4][4],xoffset,yoffset,zoffset; { - float translation_matrix[4][4]; - Load_Translation_Matrix(translation_matrix,xoffset,yoffset,zoffset); - Inverse_Concatenate_Transform(matrix,translation_matrix); + float translation_matrix[4][4]; + Load_Translation_Matrix(translation_matrix,xoffset,yoffset,zoffset); + Inverse_Concatenate_Transform(matrix,translation_matrix); } void Inverse_Concatenate_Scaling(matrix,xscale,yscale,zscale) float matrix[4][4],xscale,yscale,zscale; { - float scaling_matrix[4][4]; - Load_Scaling_Matrix(scaling_matrix,xscale,yscale,zscale); - Inverse_Concatenate_Transform(matrix,scaling_matrix); + float scaling_matrix[4][4]; + Load_Scaling_Matrix(scaling_matrix,xscale,yscale,zscale); + Inverse_Concatenate_Transform(matrix,scaling_matrix); } @@ -295,41 +295,41 @@ void Inverse_Concatenate_Rotation(matrix,axis,angle) float matrix[4][4],angle; long axis; { - float rotation_matrix[4][4]; - Load_Rotation_Matrix(rotation_matrix,axis,angle); - Inverse_Concatenate_Transform(matrix,rotation_matrix); + float rotation_matrix[4][4]; + Load_Rotation_Matrix(rotation_matrix,axis,angle); + Inverse_Concatenate_Transform(matrix,rotation_matrix); } void Load_Identity_Matrix(matrix) float matrix[4][4]; { - long i,j; - for (i=0; i<4; i++) { - for (j=0; j<4; j++) { - matrix[i][j] = 0; - } - matrix[i][i] = 1.0; - } + long i,j; + for (i=0; i<4; i++) { + for (j=0; j<4; j++) { + matrix[i][j] = 0; + } + matrix[i][i] = 1.0; + } } void Load_Translation_Matrix(matrix,xoffset,yoffset,zoffset) float matrix[4][4],xoffset,yoffset,zoffset; { - Load_Identity_Matrix(matrix); - matrix[3][0] = xoffset; - matrix[3][1] = yoffset; - matrix[3][2] = zoffset; + Load_Identity_Matrix(matrix); + matrix[3][0] = xoffset; + matrix[3][1] = yoffset; + matrix[3][2] = zoffset; } void Load_Scaling_Matrix(matrix,xscale,yscale,zscale) float matrix[4][4],xscale,yscale,zscale; { - Load_Identity_Matrix(matrix); - matrix[0][0] = xscale; - matrix[1][1] = yscale; - matrix[2][2] = zscale; + Load_Identity_Matrix(matrix); + matrix[0][0] = xscale; + matrix[1][1] = yscale; + matrix[2][2] = zscale; } @@ -337,72 +337,72 @@ void Load_Rotation_Matrix(matrix,axis,angle) float matrix[4][4],angle; long axis; { - Load_Identity_Matrix(matrix); - if (axis == XAXIS) { - matrix[1][1] = cos(angle/180.0*PI); - matrix[1][2] = sin(angle/180.0*PI); - matrix[2][1] = -sin(angle/180.0*PI); - matrix[2][2] = cos(angle/180.0*PI); - } - else if (axis == YAXIS) { - matrix[0][0] = cos(angle/180.0*PI); - matrix[0][2] = -sin(angle/180.0*PI); - matrix[2][0] = sin(angle/180.0*PI); - matrix[2][2] = cos(angle/180.0*PI); - } - else if (axis == ZAXIS) { - matrix[0][0] = cos(angle/180.0*PI); - matrix[0][1] = sin(angle/180.0*PI); - matrix[1][0] = -sin(angle/180.0*PI); - matrix[1][1] = cos(angle/180.0*PI); - } + Load_Identity_Matrix(matrix); + if (axis == XAXIS) { + matrix[1][1] = cos(angle/180.0*PI); + matrix[1][2] = sin(angle/180.0*PI); + matrix[2][1] = -sin(angle/180.0*PI); + matrix[2][2] = cos(angle/180.0*PI); + } + else if (axis == YAXIS) { + matrix[0][0] = cos(angle/180.0*PI); + matrix[0][2] = -sin(angle/180.0*PI); + matrix[2][0] = sin(angle/180.0*PI); + matrix[2][2] = cos(angle/180.0*PI); + } + else if (axis == ZAXIS) { + matrix[0][0] = cos(angle/180.0*PI); + matrix[0][1] = sin(angle/180.0*PI); + matrix[1][0] = -sin(angle/180.0*PI); + matrix[1][1] = cos(angle/180.0*PI); + } } void Concatenate_Transform(composite_matrix,transformation_matrix) float composite_matrix[][4],transformation_matrix[][4]; { - float temp_matrix[4][4]; - Multiply_Matrices(composite_matrix,transformation_matrix,temp_matrix); - Copy_Matrix(temp_matrix,composite_matrix); + float temp_matrix[4][4]; + Multiply_Matrices(composite_matrix,transformation_matrix,temp_matrix); + Copy_Matrix(temp_matrix,composite_matrix); } void Inverse_Concatenate_Transform(composite_matrix,transformation_matrix) float composite_matrix[][4],transformation_matrix[][4]; { - float temp_matrix[4][4]; - Multiply_Matrices(transformation_matrix,composite_matrix,temp_matrix); - Copy_Matrix(temp_matrix,composite_matrix); + float temp_matrix[4][4]; + Multiply_Matrices(transformation_matrix,composite_matrix,temp_matrix); + Copy_Matrix(temp_matrix,composite_matrix); } void Multiply_Matrices(input_matrix1,input_matrix2,output_matrix) float input_matrix1[][4],input_matrix2[][4],output_matrix[][4]; { - long i,j; - for (i=0; i<4; i++) { - for (j=0; j<4; j++) { - output_matrix[i][j] = - input_matrix1[i][0] * - input_matrix2[0][j] + - input_matrix1[i][1] * - input_matrix2[1][j] + - input_matrix1[i][2] * - input_matrix2[2][j] + - input_matrix1[i][3] * - input_matrix2[3][j]; - } - } + long i,j; + for (i=0; i<4; i++) { + for (j=0; j<4; j++) { + output_matrix[i][j] = + input_matrix1[i][0] * + input_matrix2[0][j] + + input_matrix1[i][1] * + input_matrix2[1][j] + + input_matrix1[i][2] * + input_matrix2[2][j] + + input_matrix1[i][3] * + input_matrix2[3][j]; + } + } } void Copy_Matrix(input_matrix,output_matrix) float input_matrix[][4],output_matrix[][4]; { - long i,j; - for (i=0; i<4; i++) { - for (j=0; j<4; j++) { - output_matrix[i][j] = input_matrix[i][j]; - } - } + long i,j; + for (i=0; i<4; i++) { + for (j=0; j<4; j++) { + output_matrix[i][j] = input_matrix[i][j]; + } + } } diff --git a/splash2/codes/apps/water-nsquared/bndry.C b/splash2/codes/apps/water-nsquared/bndry.C index 86aa07721..430704f50 100644 --- a/splash2/codes/apps/water-nsquared/bndry.C +++ b/splash2/codes/apps/water-nsquared/bndry.C @@ -15,11 +15,11 @@ /*************************************************************************/ EXTERN_ENV -#include "global.h" -#include "mddata.h" #include "mdvar.h" #include "parameters.h" +#include "mddata.h" #include "split.h" +#include "global.h" /* this routine puts the molecules back inside the box if they are out */ void BNDRY(long ProcID) diff --git a/splash2/codes/apps/water-nsquared/cnstnt.C b/splash2/codes/apps/water-nsquared/cnstnt.C index c7c149418..deb6b5486 100644 --- a/splash2/codes/apps/water-nsquared/cnstnt.C +++ b/splash2/codes/apps/water-nsquared/cnstnt.C @@ -15,15 +15,14 @@ /*************************************************************************/ EXTERN_ENV -#include - -#include "cnst.h" -#include "fileio.h" -#include "frcnst.h" -#include "global.h" -#include "parameters.h" +#include #include "water.h" #include "wwpot.h" +#include "cnst.h" +#include "frcnst.h" +#include "fileio.h" +#include "parameters.h" +#include "global.h" /* set up some constants * N : NORDER + 1 = 7 for a sixth-order method diff --git a/splash2/codes/apps/water-nsquared/cshift.C b/splash2/codes/apps/water-nsquared/cshift.C index d0e709e50..d40c99c48 100644 --- a/splash2/codes/apps/water-nsquared/cshift.C +++ b/splash2/codes/apps/water-nsquared/cshift.C @@ -15,8 +15,7 @@ /*************************************************************************/ EXTERN_ENV -#include - +#include #include "global.h" /* return the value of a with the same sign as b */ diff --git a/splash2/codes/apps/water-nsquared/initia.C b/splash2/codes/apps/water-nsquared/initia.C index 334105c08..ed11c6c8c 100644 --- a/splash2/codes/apps/water-nsquared/initia.C +++ b/splash2/codes/apps/water-nsquared/initia.C @@ -15,16 +15,16 @@ /*************************************************************************/ EXTERN_ENV +#include "math.h" +#include "stdio.h" +#include "mdvar.h" +#include "water.h" #include "cnst.h" #include "fileio.h" -#include "global.h" -#include "math.h" -#include "mddata.h" -#include "mdvar.h" #include "parameters.h" +#include "mddata.h" #include "split.h" -#include "stdio.h" -#include "water.h" +#include "global.h" void INITIA() { diff --git a/splash2/codes/apps/water-nsquared/interf.C b/splash2/codes/apps/water-nsquared/interf.C index c1334f6db..e6d551f26 100644 --- a/splash2/codes/apps/water-nsquared/interf.C +++ b/splash2/codes/apps/water-nsquared/interf.C @@ -15,15 +15,15 @@ /*************************************************************************/ EXTERN_ENV -#include "cnst.h" -#include "global.h" #include "math.h" -#include "mddata.h" #include "mdvar.h" -#include "parameters.h" -#include "split.h" #include "water.h" #include "wwpot.h" +#include "cnst.h" +#include "parameters.h" +#include "mddata.h" +#include "split.h" +#include "global.h" double ****PFORCES; diff --git a/splash2/codes/apps/water-nsquared/intraf.C b/splash2/codes/apps/water-nsquared/intraf.C index ed1376656..5eeadc032 100644 --- a/splash2/codes/apps/water-nsquared/intraf.C +++ b/splash2/codes/apps/water-nsquared/intraf.C @@ -15,15 +15,15 @@ /*************************************************************************/ EXTERN_ENV -#include "frcnst.h" -#include "global.h" #include "math.h" -#include "mddata.h" +#include "frcnst.h" #include "mdvar.h" -#include "parameters.h" -#include "split.h" #include "water.h" #include "wwpot.h" +#include "parameters.h" +#include "mddata.h" +#include "split.h" +#include "global.h" void INTRAF(double *VIR, long ProcID) { diff --git a/splash2/codes/apps/water-nsquared/kineti.C b/splash2/codes/apps/water-nsquared/kineti.C index 83b310074..83c43d3b0 100644 --- a/splash2/codes/apps/water-nsquared/kineti.C +++ b/splash2/codes/apps/water-nsquared/kineti.C @@ -15,12 +15,12 @@ /*************************************************************************/ EXTERN_ENV -#include "global.h" #include "math.h" -#include "mddata.h" #include "mdvar.h" #include "parameters.h" +#include "mddata.h" #include "split.h" +#include "global.h" /* this routine computes kinetic energy in each of the three spatial dimensions, and puts the computed values in the SUM array */ diff --git a/splash2/codes/apps/water-nsquared/mdmain.C b/splash2/codes/apps/water-nsquared/mdmain.C index f1634df7b..3ec717b6c 100644 --- a/splash2/codes/apps/water-nsquared/mdmain.C +++ b/splash2/codes/apps/water-nsquared/mdmain.C @@ -15,16 +15,16 @@ /*************************************************************************/ EXTERN_ENV -#include "cnst.h" -#include "fileio.h" -#include "global.h" -#include "mddata.h" -#include "mdvar.h" -#include "parameters.h" -#include "split.h" #include "stdio.h" +#include "parameters.h" +#include "mdvar.h" #include "water.h" #include "wwpot.h" +#include "cnst.h" +#include "mddata.h" +#include "fileio.h" +#include "split.h" +#include "global.h" /************************************************************************/ diff --git a/splash2/codes/apps/water-nsquared/parameters.H b/splash2/codes/apps/water-nsquared/parameters.H index d78559ef5..7a2570cfe 100644 --- a/splash2/codes/apps/water-nsquared/parameters.H +++ b/splash2/codes/apps/water-nsquared/parameters.H @@ -15,9 +15,9 @@ /*************************************************************************/ /* contains the definitions of certain system constants */ - + #define MAXODR 7 /* Order of predictor-corrector method + 1 */ -#define NATOM 3 /* Atoms per molecule, H-O-H */ +#define NATOM 3 /* Atoms per molecule, H-O-H */ #define MXOD2 (MAXODR+2) /* Variables maintained per mol */ #define NDIR 3 /* Number of spatial directions */ diff --git a/splash2/codes/apps/water-nsquared/poteng.C b/splash2/codes/apps/water-nsquared/poteng.C index ca702a758..e49d7227a 100644 --- a/splash2/codes/apps/water-nsquared/poteng.C +++ b/splash2/codes/apps/water-nsquared/poteng.C @@ -15,15 +15,15 @@ /*************************************************************************/ EXTERN_ENV -#include "frcnst.h" -#include "global.h" -#include "math.h" -#include "mddata.h" #include "mdvar.h" -#include "parameters.h" -#include "split.h" +#include "frcnst.h" #include "water.h" #include "wwpot.h" +#include "math.h" +#include "parameters.h" +#include "mddata.h" +#include "split.h" +#include "global.h" void POTENG(double *POTA, double *POTR, double *PTRF, long ProcID) { diff --git a/splash2/codes/apps/water-nsquared/predcor.C b/splash2/codes/apps/water-nsquared/predcor.C index ed6e5add0..d866b4d33 100644 --- a/splash2/codes/apps/water-nsquared/predcor.C +++ b/splash2/codes/apps/water-nsquared/predcor.C @@ -15,11 +15,11 @@ /*************************************************************************/ EXTERN_ENV -#include "global.h" -#include "mddata.h" #include "mdvar.h" #include "parameters.h" +#include "mddata.h" #include "split.h" +#include "global.h" /* predicts new values for displacement and its five derivatives * diff --git a/splash2/codes/apps/water-nsquared/split.H b/splash2/codes/apps/water-nsquared/split.H index a9434ef07..f084d3045 100644 --- a/splash2/codes/apps/water-nsquared/split.H +++ b/splash2/codes/apps/water-nsquared/split.H @@ -15,7 +15,7 @@ /*************************************************************************/ /* some constant definitions */ - + #define H1 0 #define O 1 #define H2 2 diff --git a/splash2/codes/apps/water-nsquared/syscons.C b/splash2/codes/apps/water-nsquared/syscons.C index 6577e574d..811a4a72a 100644 --- a/splash2/codes/apps/water-nsquared/syscons.C +++ b/splash2/codes/apps/water-nsquared/syscons.C @@ -15,16 +15,16 @@ /*************************************************************************/ EXTERN_ENV -#include - -#include "cnst.h" -#include "global.h" -#include "mddata.h" -#include "mdvar.h" -#include "parameters.h" #include "stdio.h" +#include + +#include "parameters.h" +#include "mdvar.h" #include "water.h" #include "wwpot.h" +#include "cnst.h" +#include "mddata.h" +#include "global.h" void SYSCNS() /* sets up some system constants */ { @@ -50,7 +50,7 @@ void SYSCNS() /* sets up some system constants */ box length */ } if (CUTOFF > 11.0) CUTOFF = 11.0; /* cutoff never greater than 11 - Angstrom*/ + Angstrom*/ REF1= -QQ/(CUTOFF*CUTOFF*CUTOFF); REF2=2.00*REF1; diff --git a/splash2/codes/apps/water-nsquared/water.C b/splash2/codes/apps/water-nsquared/water.C index 3365e1ea5..c9224618a 100644 --- a/splash2/codes/apps/water-nsquared/water.C +++ b/splash2/codes/apps/water-nsquared/water.C @@ -44,21 +44,20 @@ */ MAIN_ENV -#include -#include - +#include +#include #include "split.h" /* include files for declarations */ +#include "parameters.h" +#include "mdvar.h" +#include "water.h" +#include "wwpot.h" #include "cnst.h" +#include "mddata.h" #include "fileio.h" #include "frcnst.h" #include "global.h" -#include "mddata.h" -#include "mdvar.h" -#include "parameters.h" -#include "water.h" -#include "wwpot.h" long NMOL,NORDER,NATMO,NATMO3,NMOL1; long NATOMS; @@ -183,8 +182,8 @@ int main(int argc, char **argv) /* macro calls to initialize synch varibles */ BARINIT(gl->start, NumProcs); - BARINIT(gl->InterfBar, NumProcs); - BARINIT(gl->PotengBar, NumProcs); + BARINIT(gl->InterfBar, NumProcs); + BARINIT(gl->PotengBar, NumProcs); LOCKINIT(gl->IOLock); LOCKINIT(gl->IndexLock); LOCKINIT(gl->IntrafVirLock); @@ -242,7 +241,7 @@ int main(int argc, char **argv) gl->Index = 1; if (NSAVE > 0) /* not true for input decks provided */ - fprintf(six,"COLLECTING X AND V DATA AT EVERY %4ld TIME STEPS \n",NSAVE); + fprintf(six,"COLLECTING X AND V DATA AT EVERY %4ld TIME STEPS \n",NSAVE); /* spawn helper processes, each getting its unique process id */ CLOCK(gl->computestart); @@ -287,6 +286,6 @@ void WorkStart() /* routine that each created process starts at; LocalXTT = MDMAIN(NSTEP,NPRINT,NSAVE,NORD1,ProcID); if (ProcID == 0) { - XTT = LocalXTT; + XTT = LocalXTT; } } diff --git a/splash2/codes/apps/water-spatial/bndry.C b/splash2/codes/apps/water-spatial/bndry.C index 86494371d..eb5cd6e41 100644 --- a/splash2/codes/apps/water-spatial/bndry.C +++ b/splash2/codes/apps/water-spatial/bndry.C @@ -16,13 +16,12 @@ EXTERN_ENV -#include - -#include "global.h" -#include "mddata.h" +#include #include "mdvar.h" #include "parameters.h" +#include "mddata.h" #include "split.h" +#include "global.h" void BNDRY(long ProcID) /* this routine puts the molecules back inside the box if they are out */ { diff --git a/splash2/codes/apps/water-spatial/cnstnt.C b/splash2/codes/apps/water-spatial/cnstnt.C index e1c183e80..1c0411f76 100644 --- a/splash2/codes/apps/water-spatial/cnstnt.C +++ b/splash2/codes/apps/water-spatial/cnstnt.C @@ -16,16 +16,15 @@ EXTERN_ENV -#include - -#include "cnst.h" -#include "fileio.h" -#include "frcnst.h" -#include "global.h" -#include "mddata.h" -#include "parameters.h" +#include #include "water.h" #include "wwpot.h" +#include "cnst.h" +#include "frcnst.h" +#include "fileio.h" +#include "parameters.h" +#include "mddata.h" +#include "global.h" /* set up some constants; this routine is executed by * a single processor before others are created diff --git a/splash2/codes/apps/water-spatial/cshift.C b/splash2/codes/apps/water-spatial/cshift.C index f5e021c7d..93930aa43 100644 --- a/splash2/codes/apps/water-spatial/cshift.C +++ b/splash2/codes/apps/water-spatial/cshift.C @@ -16,12 +16,11 @@ EXTERN_ENV -#include - -#include "global.h" -#include "mddata.h" +#include #include "parameters.h" +#include "mddata.h" #include "water.h" +#include "global.h" /* return the value of a with the same sign as b */ #define sign(a,b) (b < 0 ) ? ( (a < 0) ? a : -a) : ( (a < 0) ? -a : a) diff --git a/splash2/codes/apps/water-spatial/initia.C b/splash2/codes/apps/water-spatial/initia.C index 6389afb4b..9791d57d8 100644 --- a/splash2/codes/apps/water-spatial/initia.C +++ b/splash2/codes/apps/water-spatial/initia.C @@ -16,17 +16,16 @@ EXTERN_ENV -#include -#include - +#include +#include +#include "mdvar.h" +#include "water.h" #include "cnst.h" #include "fileio.h" -#include "global.h" -#include "mddata.h" -#include "mdvar.h" #include "parameters.h" +#include "mddata.h" #include "split.h" -#include "water.h" +#include "global.h" void INITIA() { diff --git a/splash2/codes/apps/water-spatial/interf.C b/splash2/codes/apps/water-spatial/interf.C index ce5b61492..00d89932b 100644 --- a/splash2/codes/apps/water-spatial/interf.C +++ b/splash2/codes/apps/water-spatial/interf.C @@ -16,17 +16,16 @@ EXTERN_ENV -#include -#include - -#include "cnst.h" -#include "global.h" -#include "mddata.h" +#include +#include #include "mdvar.h" -#include "parameters.h" -#include "split.h" #include "water.h" #include "wwpot.h" +#include "cnst.h" +#include "parameters.h" +#include "mddata.h" +#include "split.h" +#include "global.h" void INTERF(long DEST, double *VIR, long ProcID) { diff --git a/splash2/codes/apps/water-spatial/intraf.C b/splash2/codes/apps/water-spatial/intraf.C index ce5493137..d3fc31b90 100644 --- a/splash2/codes/apps/water-spatial/intraf.C +++ b/splash2/codes/apps/water-spatial/intraf.C @@ -16,17 +16,16 @@ EXTERN_ENV -#include -#include - +#include +#include #include "frcnst.h" -#include "global.h" -#include "mddata.h" #include "mdvar.h" -#include "parameters.h" -#include "split.h" #include "water.h" #include "wwpot.h" +#include "parameters.h" +#include "mddata.h" +#include "split.h" +#include "global.h" void INTRAF(double *VIR, long ProcID) { diff --git a/splash2/codes/apps/water-spatial/kineti.C b/splash2/codes/apps/water-spatial/kineti.C index 5894f7e9d..ecdc7fb45 100644 --- a/splash2/codes/apps/water-spatial/kineti.C +++ b/splash2/codes/apps/water-spatial/kineti.C @@ -16,13 +16,12 @@ EXTERN_ENV -#include - -#include "global.h" -#include "mddata.h" +#include #include "mdvar.h" #include "parameters.h" +#include "mddata.h" #include "split.h" +#include "global.h" /* this routine computes kinetic energy in each of the three spatial dimensions, and puts the computed values in the SUM array */ diff --git a/splash2/codes/apps/water-spatial/mdmain.C b/splash2/codes/apps/water-spatial/mdmain.C index 0fe11fc85..50e5bc32c 100644 --- a/splash2/codes/apps/water-spatial/mdmain.C +++ b/splash2/codes/apps/water-spatial/mdmain.C @@ -16,17 +16,17 @@ EXTERN_ENV -#include +#include -#include "cnst.h" -#include "fileio.h" -#include "global.h" -#include "mddata.h" -#include "mdvar.h" #include "parameters.h" -#include "split.h" +#include "mdvar.h" #include "water.h" #include "wwpot.h" +#include "cnst.h" +#include "mddata.h" +#include "fileio.h" +#include "split.h" +#include "global.h" /************************************************************************/ diff --git a/splash2/codes/apps/water-spatial/poteng.C b/splash2/codes/apps/water-spatial/poteng.C index b76224516..2fdfa28ba 100644 --- a/splash2/codes/apps/water-spatial/poteng.C +++ b/splash2/codes/apps/water-spatial/poteng.C @@ -16,16 +16,15 @@ EXTERN_ENV -#include - -#include "frcnst.h" -#include "global.h" -#include "mddata.h" #include "mdvar.h" -#include "parameters.h" -#include "split.h" +#include "frcnst.h" #include "water.h" #include "wwpot.h" +#include +#include "parameters.h" +#include "mddata.h" +#include "split.h" +#include "global.h" void POTENG(double *POTA, double *POTR, double *PTRF, long ProcID) { diff --git a/splash2/codes/apps/water-spatial/predcor.C b/splash2/codes/apps/water-spatial/predcor.C index eabfc3e4b..f9e417d3f 100644 --- a/splash2/codes/apps/water-spatial/predcor.C +++ b/splash2/codes/apps/water-spatial/predcor.C @@ -16,11 +16,11 @@ EXTERN_ENV -#include "global.h" -#include "mddata.h" #include "mdvar.h" #include "parameters.h" +#include "mddata.h" #include "split.h" +#include "global.h" /* predicts new values for displacement and its five derivatives * using Gear's sixth-order predictor-corrector method diff --git a/splash2/codes/apps/water-spatial/split.H b/splash2/codes/apps/water-spatial/split.H index 6a75a49da..716a7c421 100644 --- a/splash2/codes/apps/water-spatial/split.H +++ b/splash2/codes/apps/water-spatial/split.H @@ -15,7 +15,7 @@ /*************************************************************************/ /* some constant definitions */ - + #define H1 0 #define O 1 #define H2 2 diff --git a/splash2/codes/apps/water-spatial/syscons.C b/splash2/codes/apps/water-spatial/syscons.C index 45ece4f27..24309a8d2 100644 --- a/splash2/codes/apps/water-spatial/syscons.C +++ b/splash2/codes/apps/water-spatial/syscons.C @@ -15,16 +15,17 @@ /*************************************************************************/ EXTERN_ENV -#include -#include +#include +#include + -#include "cnst.h" -#include "global.h" -#include "mddata.h" -#include "mdvar.h" #include "parameters.h" +#include "mdvar.h" #include "water.h" #include "wwpot.h" +#include "cnst.h" +#include "mddata.h" +#include "global.h" void SYSCNS() /* sets up some system constants */ { diff --git a/splash2/codes/apps/water-spatial/water.C b/splash2/codes/apps/water-spatial/water.C index 981d8404a..3099d06c1 100644 --- a/splash2/codes/apps/water-spatial/water.C +++ b/splash2/codes/apps/water-spatial/water.C @@ -45,22 +45,22 @@ MAIN_ENV (and not have fewer boxes than processors). */ -#include -#include -#include +#include +#include +#include /* include files for declarations */ #include "cnst.h" #include "fileio.h" #include "frcnst.h" -#include "global.h" -#include "mddata.h" #include "mdvar.h" #include "parameters.h" #include "randno.h" #include "split.h" #include "water.h" #include "wwpot.h" +#include "mddata.h" +#include "global.h" long NATOMS; long I2; @@ -380,7 +380,7 @@ void WorkStart() /* routine that each created process starts at; LocalXTT = MDMAIN(NSTEP,NPRINT,NSAVE,NORD1,ProcID); if (ProcID == 0) { - XTT = LocalXTT; + XTT = LocalXTT; } } diff --git a/splash2/codes/kernels/cholesky/amal.C b/splash2/codes/kernels/cholesky/amal.C index a6e04f8fa..d696ff2b3 100644 --- a/splash2/codes/kernels/cholesky/amal.C +++ b/splash2/codes/kernels/cholesky/amal.C @@ -16,8 +16,7 @@ EXTERN_ENV -#include - +#include #include "matrix.h" long *next_in_super, *member_of, *super_parent; @@ -118,10 +117,10 @@ void Amalgamate2(long join, SMatrix M, long *T, long *nz, long *node, long *doma printf("%ld/%ld supers before/after\n", supers_before, supers_after); printf("%.0f/%.0f (%.2f) ops before/after amalgamation\n", - g_ops_before, work_tree[M.n], work_tree[M.n]/(double) g_ops_before); + g_ops_before, work_tree[M.n], work_tree[M.n]/(double) g_ops_before); if (ops_added != work_tree[M.n]-g_ops_before) printf("Model says %ld ops added, really %.0f\n", ops_added, - work_tree[M.n]-g_ops_before); + work_tree[M.n]-g_ops_before); } @@ -149,19 +148,19 @@ void ConsiderMerge(long join, long super, SMatrix M, long *nz, long *node, long time_before = 0; PDIV(node[super], nz[super], &dummy, &dummy, &time_before); PMOD(node[super], nz[super]-node[super], nz[super]-node[super], - &dummy, &dummy, &time_before); + &dummy, &dummy, &time_before); PADD(nz[super]-node[super], nz[super]-node[super], &dummy, &time_before); PDIV(node[parent], nz[parent], &dummy, &dummy, &time_before); PMOD(node[parent], nz[parent]-node[parent], nz[parent]-node[parent], - &dummy, &dummy, &time_before); + &dummy, &dummy, &time_before); PADD(nz[parent]-node[parent], nz[parent]-node[parent], &dummy, - &time_before); + &time_before); time_after = 0; PDIV(node[super]+node[parent], node[super]+nz[parent], - &dummy, &dummy, &time_after); + &dummy, &dummy, &time_after); PMOD(node[super]+node[parent], nz[parent]-node[parent], - nz[parent]-node[parent], &dummy, &dummy, &time_after); + nz[parent]-node[parent], &dummy, &dummy, &time_after); PADD(nz[parent]-node[parent], nz[parent]-node[parent], &dummy, &time_after); simple_diff = (ops_after-ops_before) - @@ -172,7 +171,7 @@ void ConsiderMerge(long join, long super, SMatrix M, long *nz, long *node, long allow_critical_to_grow = 1; if ((!domain || domain[super] == 0) && time_before > time_after) { if (allow_critical_to_grow) - path_grows = 0; + path_grows = 0; } else path_grows = 0.0; diff --git a/splash2/codes/kernels/cholesky/assign.C b/splash2/codes/kernels/cholesky/assign.C index c71ea6505..c504de030 100644 --- a/splash2/codes/kernels/cholesky/assign.C +++ b/splash2/codes/kernels/cholesky/assign.C @@ -16,8 +16,7 @@ EXTERN_ENV -#include - +#include #include "matrix.h" #define MISS_COST 4.74 @@ -88,8 +87,8 @@ void AssignBlocksNow() if (P == 1) { for (j=0; jowner = 0; + for (i=LB.col[j]; iowner = 0; } else { EmbedBlocks(); } @@ -106,7 +105,7 @@ void EmbedBlocks() for (j=0; jowner = EmbeddedOwner(block); + BLOCK(block)->owner = EmbeddedOwner(block); } } diff --git a/splash2/codes/kernels/cholesky/bfac.C b/splash2/codes/kernels/cholesky/bfac.C index 53163a1c3..924394f68 100644 --- a/splash2/codes/kernels/cholesky/bfac.C +++ b/splash2/codes/kernels/cholesky/bfac.C @@ -16,9 +16,8 @@ EXTERN_ENV -#include - #include "matrix.h" +#include long vMiss=0, wMiss=0, xMiss=0, yMiss=0; /* Local but don't care */ extern long BS; @@ -56,7 +55,7 @@ void BFac(long diag, struct LocalCopies *lc) for (ks=jl; ks n) kl = n; - OneMatmat(lc->blktmp, &A[ks+n*js], &A[is+n*ks], kl-ks, jl-js, il-is, n, n); + OneMatmat(lc->blktmp, &A[ks+n*js], &A[is+n*ks], kl-ks, jl-js, il-is, n, n); } @@ -76,7 +75,7 @@ void OneFac(double *A, long n1, long n2) for (j=0; j n1) kl = n1; OneMatmat(lc->blktmp, &A[ks+js*n1], &B[is+ks*n3], kl-ks, jl-js, il-is, - n3, n1); + n3, n1); } } } @@ -147,20 +146,20 @@ void OneDiv(double *A, double *B, long n1, long n3, long n4) b0 = &B[n3*k]; b1 = b0+n3; b2 = b1+n3; b3 = b2+n3; while (dest0 != last) { - t0 = *dest0; t1 = *dest1; - tmp0 = *b0++; t0 -= a_j0k0*tmp0; t1 -= a_j1k0*tmp0; - tmp1 = *b1++; t0 -= a_j0k1*tmp1; t1 -= a_j1k1*tmp1; - tmp0 = *b2++; t0 -= a_j0k2*tmp0; t1 -= a_j1k2*tmp0; - tmp1 = *b3++; t0 -= a_j0k3*tmp1; t1 -= a_j1k3*tmp1; - *dest0++ = t0; *dest1++ = t1; + t0 = *dest0; t1 = *dest1; + tmp0 = *b0++; t0 -= a_j0k0*tmp0; t1 -= a_j1k0*tmp0; + tmp1 = *b1++; t0 -= a_j0k1*tmp1; t1 -= a_j1k1*tmp1; + tmp0 = *b2++; t0 -= a_j0k2*tmp0; t1 -= a_j1k2*tmp0; + tmp1 = *b3++; t0 -= a_j0k3*tmp1; t1 -= a_j1k3*tmp1; + *dest0++ = t0; *dest1++ = t1; } } for (; k n2) kl = n2; CopyBlock(A, lc->blktmp, n1, is, ks, il, kl); OneMatmat(lc->blktmp, &A[ks*n1], &C[is], is, kl-ks, il-is, n1, n1); - OneLower(lc->blktmp, &C[is+is*n1], il-is, kl-ks, n1); + OneLower(lc->blktmp, &C[is+is*n1], il-is, kl-ks, n1); } } } @@ -411,12 +410,12 @@ void OneLower(double *A, double *C, long n1, long n2, long n3) *dest0++ -= a_j0k0**b0++ + a_j0k1**b1++ + a_j0k2**b2++ + a_j0k3**b3++; dest1 = dest0 + n3; while (dest0 != last) { - t0 = *dest0; t1 = *dest1; - tmp0 = *b0++; t0 -= a_j0k0*tmp0; t1 -= a_j1k0*tmp0; - tmp1 = *b1++; t0 -= a_j0k1*tmp1; t1 -= a_j1k1*tmp1; - tmp0 = *b2++; t0 -= a_j0k2*tmp0; t1 -= a_j1k2*tmp0; - tmp1 = *b3++; t0 -= a_j0k3*tmp1; t1 -= a_j1k3*tmp1; - *dest0++ = t0; *dest1++ = t1; + t0 = *dest0; t1 = *dest1; + tmp0 = *b0++; t0 -= a_j0k0*tmp0; t1 -= a_j1k0*tmp0; + tmp1 = *b1++; t0 -= a_j0k1*tmp1; t1 -= a_j1k1*tmp1; + tmp0 = *b2++; t0 -= a_j0k2*tmp0; t1 -= a_j1k2*tmp0; + tmp1 = *b3++; t0 -= a_j0k3*tmp1; t1 -= a_j1k3*tmp1; + *dest0++ = t0; *dest1++ = t1; } } for (; k - #include "matrix.h" +#include double *TriBSolve(BMatrix LB, double *b, long *PERM) { @@ -45,27 +44,27 @@ double *TriBSolve(BMatrix LB, double *b, long *PERM) /* diagonal block */ bl = LB.col[j]; for (j1=j; j1nz[(j1-j)+(j1-j)*LB.entry[bl].block->length]; + y[j1] = bt[PERM[j1]]/ + LB.entry[bl].block->nz[(j1-j)+(j1-j)*LB.entry[bl].block->length]; for (i1=j1-j+1; i1length; i1++) { - if (LB.entry[bl].block->structure) - row = LB.row[bl] + LB.entry[bl].block->structure[i1]; - else row = LB.row[bl] + i1; - bt[PERM[row]] -= LB.entry[bl].block->nz[ - i1+(j1-j)*LB.entry[bl].block->length] * y[j1]; - } + if (LB.entry[bl].block->structure) + row = LB.row[bl] + LB.entry[bl].block->structure[i1]; + else row = LB.row[bl] + i1; + bt[PERM[row]] -= LB.entry[bl].block->nz[ + i1+(j1-j)*LB.entry[bl].block->length] * y[j1]; + } } /* blocks below diagonal */ for (bl=LB.col[j]+1; bllength; i1++) { - if (LB.entry[bl].block->structure) - row = LB.row[bl] + LB.entry[bl].block->structure[i1]; - else row = LB.row[bl] + i1; - for (j1=j; j1nz[ - i1+(j1-j)*LB.entry[bl].block->length] * y[j1]; - } - } + for (i1=0; i1length; i1++) { + if (LB.entry[bl].block->structure) + row = LB.row[bl] + LB.entry[bl].block->structure[i1]; + else row = LB.row[bl] + i1; + for (j1=j; j1nz[ + i1+(j1-j)*LB.entry[bl].block->length] * y[j1]; + } + } } } } @@ -86,27 +85,27 @@ double *TriBSolve(BMatrix LB, double *b, long *PERM) /* blocks below diagonal */ for (bl=LB.col[j]+1; bllength; i1++) { - if (LB.entry[bl].block->structure) - row = LB.row[bl] + LB.entry[bl].block->structure[i1]; - else row = LB.row[bl] + i1; + if (LB.entry[bl].block->structure) + row = LB.row[bl] + LB.entry[bl].block->structure[i1]; + else row = LB.row[bl] + i1; for (j1=j; j1nz[ - i1+(j1-j)*LB.entry[bl].block->length] * xp[row]; - } - } + y[j1] -= LB.entry[bl].block->nz[ + i1+(j1-j)*LB.entry[bl].block->length] * xp[row]; + } + } } /* diagonal block */ bl = LB.col[j]; for (j1=j+LB.partition_size[j]-1; j1>=j; j1--) { for (i1=j1-j+1; i1length; i1++) { - if (LB.entry[bl].block->structure) - row = LB.row[bl] + LB.entry[bl].block->structure[i1]; - else row = LB.row[bl] + i1; - y[j1] -= LB.entry[bl].block->nz[ - i1+(j1-j)*LB.entry[bl].block->length] * xp[row]; - } - xp[j1] = y[j1]/ - LB.entry[bl].block->nz[(j1-j)+(j1-j)*LB.entry[bl].block->length]; + if (LB.entry[bl].block->structure) + row = LB.row[bl] + LB.entry[bl].block->structure[i1]; + else row = LB.row[bl] + i1; + y[j1] -= LB.entry[bl].block->nz[ + i1+(j1-j)*LB.entry[bl].block->length] * xp[row]; + } + xp[j1] = y[j1]/ + LB.entry[bl].block->nz[(j1-j)+(j1-j)*LB.entry[bl].block->length]; } } @@ -151,13 +150,13 @@ double *CreateVector(SMatrix M) if (M.nz) { for (j=0; j - +#include #include "matrix.h" extern long *node; /* ALL GLOBAL */ @@ -46,13 +45,13 @@ void CreateBlockedMatrix2(SMatrix M, long block_ub, long *T, long *firstchild, l LB.entries_allocated = block_ub+20; LB.proc_domain_storage = (double **) MyMalloc(LB.n_domains*sizeof(double *), - DISTRIBUTED); + DISTRIBUTED); for (i=0; i LB.max_partition) LB.max_partition = LB.partition_size[j]; @@ -109,7 +108,7 @@ void CreateBlockedMatrix2(SMatrix M, long block_ub, long *T, long *firstchild, l /* determine numbering based on partitions only */ LB.renumbering = (long *) MyMalloc((LB.n+LB.n_domains)*sizeof(long), - DISTRIBUTED); + DISTRIBUTED); ComputePartitionNumbering(LB.renumbering); for (j=0; ji = LB.row[i]; BLOCK(i)->j = j; - if (LB.renumbering[BLOCK(i)->i] < 0 || - LB.renumbering[BLOCK(i)->j] < 0) { - printf("Block %ld has bad structure\n", which); - exit(-1); - } - BLOCK(i)->done = 0; - BLOCK(i)->pair = NULL; - which++; + if (LB.renumbering[BLOCK(i)->i] < 0 || + LB.renumbering[BLOCK(i)->j] < 0) { + printf("Block %ld has bad structure\n", which); + exit(-1); + } + BLOCK(i)->done = 0; + BLOCK(i)->pair = NULL; + which++; } } /* and for domain dummies */ for (p=0; pi = LB.row[i]; + BLOCK(i) = &blocks[which]; + BLOCK(i)->i = LB.row[i]; BLOCK(i)->j = LB.n+j; - BLOCK(i)->nz = NULL; - BLOCK(i)->owner = p; - BLOCK(i)->done = 0; - BLOCK(i)->pair = NULL; - which++; + BLOCK(i)->nz = NULL; + BLOCK(i)->owner = p; + BLOCK(i)->done = 0; + BLOCK(i)->pair = NULL; + which++; } ComputeBlockParents(T); @@ -215,7 +214,7 @@ long FindNumPartitions(long set_size, long piece_size) else { num_partitions = (set_size+piece_size-1)/piece_size; if (piece_size - set_size/num_partitions > - set_size/(num_partitions-1) - piece_size) + set_size/(num_partitions-1) - piece_size) num_partitions--; } @@ -232,16 +231,16 @@ void ComputeBlockParents(long *T) for (b=0; bparent = -1; - else if (BLOCK(i)->i <= BLOCK(i)->j) - BLOCK(i)->parent = -1; /* above diag */ - else { - BLOCK(i)->parent = FindBlock(BLOCK(i)->i, parent_col); - if (BLOCK(i)->parent == -1) - printf("Parent not found\n"); - } + parent_col = T[b+LB.partition_size[b]-1]; + if (parent_col == LB.n) + BLOCK(i)->parent = -1; + else if (BLOCK(i)->i <= BLOCK(i)->j) + BLOCK(i)->parent = -1; /* above diag */ + else { + BLOCK(i)->parent = FindBlock(BLOCK(i)->i, parent_col); + if (BLOCK(i)->parent == -1) + printf("Parent not found\n"); + } } } @@ -279,10 +278,10 @@ void FillInStructure(SMatrix M, long *firstchild, long *child, long *PERM, long /* find the structure of the individual blocks */ for (super=0; super= current_block && - LB.row[row] < current_block_last && - row < LB.col[col+1]) + LB.row[row] < current_block_last && + row < LB.col[col+1]) row++; } @@ -375,10 +374,10 @@ void FindBlStructure(SMatrix M, long super, long *PERM, long *INVP, long *firstc for (i=M.col[truecol]; i= super && !structure[bl]) { - structure[bl] = 1; - nz[n_nz++] = bl; + structure[bl] = 1; + nz[n_nz++] = bl; } } } @@ -390,10 +389,10 @@ void FindBlStructure(SMatrix M, long super, long *PERM, long *INVP, long *firstc for (i=LB.col[the_child]; i= super && !structure[bl]) { - structure[bl] = 1; - nz[n_nz++] = bl; + structure[bl] = 1; + nz[n_nz++] = bl; } } } @@ -427,8 +426,8 @@ void FindSuperStructure(SMatrix M, long super, long *PERM, long *INVP, long *fir for (i=M.col[truecol]; i= super && !structure[row]) { - structure[row] = 1; - nz[(*n_nz)++] = row; + structure[row] = 1; + nz[(*n_nz)++] = row; } } } @@ -442,23 +441,23 @@ void FindSuperStructure(SMatrix M, long super, long *PERM, long *INVP, long *fir for (i=LB.col[the_child]; i= super && !structure[row]) { - structure[row] = 1; - nz[(*n_nz)++] = row; + structure[row] = 1; + nz[(*n_nz)++] = row; } } } else { for (i=LB.col[the_child]; ilength; bl++) { - if (BLOCK(i)->structure) - row = LB.row[i]+BLOCK(i)->structure[bl]; - else - row = LB.row[i]+bl; + if (BLOCK(i)->structure) + row = LB.row[i]+BLOCK(i)->structure[bl]; + else + row = LB.row[i]+bl; if (row >= super && !structure[row]) { - structure[row] = 1; - nz[(*n_nz)++] = row; + structure[row] = 1; + nz[(*n_nz)++] = row; } - } + } } } } @@ -494,7 +493,7 @@ void FindDetailedStructure(long col, long *structure, long *nz, long n_nz) else { owner = EmbeddedOwner(i); if (owner < 0) - printf("%ld,%ld: %ld\n", BLOCKROW(i), BLOCKCOL(i), owner); + printf("%ld,%ld: %ld\n", BLOCKROW(i), BLOCKCOL(i), owner); BLOCK(i)->structure = (long *) MyMalloc(n*sizeof(long), owner); n = 0; for (j=0; jlength; - BLOCK(b)->nz = (double *) MyMalloc(size*sizeof(double), BLOCK(b)->owner); - for (i=0; inz[i] = 0.0; + size = LB.partition_size[j]*BLOCK(b)->length; + BLOCK(b)->nz = (double *) MyMalloc(size*sizeof(double), BLOCK(b)->owner); + for (i=0; inz[i] = 0.0; } } } @@ -535,12 +534,12 @@ void FillIn(SMatrix M, long col, long *PERM, long *INVP, double *scatter) for (i=M.col[truecol]; i= col) { - if (M.nz) - scatter[row] = M.nz[i]; - else - scatter[row] = Value(M.row[i], truecol); + if (M.nz) + scatter[row] = M.nz[i]; + else + scatter[row] = Value(M.row[i], truecol); } - + } for (i=LB.col[col]; i= col+j1) { - if (M.nz) - scatter[row] = M.nz[i]; - else - scatter[row] = Value(M.row[i], truecol); - } + row = INVP[M.row[i]]; + if (row >= col+j1) { + if (M.nz) + scatter[row] = M.nz[i]; + else + scatter[row] = Value(M.row[i], truecol); + } } for (b=LB.col[col]; blength; i++) { - if (BLOCK(b)->structure) - row = LB.row[b] + BLOCK(b)->structure[i]; - else row = LB.row[b] + i; - BLOCK(b)->nz[i+j1*BLOCK(b)->length] = - scatter[row]; - scatter[row] = 0.0; - } + for (i=0; ilength; i++) { + if (BLOCK(b)->structure) + row = LB.row[b] + BLOCK(b)->structure[i]; + else row = LB.row[b] + i; + BLOCK(b)->nz[i+j1*BLOCK(b)->length] = + scatter[row]; + scatter[row] = 0.0; + } } } } diff --git a/splash2/codes/kernels/cholesky/fo.C b/splash2/codes/kernels/cholesky/fo.C index 22f3f51f8..f73741c28 100644 --- a/splash2/codes/kernels/cholesky/fo.C +++ b/splash2/codes/kernels/cholesky/fo.C @@ -16,9 +16,8 @@ EXTERN_ENV -#include - #include "matrix.h" +#include extern struct GlobalMemory *Global; extern BMatrix LB; @@ -41,9 +40,9 @@ void PreAllocate1FO() long i; AllBlocks = (struct BlockList ***) MyMalloc(P*sizeof(struct BlockList **), - DISTRIBUTED); + DISTRIBUTED); DiagBlock = (struct BlockList ***) MyMalloc(P*sizeof(struct BlockList **), - DISTRIBUTED); + DISTRIBUTED); ToReceive = (long **) MyMalloc(P*sizeof(long *), DISTRIBUTED); NReceived = (long **) MyMalloc(P*sizeof(long *), DISTRIBUTED); for (i=0; i lc->max_panel) - lc->max_panel = LB.col[i+node[i]]-LB.col[i]; + lc->max_panel = LB.col[i+node[i]]-LB.col[i]; j = LB.col[i+1]-LB.col[i]-node[i]; if (j*(j+1)/2 > lc->max_panel) - lc->max_panel = j*(j+1)/2; + lc->max_panel = j*(j+1)/2; } if (LB.max_partition > BS) { /* if blocks need to be copied */ @@ -101,14 +100,14 @@ void PreAllocateFO(long MyNum, struct LocalCopies *lc) update_size = LB.col[root+1]-LB.col[root]-1; update_size = update_size*(update_size+1)/2; if (update_size) { - LB.proc_domain_storage[i] = (double *) MyMalloc(update_size* - sizeof(double), - MyNum); + LB.proc_domain_storage[i] = (double *) MyMalloc(update_size* + sizeof(double), + MyNum); for (j=0; jowner == MyNum && - BLOCK(LB.col[j])->remaining == 0) - BlockReadyFO(LB.col[j], MyNum, lc); + BLOCK(LB.col[j])->remaining == 0) + BlockReadyFO(LB.col[j], MyNum, lc); } - if (some) + if (some) while (HandleTaskFO(MyNum, lc)) ; @@ -196,7 +195,7 @@ void DiagReceived(long diag, long MyNum, struct LocalCopies *lc) column = BLOCKCOL(diag); for (i=LB.col[column]+1; iowner == MyNum && - BLOCK(i)->remaining == 0) { + BLOCK(i)->remaining == 0) { BDiv(diagbl->length, BLOCK(i)->length, diagbl->nz, BLOCK(i)->nz, lc); BlockDoneFO(i, MyNum, lc); } @@ -252,7 +251,7 @@ struct BlockList *CopyOneBlock(long block, long MyNum) bl->theBlock = block; bl->row = BLOCKROW(block); bl->col = BLOCKCOL(block); bl->length = BLOCK(block)->length; - + bl->structure = BLOCK(block)->structure; bl->nz = BLOCK(block)->nz; @@ -263,7 +262,7 @@ struct BlockList *CopyOneBlock(long block, long MyNum) void FreeColumnListFO(long p, long col) { struct BlockList *bl; - + while (AllBlocks[p][col]) { bl = AllBlocks[p][col]; AllBlocks[p][col] = bl->next; @@ -283,7 +282,7 @@ void DecrementRemaining(long dest_block, long MyNum, struct LocalCopies *lc) if (BLOCK(dest_block)->remaining == 0) BlockReadyFO(dest_block, MyNum, lc); else if (BLOCK(dest_block)->remaining == -1) - printf("*** Error rem ***\n"); + printf("*** Error rem ***\n"); } @@ -321,9 +320,9 @@ void PerformUpdate(struct BlockList *above_bl, struct BlockList *below_bl, long if (destination == lc->updatetmp) { ScatterUpdateFO(below_bl->length, below_bl->structure, - below_bl->length, below_bl->structure, - BLOCK(dest_block)->length, - lc->updatetmp, BLOCK(dest_block)->nz); + below_bl->length, below_bl->structure, + BLOCK(dest_block)->length, + lc->updatetmp, BLOCK(dest_block)->nz); } } @@ -338,7 +337,7 @@ void PerformUpdate(struct BlockList *above_bl, struct BlockList *below_bl, long FindRelativeIndices(below_bl->structure, below_bl->length, BLOCK(dest_block)->structure, lc->relative); relative_i = lc->relative; } - + if (above_bl->structure) relative_j = above_bl->structure; else @@ -354,9 +353,9 @@ void PerformUpdate(struct BlockList *above_bl, struct BlockList *below_bl, long if (destination == lc->updatetmp) { ScatterUpdateFO(below_bl->length, relative_i, - above_bl->length, relative_j, - BLOCK(dest_block)->length, - lc->updatetmp, BLOCK(dest_block)->nz); + above_bl->length, relative_j, + BLOCK(dest_block)->length, + lc->updatetmp, BLOCK(dest_block)->nz); } } @@ -376,7 +375,7 @@ void DistributeUpdateFO(long which_domain, long MyNum, struct LocalCopies *lc) dest_block = FindBlock(desti, destj); Send(which_domain, dest_block, bi, bj, (struct Update *) -19, - OWNER(dest_block), MyNum, lc); + OWNER(dest_block), MyNum, lc); } } } @@ -418,9 +417,9 @@ void HandleUpdate2FO(long which_domain, long bli, long blj, long MyNum, struct L relative_j = NULL; ScatterUpdateFO2(BLOCK(bli)->length, relative_i, - BLOCK(blj)->length, relative_j, - stride, BLOCK(dest_block)->length, - update, BLOCK(dest_block)->nz); + BLOCK(blj)->length, relative_j, + stride, BLOCK(dest_block)->length, + update, BLOCK(dest_block)->nz); DecrementRemaining(dest_block, MyNum, lc); } @@ -485,7 +484,7 @@ void BlockDoneFO(long block, long MyNum, struct LocalCopies *lc) /* send to column */ for (i=0; iremaining) { - bogus = 1; - } + if (BLOCK(i)->remaining) { + bogus = 1; + } } if (bogus) @@ -519,9 +518,9 @@ void CheckReceived() for (p=0; pnmod = 0; + BLOCK(i)->nmod = 0; } /* domain updates */ for (k=0; knmod++; + destj = BLOCKROW(j); + desti = BLOCKROW(i); + dest_block = FindBlock(desti, destj); + BLOCK(dest_block)->nmod++; } desti = BLOCKROW(i); dest_block = FindBlock(desti, desti); @@ -561,15 +560,15 @@ void ComputeRemainingFO() for (k=0; knmod++; - } - desti = BLOCKROW(i); - dest_block = FindBlock(desti, desti); - BLOCK(dest_block)->nmod++; + for (j=LB.col[k]+1; jnmod++; + } + desti = BLOCKROW(i); + dest_block = FindBlock(desti, desti); + BLOCK(dest_block)->nmod++; } } } @@ -583,8 +582,8 @@ void InitRemainingFO(long MyNum) for (k=0; kowner == MyNum) - BLOCK(i)->remaining = BLOCK(i)->nmod; + if (MyNum == -1 || BLOCK(i)->owner == MyNum) + BLOCK(i)->remaining = BLOCK(i)->nmod; } @@ -600,30 +599,30 @@ void ComputeReceivedFO() for (k=0; k= alloc_size) { /* Found one! */ - leftover = block_size - alloc_size - 2*sizeof(long); + leftover = block_size - alloc_size - 2*sizeof(long); result = d + (leftover/sizeof(long)) + 2; - SIZE(result) = alloc_size; - HOME(result) = home; + SIZE(result) = alloc_size; + HOME(result) = home; - if (leftover > MAXFASTBL) { - SIZE(d) = leftover; - } - else { - /* don't leave a block */ + if (leftover > MAXFASTBL) { + SIZE(d) = leftover; + } + else { + /* don't leave a block */ - /* unlink 'd' */ - if (prev) - NEXTFREE(prev) = NEXTFREE(d); - else - mem_pool[home].freeBlock[MAXFAST] = NEXTFREE(d); + /* unlink 'd' */ + if (prev) + NEXTFREE(prev) = NEXTFREE(d); + else + mem_pool[home].freeBlock[MAXFAST] = NEXTFREE(d); - if (leftover > 0) { - SIZE(d) = leftover; - MyFreeNow(d); - } - } + if (leftover > 0) { + SIZE(d) = leftover; + MyFreeNow(d); + } + } break; } @@ -208,7 +208,7 @@ char *MyMalloc(long size, long home) else { mem_pool[home].tally += SIZE(freespace); if (mem_pool[home].tally > mem_pool[home].maxm) { - mem_pool[home].maxm = mem_pool[home].tally; + mem_pool[home].maxm = mem_pool[home].tally; } MyFree(freespace); result = (long *) MyMalloc(alloc_size, home); @@ -257,10 +257,10 @@ void MigrateMem(long *start, long length, long home) } else { Place all addresses x such that (currpage <= x < endpage) on node home - } + } */ } - + void MyFree(long *block) { diff --git a/splash2/codes/kernels/cholesky/matrix.H b/splash2/codes/kernels/cholesky/matrix.H index d9071ebf6..cb3fdaa7e 100644 --- a/splash2/codes/kernels/cholesky/matrix.H +++ b/splash2/codes/kernels/cholesky/matrix.H @@ -14,7 +14,7 @@ /* */ /*************************************************************************/ -#include +#include #define FitsInCache 2048 @@ -22,38 +22,38 @@ #define PAGE_SIZE 4096 typedef struct { - long n, m, *col, *startrow, *row; - double *nz; - } SMatrix; + long n, m, *col, *startrow, *row; + double *nz; + } SMatrix; struct Pair { - long block_num; - struct Pair *next; - }; + long block_num; + struct Pair *next; + }; typedef struct { long i, j, owner, remaining, nmod; - long length; /* number of full rows in block */ - long parent; /* block number of parent block */ - double checksum; - volatile unsigned long done; - long *structure, *relative; - double *nz; - struct Pair *pair; + long length; /* number of full rows in block */ + long parent; /* block number of parent block */ + double checksum; + volatile unsigned long done; + long *structure, *relative; + double *nz; + struct Pair *pair; } Block; typedef union { Block *block; - double nz; + double nz; } Entry; - + typedef struct { long n, *col, *row, n_blocks, n_entries, entries_allocated; - long *partition_size, *renumbering, *mapI, *mapJ; - long *domain, *domains, n_domains, *proc_domains; - long n_partitions, max_partition; - double **proc_domain_storage; - Entry *entry; + long *partition_size, *renumbering, *mapI, *mapJ; + long *domain, *domains, n_domains, *proc_domains; + long n_partitions, max_partition; + double **proc_domain_storage; + Entry *entry; } BMatrix; #define BLOCK(bl_no) (LB.entry[bl_no].block) @@ -62,10 +62,10 @@ typedef struct { #define OWNER(bl_no) (BLOCK(bl_no)->owner) struct Update { - long i, j, src, remaining; - long dimi, dimj, *structi, *structj; - double *update; - struct Update *next; + long i, j, src, remaining; + long dimi, dimj, *structi, *structj; + double *update; + struct Update *next; }; struct Task { @@ -75,18 +75,18 @@ struct Task { }; struct GlobalMemory { - BARDEC(start) - LOCKDEC(waitLock) - LOCKDEC(memLock) - unsigned long runtime[MAX_PROC]; - }; + BARDEC(start) + LOCKDEC(waitLock) + LOCKDEC(memLock) + unsigned long runtime[MAX_PROC]; + }; struct BlockList { - long theBlock, row, col, length; - long *structure; - double *nz; - struct BlockList *next; - }; + long theBlock, row, col, length; + long *structure; + double *nz; + struct BlockList *next; + }; struct LocalCopies { double *blktmp; diff --git a/splash2/codes/kernels/cholesky/mf.C b/splash2/codes/kernels/cholesky/mf.C index 6168e31f3..78e2dece5 100644 --- a/splash2/codes/kernels/cholesky/mf.C +++ b/splash2/codes/kernels/cholesky/mf.C @@ -17,7 +17,6 @@ EXTERN_ENV #include "matrix.h" - #define HashNum 1024 #define Bucket(desti, destj, src) ((desti+destj+src)%HashNum) @@ -26,12 +25,12 @@ extern struct GlobalMemory *Global; struct Update **updateHash; struct taskQ { - LOCKDEC(taskLock) - struct Task *volatile taskQ; - struct Task *volatile taskQlast; - struct Task *volatile probeQ; - struct Task *volatile probeQlast; - } *tasks; + LOCKDEC(taskLock) + struct Task *volatile taskQ; + struct Task *volatile taskQlast; + struct Task *volatile probeQ; + struct Task *volatile probeQlast; + } *tasks; extern BMatrix LB; @@ -139,14 +138,14 @@ void GetBlock(long *desti, long *destj, long *src, struct Update **update, long if (tasks[MyNum].probeQ) { t = (struct Task *) tasks[MyNum].probeQ; tasks[MyNum].probeQ = t->next; - if (!t->next) - tasks[MyNum].probeQlast = NULL; + if (!t->next) + tasks[MyNum].probeQlast = NULL; } else if (tasks[MyNum].taskQ) { t = (struct Task *) tasks[MyNum].taskQ; tasks[MyNum].taskQ = t->next; - if (!t->next) - tasks[MyNum].taskQlast = NULL; + if (!t->next) + tasks[MyNum].taskQlast = NULL; } UNLOCK(tasks[MyNum].taskLock) if (t) diff --git a/splash2/codes/kernels/cholesky/numLL.C b/splash2/codes/kernels/cholesky/numLL.C index 5b9dac360..0059954e0 100644 --- a/splash2/codes/kernels/cholesky/numLL.C +++ b/splash2/codes/kernels/cholesky/numLL.C @@ -16,12 +16,11 @@ EXTERN_ENV -#include - #include "matrix.h" +#include #define AddMember(set, new) { long s, n; s = set; n = new; \ - lc->link[n] = lc->link[s]; lc->link[s] = n; } + lc->link[n] = lc->link[s]; lc->link[s] = n; } extern BMatrix LB; extern struct GlobalMemory *Global; @@ -67,38 +66,38 @@ void FactorLLDomain(long which_domain, long MyNum, struct LocalCopies *lc) theFirst = lc->first[k]; theLast = theFirst+1; while (theLast < k_length && LB.row[LB.col[k]+theLast] < j_last) - theLast++; + theLast++; if (theLast-theFirst == node[j] && - k_length-theFirst == j_len) { - ModifySuperBySuper(k, theFirst, theLast, k_length, - (double *) &LB.entry[LB.col[j]].nz); + k_length-theFirst == j_len) { + ModifySuperBySuper(k, theFirst, theLast, k_length, + (double *) &LB.entry[LB.col[j]].nz); } else if (node[k] > 1) { - ModifySuperBySuper(k, theFirst, theLast, k_length, lc->storage); - FindRelativeIndicesLeft(&LB.row[LB.col[k]+theFirst], - k_length-theFirst, 0, indices, relative); - ScatterSuperUpdate(lc->storage, theLast-theFirst, k_length-theFirst, - (double *) &LB.entry[LB.col[j]].nz, - j_len, relative); + ModifySuperBySuper(k, theFirst, theLast, k_length, lc->storage); + FindRelativeIndicesLeft(&LB.row[LB.col[k]+theFirst], + k_length-theFirst, 0, indices, relative); + ScatterSuperUpdate(lc->storage, theLast-theFirst, k_length-theFirst, + (double *) &LB.entry[LB.col[j]].nz, + j_len, relative); } else { - FindRelativeIndicesLeft(&LB.row[LB.col[k]+theFirst], - k_length-theFirst, 0, indices, relative); - ModifySuperByColumn((double *) &LB.entry[LB.col[k]+theFirst].nz, - theLast-theFirst, k_length-theFirst, - (double *) &LB.entry[LB.col[j]].nz, - j_len, relative); + FindRelativeIndicesLeft(&LB.row[LB.col[k]+theFirst], + k_length-theFirst, 0, indices, relative); + ModifySuperByColumn((double *) &LB.entry[LB.col[k]+theFirst].nz, + theLast-theFirst, k_length-theFirst, + (double *) &LB.entry[LB.col[j]].nz, + j_len, relative); } lc->first[k] = theLast; /* move on */ if (theLast < k_length) { - dest_super = LB.row[LB.col[k]+theLast]; - if (dest_super > root) - dest_super = root+1; - else if (node[dest_super] < 0) - dest_super += node[dest_super]; - AddMember(dest_super, k); + dest_super = LB.row[LB.col[k]+theLast]; + if (dest_super > root) + dest_super = root+1; + else if (node[dest_super] < 0) + dest_super += node[dest_super]; + AddMember(dest_super, k); } } @@ -108,9 +107,9 @@ void FactorLLDomain(long which_domain, long MyNum, struct LocalCopies *lc) if (lc->first[j] < j_len) { dest_super = LB.row[LB.col[j]+lc->first[j]]; if (dest_super > root) - dest_super = root+1; + dest_super = root+1; else if (node[dest_super] < 0) - dest_super += node[dest_super]; + dest_super += node[dest_super]; AddMember(dest_super, j); } } @@ -127,7 +126,7 @@ void FactorLLDomain(long which_domain, long MyNum, struct LocalCopies *lc) domain_update = LB.proc_domain_storage[which_domain]; else { domain_update = (double *) MyMalloc(update_size*sizeof(double), - MyNum); + MyNum); LB.proc_domain_storage[which_domain] = domain_update; } for (i=0; i 1) { ModifySuperBySuper(k, theFirst, theLast, k_length, lc->storage); FindRelativeIndicesLeft(&LB.row[LB.col[k]+theFirst], k_length-theFirst, - 0, indices, relative); + 0, indices, relative); ScatterSuperUpdate(lc->storage, k_length-theFirst, k_length-theFirst, - domain_update, j_len, relative); + domain_update, j_len, relative); } else { FindRelativeIndicesLeft(&LB.row[LB.col[k]+theFirst], - k_length-theFirst, 0, indices, relative); + k_length-theFirst, 0, indices, relative); ModifySuperByColumn((double *) &LB.entry[LB.col[k]+theFirst].nz, - theLast-theFirst, k_length-theFirst, - domain_update, j_len, relative); + theLast-theFirst, k_length-theFirst, + domain_update, j_len, relative); } } @@ -197,27 +196,27 @@ void CompleteSupernodeB(long super) i = first; for (; i - #include "matrix.h" +#include + struct Chunk { - long first, last, assign; - struct Chunk *next; - } *chunks_head = NULL, *chunks_tail = NULL; + long first, last, assign; + struct Chunk *next; + } *chunks_head = NULL, *chunks_tail = NULL; long tolerance = 20; @@ -61,16 +61,16 @@ void Partition(SMatrix M, long parts, long *T, long *assigned_ops, long *domain, maxm = assigned_ops[MaxBucket(assigned_ops, parts)]; if (maxm == 0 || - (100.0*(maxm - minm)/(double) maxm < tolerance) || - (1.0*parts*maxm/work_tree[M.n] < 0.05)) - break; + (100.0*(maxm - minm)/(double) maxm < tolerance) || + (1.0*parts*maxm/work_tree[M.n] < 0.05)) + break; t = GetChunk(); change = Divide(t); if (!change) - break; + break; NumberPartition(parts, assigned_ops, 0); } @@ -182,7 +182,7 @@ long Divide(struct Chunk *root) first_in_super = root->last-1; while (firstchild[first_in_super]+1 == - firstchild[first_in_super+1]) { + firstchild[first_in_super+1]) { first_in_super--; } @@ -202,80 +202,80 @@ long Divide(struct Chunk *root) long MaxBucket(long *assigned_ops, long parts) { - long i, maxm, ind; + long i, maxm, ind; - maxm = assigned_ops[0]; ind = 0; - for (i=1; i maxm) { - ind = i; maxm = assigned_ops[i]; - } + maxm = assigned_ops[0]; ind = 0; + for (i=1; i maxm) { + ind = i; maxm = assigned_ops[i]; + } - return(ind); + return(ind); } long MinBucket(long *assigned_ops, long parts) { - long i, minm, ind; + long i, minm, ind; - minm = assigned_ops[0]; ind = 0; - for (i=1; ilast-1]; - current = chunks_head; - if (!current) { - t->next = NULL; - chunks_head = t; - } - else if (work >= work_tree[current->last-1]) { - t->next = chunks_head; - chunks_head = t; - } - else { - while (current->next && worknext->last-1]) - current = current->next; - t->next = current->next; - current->next = t; - } - - if (t->next == NULL) - chunks_tail = t; + work = work_tree[t->last-1]; + current = chunks_head; + if (!current) { + t->next = NULL; + chunks_head = t; + } + else if (work >= work_tree[current->last-1]) { + t->next = chunks_head; + chunks_head = t; + } + else { + while (current->next && worknext->last-1]) + current = current->next; + t->next = current->next; + current->next = t; + } + + if (t->next == NULL) + chunks_tail = t; } struct Chunk *GetChunk() { - struct Chunk *t; + struct Chunk *t; - t = chunks_head; - if (t) { - chunks_head = t->next; - if (t == chunks_tail) - chunks_tail = NULL; - } + t = chunks_head; + if (t) { + chunks_head = t->next; + if (t == chunks_tail) + chunks_tail = NULL; + } - return(t); + return(t); } diff --git a/splash2/codes/kernels/cholesky/seg.C b/splash2/codes/kernels/cholesky/seg.C index f02644717..1b1d1d227 100644 --- a/splash2/codes/kernels/cholesky/seg.C +++ b/splash2/codes/kernels/cholesky/seg.C @@ -16,9 +16,8 @@ EXTERN_ENV -#include - #include "matrix.h" +#include double max_block_size; extern long *node; @@ -40,7 +39,7 @@ void ComputeTargetBlockSize(SMatrix M, long P) max_block_size = sqrt(total_ops/(3*max_ht)/P); printf("%ld max height, %.0f ops, %.2f conc, %.2f bl for %ld P\n", - max_ht, total_ops, total_ops/(3*max_ht), max_block_size, P); + max_ht, total_ops, total_ops/(3*max_ht), max_block_size, P); } diff --git a/splash2/codes/kernels/cholesky/solve.C b/splash2/codes/kernels/cholesky/solve.C index 8270c9b29..30764c289 100644 --- a/splash2/codes/kernels/cholesky/solve.C +++ b/splash2/codes/kernels/cholesky/solve.C @@ -33,8 +33,7 @@ MAIN_ENV -#include - +#include #include "matrix.h" #define SH_MEM_AMT 100000000 @@ -100,11 +99,11 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "B:C:p:D:sth")) != -1) { switch(c) { - case 'B': postpass_partition_size = atoi(optarg); break; - case 'C': CacheSize = (double) atoi(optarg); break; - case 'p': P = atol(optarg); break; - case 's': do_stats = 1; break; - case 't': do_test = 1; break; + case 'B': postpass_partition_size = atoi(optarg); break; + case 'C': CacheSize = (double) atoi(optarg); break; + case 'p': P = atol(optarg); break; + case 's': do_stats = 1; break; + case 't': do_test = 1; break; case 'h': printf("Usage: CHOLESKY file\n\n"); printf("options:\n"); printf(" -Bb : Use a postpass partition size of b.\n"); @@ -134,7 +133,7 @@ int main(int argc, char *argv[]) LOCKINIT(Global->waitLock) LOCKINIT(Global->memLock) - MallocInit(P); + MallocInit(P); i = 0; while (++i < argc && argv[i][0] == '-') @@ -157,7 +156,7 @@ int main(int argc, char *argv[]) printf("Fan-out, "); printf("no block copy-across\n"); - printf("LB domain, "); + printf("LB domain, "); printf("embedded "); printf("distribution\n"); @@ -215,11 +214,11 @@ int main(int argc, char *argv[]) if (domain[i]) num_domain += nz[i]; } - + ComputeTargetBlockSize(M, P); printf("Target partition size %ld, postpass size %ld\n", - target_partition_size, postpass_partition_size); + target_partition_size, postpass_partition_size); NoSegments(M); @@ -235,7 +234,7 @@ int main(int argc, char *argv[]) ps = postpass_partition_size; num_alloc = num_domain + (num_nz-num_domain)*10/ps/ps; CreateBlockedMatrix2(M, num_alloc, T, firstchild, child, PERM, INVP, - domain, partition); + domain, partition); FillInStructure(M, firstchild, child, PERM, INVP); @@ -326,7 +325,7 @@ void Go() processors to avoid migration */ lc =(struct LocalCopies *) G_MALLOC(sizeof(struct LocalCopies)+2*PAGE_SIZE, - MyNum) + MyNum) lc->freeUpdate = NULL; lc->freeTask = NULL; lc->runtime = 0; @@ -368,7 +367,7 @@ void Go() if (MyNum == 0) { gp->initdone = lc->rs; gp->finish = lc->rf; - } + } BARRIER(Global->start, P); @@ -390,15 +389,15 @@ void PlaceDomains(long P) range_start = (char *) &LB.row[LB.col[first]]; range_end = (char *) &LB.row[LB.col[LB.domains[d]+1]]; MigrateMem(&LB.row[LB.col[first]], - (LB.col[LB.domains[d]+1]-LB.col[first])*sizeof(long), - p); + (LB.col[LB.domains[d]+1]-LB.col[first])*sizeof(long), + p); /* place non-zeroes */ range_start = (char *) &BLOCK(LB.col[first]); range_end = (char *) &BLOCK(LB.col[LB.domains[d]+1]); MigrateMem(&BLOCK(LB.col[first]), - (LB.col[LB.domains[d]+1]-LB.col[first])*sizeof(double), - p); + (LB.col[LB.domains[d]+1]-LB.col[first])*sizeof(double), + p); } } diff --git a/splash2/codes/kernels/cholesky/tree.C b/splash2/codes/kernels/cholesky/tree.C index f27f2cf0d..f02d2ba4b 100644 --- a/splash2/codes/kernels/cholesky/tree.C +++ b/splash2/codes/kernels/cholesky/tree.C @@ -40,18 +40,18 @@ void EliminationTreeFromA(SMatrix A, long *T, long *P, long *INVP) if (nabor < j) { - for (r=nabor; subtree[r] != A.n; r = subtree[r]) - ; - if (r != j) - T[r] = subtree[r] = root = j; - else root = r; + for (r=nabor; subtree[r] != A.n; r = subtree[r]) + ; + if (r != j) + T[r] = subtree[r] = root = j; + else root = r; - r = nabor; - while (subtree[r] != A.n) { - nextr = subtree[r]; - subtree[r] = root; - r = nextr; - } + r = nabor; + while (subtree[r] != A.n) { + nextr = subtree[r]; + subtree[r] = root; + r = nextr; + } } } } @@ -73,8 +73,8 @@ void ParentToChild(long *T, long n, long *firstchild, long *child) for (i=n; i>=0; i--) { parent = T[i]; if (parent != i) { - next[i] = firstchild[parent]; - firstchild[parent] = i; + next[i] = firstchild[parent]; + firstchild[parent] = i; } } @@ -111,8 +111,8 @@ void ComputeNZ(SMatrix A, long *T, long *nz, long *PERM, long *INVP) k = nabor; while (marker[k] != i && k < i) { nz[k]++; - marker[k] = i; - k = T[k]; + marker[k] = i; + k = T[k]; } } } @@ -145,7 +145,7 @@ void FindSupernodes(SMatrix A, long *T, long *nz, long *node) else { node[current] = size; if (size > max_super) - max_super = size; + max_super = size; supers++; current = i; size = 1; @@ -158,7 +158,7 @@ void FindSupernodes(SMatrix A, long *T, long *nz, long *node) node[A.n] = 0; printf("%ld supers, %4.2f nodes/super, %ld max super\n", - supers, A.n/(double) supers, max_super); + supers, A.n/(double) supers, max_super); free(nchild); } diff --git a/splash2/codes/kernels/cholesky/util.C b/splash2/codes/kernels/cholesky/util.C index dbaf47944..3a7ef1f19 100644 --- a/splash2/codes/kernels/cholesky/util.C +++ b/splash2/codes/kernels/cholesky/util.C @@ -16,9 +16,8 @@ EXTERN_ENV -#include -#include - +#include +#include #include "matrix.h" #define Error(m) { printf(m); exit(0); } @@ -35,9 +34,9 @@ SMatrix NewMatrix(long n, long m, long nz) M.startrow = (long *) MyMalloc((n+1)*sizeof(long), DISTRIBUTED); M.row = (long *) MyMalloc((m+n)*sizeof(long), DISTRIBUTED); if (nz) { - M.nz = (double *) MyMalloc((m+n)*sizeof(double), DISTRIBUTED); + M.nz = (double *) MyMalloc((m+n)*sizeof(double), DISTRIBUTED); } else { - M.nz = NULL; + M.nz = NULL; } if (!M.col || !M.row || (nz && !M.nz)) { @@ -77,119 +76,119 @@ double *NewVector(long n) double Value(long i, long j) { if (i == j) { - return((double) maxm+0.1); + return((double) maxm+0.1); } else { - return(-1.0); + return(-1.0); } } SMatrix ReadSparse(char *name, char *probName) { - FILE *fp; - long n, m, i, j; - long n_rows, tmp; - long numer_lines; - long colnum, colsize, rownum, rowsize; - char buf[100], type[4]; - SMatrix M, F; + FILE *fp; + long n, m, i, j; + long n_rows, tmp; + long numer_lines; + long colnum, colsize, rownum, rowsize; + char buf[100], type[4]; + SMatrix M, F; - if (!name || name[0] == 0) { - fp = stdin; - } else { - fp = fopen(name, "r"); - } + if (!name || name[0] == 0) { + fp = stdin; + } else { + fp = fopen(name, "r"); + } - if (!fp) { - Error("Error opening file\n"); - } + if (!fp) { + Error("Error opening file\n"); + } - fscanf(fp, "%72c", buf); + fscanf(fp, "%72c", buf); - fscanf(fp, "%8c", probName); - probName[8] = 0; - DumpLine(fp); + fscanf(fp, "%8c", probName); + probName[8] = 0; + DumpLine(fp); - for (i=0; i<5; i++) { - fscanf(fp, "%14c", buf); - sscanf(buf, "%ld", &tmp); - if (i == 3) - numer_lines = tmp; - } - DumpLine(fp); + for (i=0; i<5; i++) { + fscanf(fp, "%14c", buf); + sscanf(buf, "%ld", &tmp); + if (i == 3) + numer_lines = tmp; + } + DumpLine(fp); - fscanf(fp, "%3c", type); - type[3] = 0; - if (!(type[0] != 'C' && type[1] == 'S' && type[2] == 'A')) { - fprintf(stderr, "Wrong type: %s\n", type); - exit(0); - } + fscanf(fp, "%3c", type); + type[3] = 0; + if (!(type[0] != 'C' && type[1] == 'S' && type[2] == 'A')) { + fprintf(stderr, "Wrong type: %s\n", type); + exit(0); + } - fscanf(fp, "%11c", buf); /* pad */ + fscanf(fp, "%11c", buf); /* pad */ - fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &n_rows); + fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &n_rows); - fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &n); + fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &n); - fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &m); + fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &m); - fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &tmp); - if (tmp != 0) - printf("This is not an assembled matrix!\n"); - if (n_rows != n) - printf("Matrix is not symmetric\n"); - DumpLine(fp); + fscanf(fp, "%14c", buf); sscanf(buf, "%ld", &tmp); + if (tmp != 0) + printf("This is not an assembled matrix!\n"); + if (n_rows != n) + printf("Matrix is not symmetric\n"); + DumpLine(fp); - fscanf(fp, "%16c", buf); - ParseIntFormat(buf, &colnum, &colsize); - fscanf(fp, "%16c", buf); - ParseIntFormat(buf, &rownum, &rowsize); - fscanf(fp, "%20c", buf); - fscanf(fp, "%20c", buf); + fscanf(fp, "%16c", buf); + ParseIntFormat(buf, &colnum, &colsize); + fscanf(fp, "%16c", buf); + ParseIntFormat(buf, &rownum, &rowsize); + fscanf(fp, "%20c", buf); + fscanf(fp, "%20c", buf); + + DumpLine(fp); /* format statement */ - DumpLine(fp); /* format statement */ + M = NewMatrix(n, m, 0); - M = NewMatrix(n, m, 0); + ReadVector(fp, n+1, M.col, colnum, colsize); - ReadVector(fp, n+1, M.col, colnum, colsize); + ReadVector(fp, m, M.row, rownum, rowsize); - ReadVector(fp, m, M.row, rownum, rowsize); + for (i=0; i maxm) + maxm = F.col[i+1]-F.col[i]; - maxm = 0; - for (i=0; i maxm) - maxm = F.col[i+1]-F.col[i]; + if (F.nz) { + for (j=0; j= i) { - M.row[ind++] = L.row[j]; + M.row[ind++] = L.row[j]; } } @@ -255,7 +254,7 @@ SMatrix LowerToFull(SMatrix L) M.row[ind++] = j; first[j]++; if (first[j] < L.col[j+1]) { - AddMember(L.row[first[j]], j); + AddMember(L.row[first[j]], j); } j = nextj; } @@ -266,7 +265,7 @@ SMatrix LowerToFull(SMatrix L) } else { fprintf(stderr, "Missing diagonal: %ld: ", i); for (j=L.col[i]; j tmp && j > lo) { - M.row[j] = M.row[j-1]; - j--; - } - M.row[j] = tmp; - } + for (i=lo; i tmp && j > lo) { + M.row[j] = M.row[j-1]; + j--; + } + M.row[j] = tmp; + } } diff --git a/splash2/codes/kernels/fft/fft.C b/splash2/codes/kernels/fft/fft.C index eb4a41ed5..6404b2411 100644 --- a/splash2/codes/kernels/fft/fft.C +++ b/splash2/codes/kernels/fft/fft.C @@ -43,11 +43,10 @@ /* */ /*************************************************************************/ -#include -#include - +#include +#include #define PAGE_SIZE 4096 -#define NUM_CACHE_LINES 65536 +#define NUM_CACHE_LINES 65536 #define LOG2_LINE_SIZE 4 #define PI 3.1416 #define DEFAULT_M 10 @@ -108,7 +107,7 @@ void InitU(long N, double *u); void InitU2(long N, double *u, long n1); long BitReverse(long M, long k); void FFT1D(long direction, long M, long N, double *x, double *scratch, double *upriv, double *umain2, - long MyNum, long *l_transtime, long MyFirst, long MyLast, long pad_length, long test_result, long dostats); + long MyNum, long *l_transtime, long MyFirst, long MyLast, long pad_length, long test_result, long dostats); void TwiddleOneCol(long direction, long n1, long j, double *u, double *x, long pad_length); void Scale(long n1, long N, double *x); void Transpose(long n1, double *src, double *dest, long MyNum, long MyFirst, long MyLast, long pad_length); @@ -124,7 +123,7 @@ double drand48(void); int main(int argc, char *argv[]) { - long i; + long i; long c; extern char *optarg; long m1; @@ -136,7 +135,7 @@ int main(int argc, char *argv[]) while ((c = getopt(argc, argv, "p:m:n:l:stoh")) != -1) { switch(c) { - case 'p': P = atoi(optarg); + case 'p': P = atoi(optarg); if (P < 1) { printerr("P must be >= 1\n"); exit(-1); @@ -145,33 +144,33 @@ int main(int argc, char *argv[]) printerr("P must be a power of 2\n"); exit(-1); } - break; - case 'm': M = atoi(optarg); + break; + case 'm': M = atoi(optarg); m1 = M/2; if (2*m1 != M) { printerr("M must be even\n"); exit(-1); } - break; - case 'n': num_cache_lines = atoi(optarg); + break; + case 'n': num_cache_lines = atoi(optarg); orig_num_lines = num_cache_lines; if (num_cache_lines < 1) { printerr("Number of cache lines must be >= 1\n"); exit(-1); } - break; - case 'l': log2_line_size = atoi(optarg); + break; + case 'l': log2_line_size = atoi(optarg); if (log2_line_size < 0) { printerr("Log base 2 of cache line length in bytes must be >= 0\n"); exit(-1); } - break; - case 's': dostats = !dostats; - break; - case 't': test_result = !test_result; - break; - case 'o': doprint = !doprint; - break; + break; + case 's': dostats = !dostats; + break; + case 't': test_result = !test_result; + break; + case 'o': doprint = !doprint; + break; case 'h': printf("Usage: FFT \n\n"); printf("options:\n"); printf(" -mM : M = even integer; 2**M total complex data points transformed.\n"); @@ -186,8 +185,8 @@ int main(int argc, char *argv[]) printf(" -h : Print out command line options.\n\n"); printf("Default: FFT -m%1d -p%1d -n%1d -l%1d\n", DEFAULT_M,DEFAULT_P,NUM_CACHE_LINES,LOG2_LINE_SIZE); - exit(0); - break; + exit(0); + break; } } @@ -208,7 +207,7 @@ int main(int argc, char *argv[]) printf(" Computing transpose blocking factor\n"); factor = (2*sizeof(double)) / line_size; num_cache_lines = orig_num_lines / factor; - } + } if (line_size <= 2*sizeof(double)) { pad_length = 1; } else { @@ -235,11 +234,11 @@ int main(int argc, char *argv[]) Global = (struct GlobalMemory *) G_MALLOC(sizeof(struct GlobalMemory)); x = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE); trans = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE); - umain = (double *) G_MALLOC(2*rootN*sizeof(double)); + umain = (double *) G_MALLOC(2*rootN*sizeof(double)); umain2 = (double *) G_MALLOC(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE); - Global->transtimes = (long *) G_MALLOC(P*sizeof(long)); - Global->totaltimes = (long *) G_MALLOC(P*sizeof(long)); + Global->transtimes = (long *) G_MALLOC(P*sizeof(long)); + Global->totaltimes = (long *) G_MALLOC(P*sizeof(long)); if (Global == NULL) { printerr("Could not malloc memory for Global\n"); exit(-1); @@ -261,17 +260,17 @@ int main(int argc, char *argv[]) trans = (double *) (((unsigned long) trans) + PAGE_SIZE - ((unsigned long) trans) % PAGE_SIZE); umain2 = (double *) (((unsigned long) umain2) + PAGE_SIZE - ((unsigned long) umain2) % PAGE_SIZE); -/* In order to optimize data distribution, the data structures x, trans, - and umain2 have been aligned so that each begins on a page boundary. - This ensures that the amount of padding calculated by the program is - such that each processor's partition ends on a page boundary, thus - ensuring that all data from these structures that are needed by a +/* In order to optimize data distribution, the data structures x, trans, + and umain2 have been aligned so that each begins on a page boundary. + This ensures that the amount of padding calculated by the program is + such that each processor's partition ends on a page boundary, thus + ensuring that all data from these structures that are needed by a processor can be allocated to its local memory */ /* POSSIBLE ENHANCEMENT: Here is where one might distribute the x, - trans, and umain2 data structures across physically distributed + trans, and umain2 data structures across physically distributed memories as desired. - + One way to place data is as follows: double *base; @@ -378,23 +377,23 @@ int main(int argc, char *argv[]) printf(" Avg %10.0f %10.0f %8.5f\n", ((double) avgcomptime)/P,((double) avgtranstime)/P,avgfractime/P); printf(" Max %10ld %10ld %8.5f\n", - maxtotal,transtime,maxfrac); + maxtotal,transtime,maxfrac); printf(" Min %10ld %10ld %8.5f\n", - mintotal,transtime2,minfrac); + mintotal,transtime2,minfrac); } Global->starttime = start; printf("\n"); printf(" TIMING INFORMATION\n"); printf("Start time : %16lu\n", - Global->starttime); + Global->starttime); printf("Initialization finish time : %16lu\n", - Global->initdonetime); + Global->initdonetime); printf("Overall finish time : %16lu\n", - Global->finishtime); + Global->finishtime); printf("Total time with initialization : %16lu\n", - Global->finishtime-Global->starttime); + Global->finishtime-Global->starttime); printf("Total time without initialization : %16lu\n", - Global->finishtime-Global->initdonetime); + Global->finishtime-Global->initdonetime); printf("Overall transpose time : %16ld\n", transtime); printf("Overall transpose fraction : %16.5f\n", @@ -405,7 +404,7 @@ int main(int argc, char *argv[]) ck3 = CheckSum(x); printf(" INVERSE FFT TEST RESULTS\n"); printf("Checksum difference is %.3f (%.3f, %.3f)\n", - ck1-ck3, ck1, ck3); + ck1-ck3, ck1, ck3); if (fabs(ck1-ck3) < 0.001) { printf("TEST PASSED\n"); } else { @@ -422,16 +421,16 @@ void SlaveStart() long i; long MyNum; double *upriv; - long initdone; - long finish; + long initdone; + long finish; long l_transtime=0; - long MyFirst; + long MyFirst; long MyLast; LOCK(Global->idlock); MyNum = Global->id; Global->id++; - UNLOCK(Global->idlock); + UNLOCK(Global->idlock); BARINCLUDE(Global->start); @@ -440,14 +439,14 @@ void SlaveStart() BARRIER(Global->start, P); - upriv = (double *) malloc(2*(rootN-1)*sizeof(double)); + upriv = (double *) malloc(2*(rootN-1)*sizeof(double)); if (upriv == NULL) { fprintf(stderr,"Proc %ld could not malloc memory for upriv\n",MyNum); exit(-1); } for (i=0;i<2*(rootN-1);i++) { upriv[i] = umain[i]; - } + } MyFirst = rootN*MyNum/P; MyLast = rootN*(MyNum+1)/P; @@ -464,14 +463,14 @@ void SlaveStart() } /* perform forward FFT */ - FFT1D(1, M, N, x, trans, upriv, umain2, MyNum, &l_transtime, MyFirst, - MyLast, pad_length, test_result, dostats); + FFT1D(1, M, N, x, trans, upriv, umain2, MyNum, &l_transtime, MyFirst, + MyLast, pad_length, test_result, dostats); /* perform backward FFT */ if (test_result) { - FFT1D(-1, M, N, x, trans, upriv, umain2, MyNum, &l_transtime, MyFirst, - MyLast, pad_length, test_result, dostats); - } + FFT1D(-1, M, N, x, trans, upriv, umain2, MyNum, &l_transtime, MyFirst, + MyLast, pad_length, test_result, dostats); + } if ((MyNum == 0) || (dostats)) { CLOCK(finish); @@ -493,15 +492,15 @@ double TouchArray(double *x, double *scratch, double *u, double *upriv, long MyF /* touch my data */ for (j=0;j<2*(rootN-1);j++) { tot += upriv[j]; - } + } for (j=MyFirst; j rootN-1) { - return; + if (base+j > rootN-1) { + return; } u[2*(base+j)] = cos(2.0*PI*j/(2*n1)); u[2*(base+j)+1] = -sin(2.0*PI*j/(2*n1)); @@ -561,11 +560,11 @@ void InitU(long N, double *u) void InitU2(long N, double *u, long n1) { - long i,j,k; + long i,j,k; - for (j=0; jstart, P); @@ -658,11 +657,11 @@ void FFT1D(long direction, long M, long N, double *x, double *scratch, double *u BARRIER(Global->start, P); /* copy columns from scratch to x */ - if ((test_result) || (doprint)) { + if ((test_result) || (doprint)) { for (j=MyFirst; jstart, P); } @@ -671,15 +670,15 @@ void FFT1D(long direction, long M, long N, double *x, double *scratch, double *u void TwiddleOneCol(long direction, long n1, long j, double *u, double *x, long pad_length) { long i; - double omega_r; - double omega_c; - double x_r; + double omega_r; + double omega_c; + double x_r; double x_c; for (i=0; i +#include + +#define PAGE_SIZE 4096 +#define NUM_CACHE_LINES 65536 +#define LOG2_LINE_SIZE 4 +#define PI 3.1416 +#define DEFAULT_M 10 +#define DEFAULT_P 1 + + + +#define SWAP(a,b) {double tmp; tmp=a; a=b; b=tmp;} + +struct GlobalMemory { + int id; + int (idlock); + int (start); + int *transtimes; + int *totaltimes; + int starttime; + int finishtime; + int initdonetime; +} *Global; + + +int P = DEFAULT_P; +int M = DEFAULT_M; +int N; /* N = 2^M */ +int rootN; /* rootN = N^1/2 */ +double *x; /* x is the original time-domain data */ +double *trans; /* trans is used as scratch space */ +double *umain; /* umain is roots of unity for 1D FFTs */ +double *umain2; /* umain2 is entire roots of unity matrix */ +int test_result = 0; +int doprint = 0; +int dostats = 0; +int transtime = 0; +int transtime2 = 0; +int avgtranstime = 0; +int avgcomptime = 0; +unsigned int transstart = 0; +unsigned int transend = 0; +int maxtotal=0; +int mintotal=0; +double maxfrac=0; +double minfrac=0; +double avgfractime=0; +int orig_num_lines = NUM_CACHE_LINES; /* number of cache lines */ +int num_cache_lines = NUM_CACHE_LINES; /* number of cache lines */ +int log2_line_size = LOG2_LINE_SIZE; +int line_size; +int rowsperproc; +double ck1; +double ck3; /* checksums for testing answer */ +int pad_length; + +void SlaveStart(); +double TouchArray(double *,double *,double *,double *,int,int,int,int); +void FFT1D(int,int,int,double *,double *,double *,double *,int,int *,int, + int,int,int,int,int,int,struct GlobalMemory *); +double CheckSum(); +double drand48(); +int log_2(int); +void printerr(char *); + + +main(argc, argv) + +int argc; +char *argv; + +{ + int i; + int j; + int c; + extern char *optarg; + int m1; + int factor; + int pages; + unsigned int start; + + {long time(); (start) = time(0);}; + + while ((c = getopt(argc, argv, "p:m:n:l:stoh")) != -1) { + switch(c) { + case 'p': P = atoi(optarg); + if (P < 1) { + printerr("P must be >= 1\n"); + exit(-1); + } + if (log_2(P) == -1) { + printerr("P must be a power of 2\n"); + exit(-1); + } + break; + case 'm': M = atoi(optarg); + m1 = M/2; + if (2*m1 != M) { + printerr("M must be even\n"); + exit(-1); + } + break; + case 'n': num_cache_lines = atoi(optarg); + orig_num_lines = num_cache_lines; + if (num_cache_lines < 1) { + printerr("Number of cache lines must be >= 1\n"); + exit(-1); + } + break; + case 'l': log2_line_size = atoi(optarg); + if (log2_line_size < 0) { + printerr("Log base 2 of cache line length in bytes must be >= 0\n"); + exit(-1); + } + break; + case 's': dostats = !dostats; + break; + case 't': test_result = !test_result; + break; + case 'o': doprint = !doprint; + break; + case 'h': printf("Usage: FFT \n\n"); + printf("options:\n"); + printf(" -mM : M = even integer; 2**M total complex data points transformed.\n"); + printf(" -pP : P = number of processors; Must be a power of 2.\n"); + printf(" -nN : N = number of cache lines.\n"); + printf(" -lL : L = Log base 2 of cache line length in bytes.\n"); + printf(" -s : Print individual processor timing statistics.\n"); + printf(" -t : Perform FFT and inverse FFT. Test output by comparing the\n"); + printf(" integral of the original data to the integral of the data that\n"); + printf(" results from performing the FFT and inverse FFT.\n"); + printf(" -o : Print out complex data points.\n"); + printf(" -h : Print out command line options.\n\n"); + printf("Default: FFT -m%1d -p%1d -n%1d -l%1d\n", + DEFAULT_M,DEFAULT_P,NUM_CACHE_LINES,LOG2_LINE_SIZE); + exit(0); + break; + } + } + + {;}; + + N = 1<= P\n"); + exit(-1); + } + + line_size = 1 << log2_line_size; + if (line_size < 2*sizeof(double)) { + printf("WARNING: Each element is a complex double (%d bytes)\n",2*sizeof(double)); + printf(" => Less than one element per cache line\n"); + printf(" Computing transpose blocking factor\n"); + factor = (2*sizeof(double)) / line_size; + num_cache_lines = orig_num_lines / factor; + } + if (line_size <= 2*sizeof(double)) { + pad_length = 1; + } else { + pad_length = line_size / (2*sizeof(double)); + } + + if (rowsperproc * rootN * 2 * sizeof(double) >= PAGE_SIZE) { + pages = (2 * pad_length * sizeof(double) * rowsperproc) / PAGE_SIZE; + if (pages * PAGE_SIZE != 2 * pad_length * sizeof(double) * rowsperproc) { + pages ++; + } + pad_length = (pages * PAGE_SIZE) / (2 * sizeof(double) * rowsperproc); + } else { + pad_length = (PAGE_SIZE - (rowsperproc * rootN * 2 * sizeof(double))) / + + (2 * sizeof(double) * rowsperproc); + if (pad_length * (2 * sizeof(double) * rowsperproc) != + (PAGE_SIZE - (rowsperproc * rootN * 2 * sizeof(double)))) { + printerr("Padding algorithm unsuccessful\n"); + exit(-1); + } + } + + Global = (struct GlobalMemory *) malloc(sizeof(struct GlobalMemory));; + x = (double *) malloc(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);; + trans = (double *) malloc(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);; + umain = (double *) malloc(2*rootN*sizeof(double));; + umain2 = (double *) malloc(2*(N+rootN*pad_length)*sizeof(double)+PAGE_SIZE);; + + Global->transtimes = (int *) malloc(P*sizeof(int));; + Global->totaltimes = (int *) malloc(P*sizeof(int));; + if (Global == NULL) { + printerr("Could not malloc memory for Global\n"); + exit(-1); + } else if (x == NULL) { + printerr("Could not malloc memory for x\n"); + exit(-1); + } else if (trans == NULL) { + printerr("Could not malloc memory for trans\n"); + exit(-1); + } else if (umain == NULL) { + printerr("Could not malloc memory for umain\n"); + exit(-1); + } else if (umain2 == NULL) { + printerr("Could not malloc memory for umain2\n"); + exit(-1); + } + + x = (double *) (((unsigned) x) + PAGE_SIZE - ((unsigned) x) % PAGE_SIZE); + trans = (double *) (((unsigned) trans) + PAGE_SIZE - ((unsigned) trans) % PAGE_SIZE); + umain2 = (double *) (((unsigned) umain2) + PAGE_SIZE - ((unsigned) umain2) % PAGE_SIZE); + +/* In order to optimize data distribution, the data structures x, trans, + and umain2 have been aligned so that each begins on a page boundary. + This ensures that the amount of padding calculated by the program is + such that each processor's partition ends on a page boundary, thus + ensuring that all data from these structures that are needed by a + processor can be allocated to its local memory */ + +/* POSSIBLE ENHANCEMENT: Here is where one might distribute the x, + trans, and umain2 data structures across physically distributed + memories as desired. + + One way to place data is as follows: + + double *base; + int i; + + i = ((N/P)+(rootN/P)*pad_length)*2; + base = &(x[0]); + for (j=0;jid = 0; + InitX(N, x); /* place random values in x */ + + if (test_result) { + ck1 = CheckSum(N, x); + } + if (doprint) { + printf("Original data values:\n"); + PrintArray(N, x); + } + + InitU(N,umain); /* initialize u arrays*/ + InitU2(N,umain2,rootN); + + /* fire off P processes */ + for (i=1; itranstimes[0]; + printf("\n"); + printf(" PROCESS STATISTICS\n"); + printf(" Computation Transpose Transpose\n"); + printf(" Proc Time Time Fraction\n"); + printf(" 0 %10d %10d %8.5f\n", + Global->totaltimes[0],Global->transtimes[0], + ((double)Global->transtimes[0])/Global->totaltimes[0]); + if (dostats) { + transtime2 = Global->transtimes[0]; + avgtranstime = Global->transtimes[0]; + avgcomptime = Global->totaltimes[0]; + maxtotal = Global->totaltimes[0]; + mintotal = Global->totaltimes[0]; + maxfrac = ((double)Global->transtimes[0])/Global->totaltimes[0]; + minfrac = ((double)Global->transtimes[0])/Global->totaltimes[0]; + avgfractime = ((double)Global->transtimes[0])/Global->totaltimes[0]; + for (i=1;itranstimes[i] > transtime) { + transtime = Global->transtimes[i]; + } + if (Global->transtimes[i] < transtime2) { + transtime2 = Global->transtimes[i]; + } + if (Global->totaltimes[i] > maxtotal) { + maxtotal = Global->totaltimes[i]; + } + if (Global->totaltimes[i] < mintotal) { + mintotal = Global->totaltimes[i]; + } + if (((double)Global->transtimes[i])/Global->totaltimes[i] > maxfrac) { + maxfrac = ((double)Global->transtimes[i])/Global->totaltimes[i]; + } + if (((double)Global->transtimes[i])/Global->totaltimes[i] < minfrac) { + minfrac = ((double)Global->transtimes[i])/Global->totaltimes[i]; + } + printf(" %3d %10d %10d %8.5f\n", + i,Global->totaltimes[i],Global->transtimes[i], + ((double)Global->transtimes[i])/Global->totaltimes[i]); + avgtranstime += Global->transtimes[i]; + avgcomptime += Global->totaltimes[i]; + avgfractime += ((double)Global->transtimes[i])/Global->totaltimes[i]; + } + printf(" Avg %10.0f %10.0f %8.5f\n", + ((double) avgcomptime)/P,((double) avgtranstime)/P,avgfractime/P); + printf(" Max %10d %10d %8.5f\n", + maxtotal,transtime,maxfrac); + printf(" Min %10d %10d %8.5f\n", + mintotal,transtime2,minfrac); + } + Global->starttime = start; + printf("\n"); + printf(" TIMING INFORMATION\n"); + printf("Start time : %16d\n", + Global->starttime); + printf("Initialization finish time : %16d\n", + Global->initdonetime); + printf("Overall finish time : %16d\n", + Global->finishtime); + printf("Total time with initialization : %16d\n", + Global->finishtime-Global->starttime); + printf("Total time without initialization : %16d\n", + Global->finishtime-Global->initdonetime); + printf("Overall transpose time : %16d\n", + transtime); + printf("Overall transpose fraction : %16.5f\n", + ((double) transtime)/(Global->finishtime-Global->initdonetime)); + printf("\n"); + + if (test_result) { + ck3 = CheckSum(N, x); + printf(" INVERSE FFT TEST RESULTS\n"); + printf("Checksum difference is %.3f (%.3f, %.3f)\n", + ck1-ck3, ck1, ck3); + if (fabs(ck1-ck3) < 0.001) { + printf("TEST PASSED\n"); + } else { + printf("TEST FAILED\n"); + } + } + + {exit(0);}; +} + + +void SlaveStart() +{ + int i; + int j; + int MyNum; + double error; + double *upriv; + int initdone; + int finish; + int l_transtime=0; + int MyFirst; + int MyLast; + + {;}; + MyNum = Global->id; + Global->id++; + {;}; + +/* POSSIBLE ENHANCEMENT: Here is where one might pin processes to + processors to avoid migration */ + + {;}; + + upriv = (double *) malloc(2*(rootN-1)*sizeof(double)); + if (upriv == NULL) { + fprintf(stderr,"Proc %d could not malloc memory for upriv\n",MyNum); + exit(-1); + } + for (i=0;i<2*(rootN-1);i++) { + upriv[i] = umain[i]; + } + + MyFirst = rootN*MyNum/P; + MyLast = rootN*(MyNum+1)/P; + + TouchArray(x, trans, umain2, upriv, N, MyNum, MyFirst, MyLast); + + {;}; + +/* POSSIBLE ENHANCEMENT: Here is where one might reset the + statistics that one is measuring about the parallel execution */ + + if ((MyNum == 0) || (dostats)) { + {long time(); (initdone) = time(0);}; + } + + /* perform forward FFT */ + FFT1D(1, M, N, x, trans, upriv, umain2, MyNum, &l_transtime, MyFirst, + MyLast, pad_length, P, test_result, doprint, dostats, Global); + + /* perform backward FFT */ + if (test_result) { + FFT1D(-1, M, N, x, trans, upriv, umain2, MyNum, &l_transtime, MyFirst, + MyLast, pad_length, P, test_result, doprint, dostats, Global); + } + + if ((MyNum == 0) || (dostats)) { + {long time(); (finish) = time(0);}; + Global->transtimes[MyNum] = l_transtime; + Global->totaltimes[MyNum] = finish-initdone; + } + if (MyNum == 0) { + Global->finishtime = finish; + Global->initdonetime = initdone; + } +} + + +double TouchArray(x, scratch, u, upriv, N, MyNum, MyFirst, MyLast) + +double *x; +double *scratch; +double *u; +double *upriv; +int N; +int MyNum; +int MyFirst; +int MyLast; + +{ + int i,j,k; + double tot = 0.0; + + /* touch my data */ + for (j=0;j<2*(rootN-1);j++) { + tot += upriv[j]; + } + for (j=MyFirst; j rootN-1) { + return; + } + u[2*(base+j)] = cos(2.0*PI*j/(2*n1)); + u[2*(base+j)+1] = -sin(2.0*PI*j/(2*n1)); + } + } +} + + +InitU2(N, u, n1) + +int N; +double *u; +int n1; + +{ + int i,j,k; + int base; + + for (j=0; j>1; + } + return(j); +} + + +void FFT1D(direction, M, N, x, scratch, upriv, umain2, MyNum, l_transtime, + MyFirst, MyLast, pad_length, P, test_result, doprint, dostats, + Global) + +int direction; +int M; +int N; +int *l_transtime; +double *x; +double *upriv; +double *scratch; +double *umain2; +int MyFirst; +int MyLast; +int pad_length; +int P; +int test_result; +int doprint; +int dostats; +struct GlobalMemory *Global; + +{ + int i; + int j; + int m1; + int n1; + int flag = 0; + unsigned int clocktime1; + unsigned int clocktime2; + + m1 = M/2; + n1 = 1< k) { + SWAP(x[2*j], x[2*k]); + SWAP(x[2*j+1], x[2*k+1]); + } + } +} + + +FFT1DOnce(direction, M, N, u, x) + +int direction; +int M; +int N; +double *u; +double *x; + +{ + int j; + int k; + int q; + int L; + int r; + int Lstar; + double *u1; + double *x1; + double *x2; + double omega_r; + double omega_c; + double tau_r; + double tau_c; + double x_r; + double x_c; + + Reverse(N, M, x); + + for (q=1; q<=M; q++) { + L = 1< -#include -#include - +#include +#include +#include MAIN_ENV #define MAXRAND 32767.0 @@ -54,14 +53,14 @@ MAIN_ENV #define PAGE_SIZE 1024 struct GlobalMemory { - double *t_in_fac; + double *t_in_fac; double *t_in_solve; - double *t_in_mod; + double *t_in_mod; double *t_in_bar; double *completion; - unsigned long starttime; - unsigned long rf; - unsigned long rs; + unsigned long starttime; + unsigned long rf; + unsigned long rs; unsigned long done; long id; BARDEC(start) @@ -132,7 +131,7 @@ int main(int argc, char *argv[]) case 't': test_result = !test_result; break; case 'o': doprint = !doprint; break; case 'h': printf("Usage: LU \n\n"); - printf("options:\n"); + printf("options:\n"); printf(" -nN : Decompose NxN matrix.\n"); printf(" -pP : P = number of processors.\n"); printf(" -bB : Use a block size of B. BxB elements should fit in cache for \n"); @@ -143,7 +142,7 @@ int main(int argc, char *argv[]) printf(" -o : Print out matrix values.\n"); printf(" -h : Print out command line options.\n\n"); printf("Default: LU -n%1d -p%1d -b%1d\n", - DEFAULT_N,DEFAULT_P,DEFAULT_B); + DEFAULT_N,DEFAULT_P,DEFAULT_B); exit(0); break; } @@ -178,13 +177,13 @@ int main(int argc, char *argv[]) proc_bytes = (long *) malloc(P*sizeof(long)); if (proc_bytes == NULL) { - fprintf(stderr,"Could not malloc memory for proc_bytes.\n"); - exit(-1); + fprintf(stderr,"Could not malloc memory for proc_bytes.\n"); + exit(-1); } last_malloc = (double **) G_MALLOC(P*sizeof(double *)); if (last_malloc == NULL) { - fprintf(stderr,"Could not malloc memory for last_malloc.\n"); - exit(-1); + fprintf(stderr,"Could not malloc memory for last_malloc.\n"); + exit(-1); } for (i=0;it_in_fac = (double *) G_MALLOC(P*sizeof(double)); @@ -286,8 +285,8 @@ int main(int argc, char *argv[]) size = block_size*block_size; } - Place all addresses x such that - (&(a[i+j*nblocks][0]) <= x < &(a[i+j*nblocks][size-1])) + Place all addresses x such that + (&(a[i+j*nblocks][0]) <= x < &(a[i+j*nblocks][size-1])) on node proc_num } } @@ -323,12 +322,12 @@ int main(int argc, char *argv[]) avgt += Global->completion[i]; } avgt = avgt / P; - + min_fac = max_fac = avg_fac = Global->t_in_fac[0]; min_solve = max_solve = avg_solve = Global->t_in_solve[0]; min_mod = max_mod = avg_mod = Global->t_in_mod[0]; min_bar = max_bar = avg_bar = Global->t_in_bar[0]; - + for (i=1; it_in_fac[i] > max_fac) { max_fac = Global->t_in_fac[i]; @@ -375,8 +374,8 @@ int main(int argc, char *argv[]) for (i=1; icompletion[i],Global->t_in_fac[i], - Global->t_in_solve[i],Global->t_in_mod[i], - Global->t_in_bar[i]); + Global->t_in_solve[i],Global->t_in_mod[i], + Global->t_in_bar[i]); } printf(" Avg %10.0f %10.0f %10.0f %10.0f %10.0f\n", avgt,avg_fac,avg_solve,avg_mod,avg_bar); @@ -423,8 +422,8 @@ void SlaveStart() void OneSolve(long n, long block_size, long MyNum, long dostats) { - unsigned long myrs; - unsigned long myrf; + unsigned long myrs; + unsigned long myrf; unsigned long mydone; struct LocalCopies *lc; @@ -479,8 +478,8 @@ void OneSolve(long n, long block_size, long MyNum, long dostats) void lu0(double *a, long n, long stride) { - long j; - long k; + long j; + long k; long length; double alpha; @@ -498,7 +497,7 @@ void lu0(double *a, long n, long stride) void bdiv(double *a, double *diag, long stride_a, long stride_diag, long dimi, long dimk) { - long j; + long j; long k; double alpha; @@ -513,8 +512,8 @@ void bdiv(double *a, double *diag, long stride_a, long stride_diag, long dimi, l void bmodd(double *a, double *c, long dimi, long dimj, long stride_a, long stride_c) { - long j; - long k; + long j; + long k; long length; double alpha; @@ -531,13 +530,13 @@ void bmodd(double *a, double *c, long dimi, long dimj, long stride_a, long strid void bmod(double *a, double *b, double *c, long dimi, long dimj, long dimk, long stridea, long strideb, long stridec) { - long j; + long j; long k; double alpha; for (k=0; k n) { kl = n; strK = kl - k; @@ -593,7 +592,7 @@ void lu(long n, long bs, long MyNum, struct LocalCopies *lc, long dostats) /* factor diagonal block */ if (BlockOwner(K, K) == MyNum) { - A = a[K+K*nblocks]; + A = a[K+K*nblocks]; lu0(A, strK, strK); } @@ -611,35 +610,35 @@ void lu(long n, long bs, long MyNum, struct LocalCopies *lc, long dostats) D = a[K+K*nblocks]; for (i=kl, I=K+1; i n) { - il = n; + il = i + bs; + if (il > n) { + il = n; strI = il - i; } else { strI = bs; } - A = a[I+K*nblocks]; - bdiv(A, D, strI, strK, strI, strK); + A = a[I+K*nblocks]; + bdiv(A, D, strI, strK, strI, strK); } } /* modify row k by diagonal block */ for (j=kl, J=K+1; j n) { - jl = n; + jl = j+bs; + if (jl > n) { + jl = n; strJ = jl - j; } else { strJ = bs; } A = a[K+J*nblocks]; - bmodd(D, A, strK, strJ, strK, strK); + bmodd(D, A, strK, strJ, strK, strK); } } if ((MyNum == 0) || (dostats)) { CLOCK(t22); - } + } BARRIER(Global->start, P); @@ -649,27 +648,27 @@ void lu(long n, long bs, long MyNum, struct LocalCopies *lc, long dostats) /* modify subsequent block columns */ for (i=kl, I=K+1; i n) { - il = n; + il = n; strI = il - i; } else { strI = bs; } - A = a[I+K*nblocks]; + A = a[I+K*nblocks]; for (j=kl, J=K+1; j n) { - jl = n; + jl = j + bs; + if (jl > n) { + jl = n; strJ= jl - j; } else { strJ = bs; } - if (BlockOwner(I, J) == MyNum) { /* parcel out blocks */ - B = a[K+J*nblocks]; - C = a[I+J*nblocks]; - bmod(A, B, C, strI, strJ, strK, strI, strK, strI); - } + if (BlockOwner(I, J) == MyNum) { /* parcel out blocks */ + B = a[K+J*nblocks]; + C = a[I+J*nblocks]; + bmod(A, B, C, strI, strJ, strK, strI, strK, strI); + } } } @@ -697,24 +696,24 @@ void InitA(double *rhs) for (j=0; j=0; j--) { for (i=0; i -#include -#include - +#include +#include +#include MAIN_ENV #define MAXRAND 32767.0 @@ -163,13 +162,13 @@ int main(int argc, char *argv[]) a = (double *) G_MALLOC(n*n*sizeof(double)); if (a == NULL) { - printerr("Could not malloc memory for a.\n"); - exit(-1); + printerr("Could not malloc memory for a.\n"); + exit(-1); } rhs = (double *) G_MALLOC(n*sizeof(double)); if (rhs == NULL) { - printerr("Could not malloc memory for rhs.\n"); - exit(-1); + printerr("Could not malloc memory for rhs.\n"); + exit(-1); } Global = (struct GlobalMemory *) G_MALLOC(sizeof(struct GlobalMemory)); @@ -200,7 +199,7 @@ int main(int argc, char *argv[]) } /* POSSIBLE ENHANCEMENT: Here is where one might distribute the a - matrix data across physically distributed memories in a + matrix data across physically distributed memories in a round-robin fashion as desired. */ BARINIT(Global->start, P); @@ -457,17 +456,17 @@ void daxpy(double *a, double *b, long n, double alpha) long BlockOwner(long I, long J) { // return((I%num_cols) + (J%num_rows)*num_cols); - return((I + J) % P); + return((I + J) % P); } long BlockOwnerColumn(long I, long J) { - return(I % P); + return(I % P); } long BlockOwnerRow(long I, long J) { - return(((J % P) + (P / 2)) % P); + return(((J % P) + (P / 2)) % P); } void lu(long n, long bs, long MyNum, struct LocalCopies *lc, long dostats) @@ -479,7 +478,7 @@ void lu(long n, long bs, long MyNum, struct LocalCopies *lc, long dostats) strI = n; for (k=0, K=0; kn) { kl = n; } @@ -490,7 +489,7 @@ void lu(long n, long bs, long MyNum, struct LocalCopies *lc, long dostats) /* factor diagonal block */ if (BlockOwner(K, K) == MyNum) { - A = &(a[k+k*n]); + A = &(a[k+k*n]); lu0(A, kl-k, strI); } @@ -508,7 +507,7 @@ void lu(long n, long bs, long MyNum, struct LocalCopies *lc, long dostats) D = &(a[k+k*n]); for (i=kl, I=K+1; i n) { il = n; @@ -520,7 +519,7 @@ void lu(long n, long bs, long MyNum, struct LocalCopies *lc, long dostats) /* modify row k by diagonal block */ for (j=kl, J=K+1; j n) { jl = n; @@ -580,7 +579,7 @@ void InitA(double *rhs) for (i=0; i +#include #include -#include -#include - #define DEFAULT_P 1 #define DEFAULT_N 262144 -#define DEFAULT_R 1024 +#define DEFAULT_R 1024 #define DEFAULT_M 524288 -#define MAX_PROCESSORS 64 +#define MAX_PROCESSORS 64 #define RADIX_S 8388608.0e0 #define RADIX 70368744177664.0e0 #define SEED 314159265.0e0 @@ -119,7 +118,7 @@ int main(int argc, char *argv[]) long p; long quotient; long remainder; - long sum_i; + long sum_i; long sum_f; long size; long **temp; @@ -142,9 +141,9 @@ int main(int argc, char *argv[]) exit(-1); } if (number_of_processors > MAX_PROCESSORS) { - printerr("Maximum processors (MAX_PROCESSORS) exceeded\n"); - exit(-1); - } + printerr("Maximum processors (MAX_PROCESSORS) exceeded\n"); + exit(-1); + } break; case 'r': radix = atoi(optarg); if (radix < 1) { @@ -187,18 +186,18 @@ int main(int argc, char *argv[]) printf(" -h : Print out command line options.\n\n"); printf("Default: RADIX -p%1d -n%1d -r%1d -m%1d\n", DEFAULT_P,DEFAULT_N,DEFAULT_R,DEFAULT_M); - exit(0); + exit(0); } } MAIN_INITENV(,80000000) - log2_radix = log_2(radix); + log2_radix = log_2(radix); log2_keys = log_2(num_keys); global = (struct global_memory *) G_MALLOC(sizeof(struct global_memory)); if (global == NULL) { - fprintf(stderr,"ERROR: Cannot malloc enough memory for global\n"); - exit(-1); + fprintf(stderr,"ERROR: Cannot malloc enough memory for global\n"); + exit(-1); } key[0] = (long *) G_MALLOC(num_keys*sizeof(long)); key[1] = (long *) G_MALLOC(num_keys*sizeof(long)); @@ -209,10 +208,10 @@ int main(int argc, char *argv[]) global->totaltime = (double *) G_MALLOC(number_of_processors*sizeof(double)); size = number_of_processors*(radix*sizeof(long)+sizeof(long *)); rank_me = (long **) G_MALLOC(size); - if ((key[0] == NULL) || (key[1] == NULL) || (key_partition == NULL) || (rank_partition == NULL) || + if ((key[0] == NULL) || (key[1] == NULL) || (key_partition == NULL) || (rank_partition == NULL) || (global->ranktime == NULL) || (global->sorttime == NULL) || (global->totaltime == NULL) || (rank_me == NULL)) { fprintf(stderr,"ERROR: Cannot malloc enough memory\n"); - exit(-1); + exit(-1); } temp = rank_me; @@ -231,7 +230,7 @@ int main(int argc, char *argv[]) /* ALOCKINIT(global->section_lock,MAX_PROCESSORS)*/ BARINIT(global->barrier_rank, number_of_processors) BARINIT(global->barrier_key, number_of_processors) - + for (i=0; i<2*number_of_processors; i++) { PAUSEINIT(global->prefix_tree[i].done); } @@ -277,11 +276,11 @@ int main(int argc, char *argv[]) rank_partition[p] = radix; /* POSSIBLE ENHANCEMENT: Here is where one might distribute the key, - rank_me, rank, and gp data structures across physically - distributed memories as desired. - - One way to place data is as follows: - + rank_me, rank, and gp data structures across physically + distributed memories as desired. + + One way to place data is as follows: + for (i=0;i>= 1; index = base + offset; Place all addresses x such that: - &(global->prefix_tree[index]) <= x < + &(global->prefix_tree[index]) <= x < &(global->prefix_tree[index + 1]) on node toffset base += level; level >>= 1; - } + } } */ /* Fill the random-number array. */ - + CREATE(slave_sort, number_of_processors); WAIT_FOR_END(number_of_processors); @@ -382,9 +381,9 @@ int main(int argc, char *argv[]) printout(); } if (test_result) { - test_sort(global->final); + test_sort(global->final); } - + MAIN_END; } @@ -455,12 +454,12 @@ void slave_sort() init(key_start,key_stop,from); - BARRIER(global->barrier_key, number_of_processors) + BARRIER(global->barrier_key, number_of_processors) /* POSSIBLE ENHANCEMENT: Here is where one might reset the statistics that one is measuring about the parallel execution */ - BARRIER(global->barrier_key, number_of_processors) + BARRIER(global->barrier_key, number_of_processors) if ((MyNum == 0) || (stats)) { CLOCK(time1) @@ -482,20 +481,20 @@ void slave_sort() for (i = 0; i < radix; i++) { rank_me_mynum[i] = 0; - } + } key_from = (long *) key[from]; key_to = (long *) key[to]; for (i=key_start;i> shiftnum; + my_key = my_key >> shiftnum; rank_me_mynum[my_key]++; } - key_density[0] = rank_me_mynum[0]; + key_density[0] = rank_me_mynum[0]; for (i=1;ibarrier_rank, number_of_processors) + BARRIER(global->barrier_rank, number_of_processors) n = &(global->prefix_tree[MyNum]); for (i = 0; i < radix; i++) { @@ -573,7 +572,7 @@ void slave_sort() offset = MyNum; level = number_of_processors; base = 0; - for (i = 0; i < radix; i++) { + for(i = 0; i < radix; i++) { rank_ff_mynum[i] = 0; } while (offset != 0) { @@ -604,13 +603,13 @@ void slave_sort() /* put it in order according to this digit */ - for (i = key_start; i < key_stop; i++) { + for (i = key_start; i < key_stop; i++) { this_key = key_from[i] & bb; - this_key = this_key >> shiftnum; + this_key = this_key >> shiftnum; tmp = rank_ff_mynum[this_key]; key_to[tmp] = key_from[i]; rank_ff_mynum[this_key]++; - } /* i */ + } /* i */ if ((MyNum == 0) || (stats)) { CLOCK(time5); @@ -653,7 +652,7 @@ double product_mod_46(double t1, double t2) double b1; double a2; double b2; - + a1 = (double)((long)(t1 / RADIX_S)); /* Decompose the arguments. */ a2 = t1 - a1 * RADIX_S; b1 = (double)((long)(t2 / RADIX_S)); @@ -674,8 +673,8 @@ double ran_num_init(unsigned long k, double b, double t) { unsigned long j; - while (k != 0) { /* while () is executed m times - such that 2^m > k. */ + while (k != 0) { /* while() is executed m times + such that 2^m > k. */ j = k >> 1; if ((j << 1) != k) { b = product_mod_46(b, t);