Fix splash2 benchmark

During the last commit of splash2 benchmark it seems before committing
when we ran "make clean", it effectively undid what the patch at below
link did
http://www.capsl.udel.edu/splash/Download.html

Fix this since without this it is not possible to build the arcane
splash2 benchmark.
This commit is contained in:
Sanchayan Maity 2017-04-26 21:33:02 +05:30
parent 2fcc51c2c1
commit 0f4b39775c
135 changed files with 9862 additions and 8916 deletions

View File

@ -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 = *

View File

@ -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

View File

@ -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].min[i]) {
Local[ProcessId].min[i]=Pos(p)[i];
}
Local[ProcessId].min[i]=Pos(p)[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; i<NDIM;i++) {
if (Pos(p)[i]<Local[0].min[i]) Local[0].min[i]=Pos(p)[i] ;
if (Pos(p)[i]>Local[0].max[i]) Local[0].max[i]=Pos(p)[i] ;
if (Pos(p)[i]<Local[0].min[i]) Local[0].min[i]=Pos(p)[i] ;
if (Pos(p)[i]>Local[0].max[i]) Local[0].max[i]=Pos(p)[i] ;
}
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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 {

View File

@ -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;k<NSUB;k++) {
if (Subp(c)[k] != NULL) {
printtree(Subp(c)[k]);
}
if (Subp(c)[k] != NULL) {
printtree(Subp(c)[k]);
}
}
break;
case LEAF:
@ -136,11 +136,11 @@ void printtree(nodeptr n)
PRTV("Pos", Pos(n));
printf("\n");
for (k = 0; k < l->num_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;

View File

@ -21,14 +21,13 @@
#ifndef _STDINC_H_
#define _STDINC_H_
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/times.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#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

View File

@ -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;

View File

@ -14,13 +14,12 @@
/* */
/*************************************************************************/
#include <cmath>
#include <cstdio>
#include "box.h"
#include <stdio.h>
#include <math.h>
#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;
}

View File

@ -14,15 +14,14 @@
/* */
/*************************************************************************/
#include <cfloat>
#include <cstdio>
#include "box.h"
#include "construct_grid.h"
#include <stdio.h>
#include <float.h>
#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;
}
}

View File

@ -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;
}
}
}

View File

@ -14,10 +14,9 @@
/* */
/*************************************************************************/
#include <cmath>
#include <cstdarg>
#include <cstdio>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include "defs.h"
#include "memory.h"

View File

@ -17,11 +17,11 @@
#ifndef _Defs_H
#define _Defs_H 1
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <limits.h>
/* Define booleans */
#ifdef TRUE

View File

@ -66,20 +66,19 @@
*/
#include <cerrno>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "box.h"
#include "construct_grid.h"
#include "cost_zones.h"
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#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) {

View File

@ -14,15 +14,14 @@
/* */
/*************************************************************************/
#include <cmath>
#include <cstdio>
#include "box.h"
#include <stdio.h>
#include <math.h>
#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);

View File

@ -14,8 +14,7 @@
/* */
/*************************************************************************/
#include <cfloat>
#include <float.h>
#include "defs.h"
#include "memory.h"

View File

@ -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

View File

@ -14,11 +14,9 @@
/* */
/*************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#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");
}

View File

@ -14,13 +14,12 @@
/* */
/*************************************************************************/
#include <climits>
#include <cmath>
#include "box.h"
#include <math.h>
#include <limits.h>
#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;

View File

@ -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);

View File

@ -19,10 +19,9 @@
EXTERN_ENV
#include <cmath>
#include <cstdio>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "decs.h"
void jacobcalc(double ***x, double ***y, double ***z, long pid, long firstrow, long lastrow, long firstcol, long lastcol)

View File

@ -19,10 +19,9 @@
EXTERN_ENV
#include <cmath>
#include <cstdio>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "decs.h"
void jacobcalc2(double ****x, double ****y, double ****z, long psiindex, long pid, long firstrow, long lastrow, long firstcol, long lastcol)

View File

@ -18,10 +18,9 @@
EXTERN_ENV
#include <cmath>
#include <cstdio>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#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]);
}
}

View File

@ -56,11 +56,10 @@ MAIN_ENV
#define DOWNRIGHT 7
#define PAGE_SIZE 4096
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include "decs.h"
struct multi_struct *multi;

View File

@ -21,11 +21,10 @@
EXTERN_ENV
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#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<jend;j+=2) {
a = t1a[j+1] + t1a[j-1] +
t1c[j] + t1d[j] -
t1b[j] ;
t1c[j] + t1d[j] -
t1b[j] ;
oldval = t1a[j];
newval = a / factor;
newerr = oldval - newval;
@ -253,8 +252,8 @@ void relax(long k, double *err, long color, long my_num)
t1d = (double *) t2a[i+1];
for (j=oddjstart;j<jend;j+=2) {
a = t1a[j+1] + t1a[j-1] +
t1c[j] + t1d[j] -
t1b[j] ;
t1c[j] + t1d[j] -
t1b[j] ;
oldval = t1a[j];
newval = a / factor;
newerr = oldval - newval;
@ -272,8 +271,8 @@ void relax(long k, double *err, long color, long my_num)
t1d = (double *) t2a[i+1];
for (j=oddjstart;j<jend;j+=2) {
a = t1a[j+1] + t1a[j-1] +
t1c[j] + t1d[j] -
t1b[j] ;
t1c[j] + t1d[j] -
t1b[j] ;
oldval = t1a[j];
newval = a / factor;
newerr = oldval - newval;
@ -290,8 +289,8 @@ void relax(long k, double *err, long color, long my_num)
t1d = (double *) t2a[i+1];
for (j=evenjstart;j<jend;j+=2) {
a = t1a[j+1] + t1a[j-1] +
t1c[j] + t1d[j] -
t1b[j] ;
t1c[j] + t1d[j] -
t1b[j] ;
oldval = t1a[j];
newval = a / factor;
newerr = oldval - newval;
@ -371,7 +370,7 @@ void rescal(long kf, long my_num)
t2b = (double **) rhs_multi[my_num][kf];
t2c = (double **) rhs_multi[my_num][krc];
if17=2*(istart-1);
for (ic=istart;ic<=iend;ic++) {
for(ic=istart;ic<=iend;ic++) {
if17+=2;
i_int_factor = (ic+i_off) * i_int_coeff[krc] * 0.5;
jf = 2 * (jstart - 1);
@ -383,7 +382,7 @@ void rescal(long kf, long my_num)
t1f = (double *) t2a[if17-2];
t1g = (double *) t2a[if17-3];
t1h = (double *) t2b[if17-2];
for (jc=jstart;jc<=jend;jc++) {
for(jc=jstart;jc<=jend;jc++) {
jf+=2;
j_int_factor = (jc+j_off)*j_int_coeff[krc] * 0.5;
@ -393,32 +392,32 @@ void rescal(long kf, long my_num)
s = t1a[jf+1] + t1a[jf-1] + t1d[jf] + t1e[jf];
s1 = 2.0 * (t1b[jf] - s + factor * t1a[jf]);
if (((if17 == 2) && (gp[my_num].neighbors[UP] == -1)) ||
((jf == 2) && (gp[my_num].neighbors[LEFT] == -1))) {
((jf == 2) && (gp[my_num].neighbors[LEFT] == -1))) {
s2 = 0;
s3 = 0;
s4 = 0;
} else if ((if17 == 2) || (jf == 2)) {
if (jf == 2) {
temp = q_multi[left_proc][kf][if17][jm-1];
if (jf == 2) {
temp = q_multi[left_proc][kf][if17][jm-1];
} else {
temp = t1a[jf-3];
}
s = t1a[jf-1] + temp + t1d[jf-2] + t1e[jf-2];
s2 = 2.0 * (t1b[jf-2] - s + factor * t1a[jf-2]);
if (if17 == 2) {
temp = q_multi[up_proc][kf][im-1][jf];
if (if17 == 2) {
temp = q_multi[up_proc][kf][im-1][jf];
} else {
temp = t1g[jf];
}
s = t1f[jf+1]+ t1f[jf-1]+ temp + t1d[jf];
s3 = 2.0 * (t1h[jf] - s + factor * t1f[jf]);
if (jf == 2) {
temp = q_multi[left_proc][kf][if17-2][jm-1];
if (jf == 2) {
temp = q_multi[left_proc][kf][if17-2][jm-1];
} else {
temp = t1f[jf-3];
}
if (if17 == 2) {
temp2 = q_multi[up_proc][kf][im-1][jf-2];
if (if17 == 2) {
temp2 = q_multi[up_proc][kf][im-1][jf-2];
} else {
temp2 = t1g[jf-2];
}
@ -484,7 +483,7 @@ void intadd(long kc, long my_num)
t2a = (double **) q_multi[my_num][kc];
t2b = (double **) q_multi[my_num][kf];
if17 = 2*(istart-1);
for (ic=istart;ic<=iend;ic++) {
for(ic=istart;ic<=iend;ic++) {
if17+=2;
i_int_factor1= ((imx[kc]-2)-(ic+i_off-1)) * (i_int_coeff[kf]);
i_int_factor2= (ic+i_off) * i_int_coeff[kf];
@ -495,7 +494,7 @@ void intadd(long kc, long my_num)
t1c = (double *) t2a[ic+1];
t1d = (double *) t2b[if17];
t1e = (double *) t2b[if17-1];
for (jc=jstart;jc<=jend;jc++) {
for(jc=jstart;jc<=jend;jc++) {
jf+=2;
j_int_factor1= ((jmx[kc]-2)-(jc+j_off-1)) * (j_int_coeff[kf]);
j_int_factor2= (jc+j_off) * j_int_coeff[kf];

View File

@ -20,11 +20,10 @@
EXTERN_ENV
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#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];
}
}

View File

@ -20,11 +20,10 @@
EXTERN_ENV
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#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];
}
}

View File

@ -16,9 +16,8 @@
EXTERN_ENV
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#include "decs.h"
void subblock()

View File

@ -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 <cmath>
#include <cstdio>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#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)

View File

@ -20,10 +20,9 @@
performs the laplacian calculation for a subblock. */
#include <cmath>
#include <cstdio>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#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)

View File

@ -23,11 +23,10 @@
/* */
/*************************************************************************/
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include "decs.h"
MAIN_ENV

View File

@ -19,11 +19,10 @@
iterations, w cycles, and the method of half-injection for
residual computation */
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#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;i<iend;i+=2) {
for (j=evenjstart;j<jend;j+=2) {
a = multi->q_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;i<iend;i+=2) {
for (j=oddjstart;j<jend;j+=2) {
a = multi->q_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;i<iend;i+=2) {
for (j=oddjstart;j<jend;j+=2) {
a = multi->q_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;i<iend;i+=2) {
for (j=evenjstart;j<jend;j+=2) {
a = multi->q_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;
}
}
}

View File

@ -18,10 +18,10 @@
subroutine slave
**************** */
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#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];
}
}

View File

@ -18,11 +18,10 @@
subroutine slave2
**************** */
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#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];
}
}

View File

@ -14,7 +14,7 @@
/* */
/*************************************************************************/
#include <cstdio>
#include <stdio.h>
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 ;

View File

@ -23,7 +23,7 @@
*/
#include <cstdio>
#include <stdio.h>
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 ;

View File

@ -8,9 +8,8 @@
*
***************************************************************/
#include <math.h>
#include <stdio.h>
#include <math.h>
#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 ) ;
}

View File

@ -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;
/****************************************

View File

@ -24,7 +24,7 @@
*
*************************************************************************/
#include <cstdio>
#include <stdio.h>
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 ) ;
}

View File

@ -24,7 +24,7 @@
*
*************************************************************************/
#include <cstdio>
#include <stdio.h>
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 ) ;

View File

@ -22,15 +22,12 @@
*
***************************************************************/
#include <cstdio>
#include <cstring>
#include <stdio.h>
#include <string.h>
#if defined(SGI_GL)
#include <gl.h>
#if defined(GL_NASA)
#include <panel.h>
#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) ;

View File

@ -20,7 +20,7 @@
*
***************************************************************/
#include <cstdio>
#include <stdio.h>
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 ;

View File

@ -21,8 +21,7 @@ of the program, as well as lobal data structure declarations */
#ifndef _RADIOSITY_H
#define _RADIOSITY_H
#include <cmath>
#include <math.h>
include(parallel.h)
include(patch.h)
include(model.h)
@ -30,6 +29,7 @@ include(task.h)
#include "glib.h"
#include "pslib.h"
/****************************************
*
* Configuration Parameters

View File

@ -28,7 +28,7 @@
EXTERN_ENV;
#include <cstdio>
#include <stdio.h>
include(radiosity.h)

View File

@ -21,7 +21,7 @@
*
*************************************************************************/
#include <cstdio>
#include <stdio.h>
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 ) ;

View File

@ -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

View File

@ -24,7 +24,7 @@
*
*************************************************************************/
#include <cstdio>
#include <stdio.h>
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 ) ;

View File

@ -21,8 +21,8 @@
*
***************************************************************/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
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 ) ;
}

View File

@ -25,11 +25,12 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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];
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -31,23 +31,24 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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);
}

View File

@ -27,49 +27,49 @@
*/
#include <stdio.h>
#include <fcntl.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <string.h>
#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);
}

View File

@ -25,196 +25,195 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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");
}
}
}

View File

@ -26,11 +26,12 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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);
}

File diff suppressed because it is too large Load Diff

View File

@ -26,11 +26,12 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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);
}

View File

@ -80,11 +80,11 @@
#define VERSION "1.00"
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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<n>\tEnable antialiasing with n subpixels (default = 1).\n\tWhen using with SPLASH suite for evaluation, use default (no antialiasing)\n");
fprintf(stdout, "\t-m<n>\tRequest n megabytes of global memory (default = 32).\n");
fprintf(stdout, "\t-p<n>\tRun on n processors (default = 1).\n");
fprintf(stdout, "\t-h\tPrint this usage message.\n");
fprintf(stdout, "\t-a<n>\tEnable antialiasing with n subpixels (default = 1).\n\tWhen using with SPLASH suite for evaluation, use default (no antialiasing)\n");
fprintf(stdout, "\t-m<n>\tRequest n megabytes of global memory (default = 32).\n");
fprintf(stdout, "\t-p<n>\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
}

View File

@ -25,11 +25,12 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -35,25 +35,24 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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);
}

View File

@ -14,12 +14,11 @@
/* */
/*************************************************************************/
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "tiff_rgba_io.h"
#include <stdio.h>
#include <unistd.h>
#include <malloc.h>
#include <stdlib.h>
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 <infile> <outfile>\n");
exit(1);
fprintf(stderr, "spachtotiff <infile> <outfile>\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);
}
}
}

View File

@ -25,7 +25,6 @@ static char sccsid[] = "@(#)savemap.c 1.3 2/6/9q";
#include <stdio.h>
#include <stdlib.h>
#include <tiffio.h>
#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;
}

View File

@ -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;

View File

@ -28,11 +28,12 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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);
}
}
}
}
}
}
}
}

View File

@ -25,11 +25,12 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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++;
}
}

View File

@ -25,9 +25,8 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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);
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -30,11 +30,12 @@
*/
#include <cmath>
#include <cstdio>
#include <stdio.h>
#include <math.h>
#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;
}
}
}
}

View File

@ -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<NM; i++) {
for (j=0; j<NM; j++) {
if (ABS(invjacobian[i][j]) > 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; outy<yindex+block_ylen && outy<ystop;
outy+=highest_sampling_boxlen) {
for (outx=xindex; outx<xindex+block_xlen && outx<xstop;
outx+=highest_sampling_boxlen) {
outy+=highest_sampling_boxlen) {
for (outx=xindex; outx<xindex+block_xlen && outx<xstop;
outx+=highest_sampling_boxlen) {
/* Trace rays within square box of highest sampling size */
/* whose lower-left corner is current image space location. */
Ray_Trace_Adaptive_Box(outx,outy,highest_sampling_boxlen);
}
/* Trace rays within square box of highest sampling size */
/* whose lower-left corner is current image space location. */
Ray_Trace_Adaptive_Box(outx,outy,highest_sampling_boxlen);
}
}
ALOCK(Global->QLock,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; i<boxlen && outy+i<image_len[Y]; i+=half_boxlen) {
for (j=0; j<boxlen && outx+j<image_len[X]; j+=half_boxlen) {
Ray_Trace_Adaptive_Box(outx+j,outy+i,half_boxlen);
Ray_Trace_Adaptive_Box(outx+j,outy+i,half_boxlen);
}
}
}
@ -354,15 +354,15 @@ void Ray_Trace_Non_Adaptively(long my_node)
xindex = xstart + (work%lnum_xblocks)*block_xlen;
yindex = ystart + (work/lnum_xblocks)*block_ylen;
for (outy=yindex; outy<yindex+block_ylen && outy<ystop; outy++) {
for (outx=xindex; outx<xindex+block_xlen && outx<xstop; outx++) {
for (outx=xindex; outx<xindex+block_xlen && outx<xstop; outx++) {
/* Trace ray from specified image space location into map. */
/* Stochastic sampling is as described in adaptive code. */
foutx = (float)(outx);
fouty = (float)(outy);
pixel_address = IMAGE_ADDRESS(outy,outx);
Trace_Ray(foutx,fouty,pixel_address);
}
/* Trace ray from specified image space location into map. */
/* Stochastic sampling is as described in adaptive code. */
foutx = (float)(outx);
fouty = (float)(outy);
pixel_address = IMAGE_ADDRESS(outy,outx);
Trace_Ray(foutx,fouty,pixel_address);
}
}
ALOCK(Global->QLock,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<xindex+block_xlen &&
outx<image_len[X]; outx+=lowest_volume_boxlen) {
/* Trace ray from specified image space location into map. */
/* Stochastic sampling is as described in adaptive code. */
MASK_IMAGE(outy,outx) += RAY_TRACED;
foutx = (float)(outx);
fouty = (float)(outy);
pixel_address = IMAGE_ADDRESS(outy,outx);
Trace_Ray(foutx,fouty,pixel_address);
num_rays_traced++;
/* Trace ray from specified image space location into map. */
/* Stochastic sampling is as described in adaptive code. */
MASK_IMAGE(outy,outx) += RAY_TRACED;
foutx = (float)(outx);
fouty = (float)(outy);
pixel_address = IMAGE_ADDRESS(outy,outx);
Trace_Ray(foutx,fouty,pixel_address);
num_rays_traced++;
}
}
}
@ -423,9 +423,9 @@ void Interpolate_Recursively(long my_node)
for (outx=xindex; outx<xindex+block_xlen &&
outx<image_len[X]; outx+=highest_sampling_boxlen) {
/* Fill in image within square box of highest sampling size */
/* whose lower-left corner is current image space location. */
Interpolate_Recursive_Box(outx,outy,highest_sampling_boxlen);
/* Fill in image within square box of highest sampling size */
/* whose lower-left corner is current image space location. */
Interpolate_Recursive_Box(outx,outy,highest_sampling_boxlen);
}
}
}
@ -472,12 +472,12 @@ void Interpolate_Recursive_Box(long outx, long outy, long boxlen)
xalpha = (float)j * one_over_boxlen;
one_minus_xalpha = 1.0 - xalpha;
if (MASK_IMAGE(outy+i,outx+j) == 0) {
color = corner_color[0][0]*one_minus_xalpha*one_minus_yalpha+
corner_color[0][1]*xalpha*one_minus_yalpha+
corner_color[1][0]*one_minus_xalpha*yalpha+
corner_color[1][1]*xalpha*yalpha;
IMAGE(outy+i,outx+j) = color;
MASK_IMAGE(outy+i,outx+j) += INTERPOLATED;
color = corner_color[0][0]*one_minus_xalpha*one_minus_yalpha+
corner_color[0][1]*xalpha*one_minus_yalpha+
corner_color[1][0]*one_minus_xalpha*yalpha+
corner_color[1][1]*xalpha*yalpha;
IMAGE(outy+i,outx+j) = color;
MASK_IMAGE(outy+i,outx+j) += INTERPOLATED;
}
}
}
@ -490,7 +490,7 @@ void Interpolate_Recursive_Box(long outx, long outy, long boxlen)
if (half_boxlen > 1) {
for (i=0; i<boxlen && outy+i<image_len[Y]; i+=half_boxlen) {
for (j=0; j<boxlen && outx+j<image_len[X]; j+=half_boxlen) {
Interpolate_Recursive_Box(outx+j,outy+i,half_boxlen);
Interpolate_Recursive_Box(outx+j,outy+i,half_boxlen);
}
}
}

View File

@ -21,63 +21,63 @@
*************************************************************************/
/* Fast subscripted access to map */
/* (assumes mins = 0 and chars) */
/* Fast subscripted access to map */
/* (assumes mins = 0 and chars) */
#define MAP_ADDRESS(IZ,IY,IX) (map_address+\
((IZ)*map_len[Y]+(IY))*map_len[X]+(IX))
((IZ)*map_len[Y]+(IY))*map_len[X]+(IX))
#define MAP(IZ,IY,IX) (*MAP_ADDRESS(IZ,IY,IX))
/* Fast subscripted access to map */
/* (assumes mins = 0 and chars) */
/* Fast subscripted access to map */
/* (assumes mins = 0 and chars) */
#define GMAG_ADDRESS(IZ,IY,IX) (gmag_address+\
((IZ)*gmag_len[Y]+(IY))*gmag_len[X]+(IX))
((IZ)*gmag_len[Y]+(IY))*gmag_len[X]+(IX))
#define GMAG(IZ,IY,IX) (*GMAG_ADDRESS(IZ,IY,IX))
/* Subscripted access to normal map */
/* (NM GRADIENTs at each IX,IY,IZ) */
/* Subscripted access to normal map */
/* (NM GRADIENTs at each IX,IY,IZ) */
#define TADDR(IZ,IY,IX) (LOOKUP_HSIZE+((IZ)*LOOKUP_PREC+(IY))*2+(IX))
#define NORM_ADDRESS(IZ,IY,IX,D) (norm_address+\
((IZ)*norm_len[Y]+(IY))*norm_len[X]+(IX))
((IZ)*norm_len[Y]+(IY))*norm_len[X]+(IX))
#define NORM(IZ,IY,IX,D) (*NORM_ADDRESS(IZ,IY,IX,D))
/* Subscripted access to opacity map */
/* (1 char at each IX,IY,IZ) */
/* Subscripted access to opacity map */
/* (1 char at each IX,IY,IZ) */
#define OPC_ADDRESS(IZ,IY,IX) (opc_address+\
((IZ)*opc_len[Y]+(IY))*opc_len[X]+(IX))
((IZ)*opc_len[Y]+(IY))*opc_len[X]+(IX))
#define OPC(IZ,IY,IX) (*OPC_ADDRESS(IZ,IY,IX))
/* Subscripted access to normal map */
/* (NM GRADIENTs at each IX,IY,IZ) */
/* Subscripted access to normal map */
/* (NM GRADIENTs at each IX,IY,IZ) */
#define VOX_ADDRESS(IZ,IY,IX,D) (vox_address+\
(((IZ)*vox_len[Y]+(IY))*vox_len[X]+(IX))*\
2+(D))
(((IZ)*vox_len[Y]+(IY))*vox_len[X]+(IX))*\
2+(D))
#define VOX(IZ,IY,IX,D) (*VOX_ADDRESS(IZ,IY,IX,D))
#define PYR_ADDRESS(ILEVEL,IZ,IY,IX)\
(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))
(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))

View File

@ -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) */

View File

@ -17,7 +17,6 @@
/********** storing/loading of large arrays to/from files **********/
#include <fcntl.h>
#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;
}

View File

@ -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 */

View File

@ -21,15 +21,13 @@
*************************************************************************/
#include <sys/types.h>
#include <climits>
#include <cmath> /* Definitions for mathematical library */
#include <cstdio> /* 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 <stdio.h> /* Definitions for standard I/O library */
#include <math.h> /* Definitions for mathematical library */
#include <limits.h>
#include <sys/types.h>

View File

@ -26,13 +26,11 @@
*************************************************************************/
#include <sys/resource.h>
#include <sys/time.h>
#include <climits>
#include <cstring>
#include "incl.h"
#include <string.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <limits.h>
#include "tiffio.h"
#define SH_MEM_AMT 60000000
@ -259,35 +257,35 @@ void Render_Loop()
for (step=0; step<ROTATE_STEPS; step++) { /* do rotation sequence */
/* POSSIBLE ENHANCEMENT: Here is where one might reset statistics, if
one wanted to.
one wanted to.
*/
frame = step;
/* initialize images here */
local_image_address = image_address + image_partition * my_node;
local_mask_image_address = mask_image_address +
mask_image_partition * my_node;
mask_image_partition * my_node;
BARRIER(Global->SlaveBarrier,num_nodes);
if (my_node == num_nodes-1) {
for (i=image_partition*my_node; i<image_length; i++)
*local_image_address++ = background;
if (adaptive)
for (i=mask_image_partition*my_node; i<mask_image_length; i++)
*local_mask_image_address++ = NULL_PIXEL;
for (i=image_partition*my_node; i<image_length; i++)
*local_image_address++ = background;
if (adaptive)
for (i=mask_image_partition*my_node; i<mask_image_length; i++)
*local_mask_image_address++ = NULL_PIXEL;
}
else {
for (i=0; i<image_partition; i++)
*local_image_address++ = background;
if (adaptive)
for (i=0; i<mask_image_partition; i++)
*local_mask_image_address++ = NULL_PIXEL;
for (i=0; i<image_partition; i++)
*local_image_address++ = background;
if (adaptive)
for (i=0; i<mask_image_partition; i++)
*local_mask_image_address++ = NULL_PIXEL;
}
if (my_node == ROOT) {
#ifdef DIM
Select_View((float)STEP_SIZE, dim);
Select_View((float)STEP_SIZE, dim);
#else
Select_View((float)STEP_SIZE, Y);
#endif
@ -302,33 +300,33 @@ void Render_Loop()
Render(my_node);
if (my_node == ROOT) {
if (ROTATE_STEPS > 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<length; i++) *(*address+i) = 0;
@ -440,7 +438,7 @@ void Allocate_Shading_Table(PIXEL **address1, long length)
long i;
printf(" Allocating shade lookup table of %ld bytes...\n",
length*sizeof(PIXEL));
length*sizeof(PIXEL));
/* POSSIBLE ENHANCEMENT: If you want to replicate the shade table,
replace the macro with a simple malloc in the line below */

View File

@ -20,15 +20,14 @@
* *
******************************************************************************/
#include <cstring>
#include <string.h>
#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);

View File

@ -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 */

View File

@ -21,22 +21,21 @@
* *
******************************************************************************/
#include <cstring>
#include <string.h>
#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<ystop; outy++) {
for (outx=xstart; outx<xstop; outx++) {
inx = INSET + outx;
iny = INSET + outy;
inz = INSET + outz;
inx = INSET + outx;
iny = INSET + outy;
inz = INSET + outz;
/* Compute voxel gradient assuming gradient operator is 1x3 */
grd_x = (double)((long)MAP(inz,iny,inx+1) - (long)MAP(inz,iny,inx-1));
grd_y = (double)((long)MAP(inz,iny+1,inx) - (long)MAP(inz,iny-1,inx));
grd_z = (double)((long)MAP(inz+1,iny,inx) - (long)MAP(inz-1,iny,inx));
/* Compute voxel gradient assuming gradient operator is 1x3 */
grd_x = (double)((long)MAP(inz,iny,inx+1) - (long)MAP(inz,iny,inx-1));
grd_y = (double)((long)MAP(inz,iny+1,inx) - (long)MAP(inz,iny-1,inx));
grd_z = (double)((long)MAP(inz+1,iny,inx) - (long)MAP(inz-1,iny,inx));
/* Compute (magnitude*grd_divisor)**2 of gradient */
/* Reduce (magnitude*grd_divisor)**2 to magnitude*grd_divisor */
/* Reduce magnitude*grd_divisor to magnitude */
magnitude = grd_x*grd_x+grd_y*grd_y+grd_z*grd_z;
/* Compute (magnitude*grd_divisor)**2 of gradient */
/* Reduce (magnitude*grd_divisor)**2 to magnitude*grd_divisor */
/* Reduce magnitude*grd_divisor to magnitude */
magnitude = grd_x*grd_x+grd_y*grd_y+grd_z*grd_z;
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);
}
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);
}
}
}
}

View File

@ -20,19 +20,18 @@
* *
******************************************************************************/
#include <cstring>
#include <string.h>
#include "incl.h"
#define WRITE_PYR(IBIT,ILEVEL,IZ,IY,IX)\
(PYR_ADDRESS(ILEVEL,IZ,IY,IX),\
*pyr_address2|=(IBIT)<<pyr_offset2)
(PYR_ADDRESS(ILEVEL,IZ,IY,IX),\
*pyr_address2|=(IBIT)<<pyr_offset2)
/* The following declarations show the layout of the .pyr file. */
/* If changed, the version number must be incremented and code */
/* written to handle loading of both old and current versions. */
/* Version for new .pyr files: */
/* Version for new .pyr files: */
#define PYR_CUR_VERSION 1 /* Initial release */
short pyr_version; /* Version of this .pyr file */
@ -42,26 +41,26 @@ short pyr_len[MAX_PYRLEVEL+1][NM]; /* Number of voxels on each level */
short pyr_voxlen[MAX_PYRLEVEL+1][NM]; /* Size of voxels on each level */
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)) */
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) */
/* End of layout of .pyr file. */
/* Subscripted access to binary pyramid */
/* (PYR_ADDRESS only computes temporaries, */
/* most others invoke PYR_ADDRESS, then: */
/* PYR returns char with bit in low bit,*/
/* CLEAR_PYR clears bit to 0, */
/* SET_PYR sets bit to 1, */
/* WRITE_PYR ORs BOOLEAN IBIT into bit, */
/* OVERWRITE_PYR clears, then ORs IBIT, */
/* CURRENT_PYR returns at current address)*/
/* Warning: do not invoke any of these */
/* macros more than once per statement, */
/* or values of temporaries may conflict, */
/* depending on optimization by compiler. */
/* Subscripted access to binary pyramid */
/* (PYR_ADDRESS only computes temporaries, */
/* most others invoke PYR_ADDRESS, then: */
/* PYR returns char with bit in low bit,*/
/* CLEAR_PYR clears bit to 0, */
/* SET_PYR sets bit to 1, */
/* WRITE_PYR ORs BOOLEAN IBIT into bit, */
/* OVERWRITE_PYR clears, then ORs IBIT, */
/* CURRENT_PYR returns at current address)*/
/* Warning: do not invoke any of these */
/* macros more than once per statement, */
/* or values of temporaries may conflict, */
/* depending on optimization by compiler. */
long pyr_offset1, /* Bit offset of desired bit within pyramid */
pyr_offset2; /* Bit offset of bit within byte */
BYTE *pyr_address2; /* Pointer to byte containing bit */
@ -82,7 +81,7 @@ void Compute_Octree()
while ((1<<(pyr_levels-1)) < max_len)
pyr_levels++;
printf(" Computing binary pyramid of %d levels...\n",
pyr_levels);
pyr_levels);
for (i=0; i<NM; i++) {
pyr_len[0][i] = opc_len[i];
@ -123,20 +122,20 @@ on all processors, don't do this create.
for (level=1; level<pyr_levels; level++) {
for (i=0; i<NM; i++) {
if (pyr_len[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;
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<zstop; outz++) {
for (outy=ystart; outy<ystop; outy++) {
for (outx=xstart; outx<xstop; outx++) {
if (OPC(outz,outy,outx) == 0) /* mask bit is one unless opacity */
WRITE_PYR(0,0,outz,outy,outx); /* value is zero. */
else
WRITE_PYR(1,0,outz,outy,outx);
if (OPC(outz,outy,outx) == 0) /* mask bit is one unless opacity */
WRITE_PYR(0,0,outz,outy,outx); /* value is zero. */
else
WRITE_PYR(1,0,outz,outy,outx);
}
}
}
@ -243,18 +242,18 @@ on all processors, then you should execute what's in the SERIAL_PREPROC
for (outy=0; outy<pyr_len[0][Y]; outy++) {
outy_plus_one = MIN(outy+1,pyr_len[0][Y]-1);
for (outx=0; outx<pyr_len[0][X]; outx++) {
outx_plus_one = MIN(outx+1,pyr_len[0][X]-1);
outx_plus_one = MIN(outx+1,pyr_len[0][X]-1);
bit = PYR(0,outz,outy,outx);
bit |= PYR(0,outz,outy,outx_plus_one);
bit |= PYR(0,outz,outy_plus_one,outx);
bit |= PYR(0,outz,outy_plus_one,outx_plus_one);
bit |= PYR(0,outz_plus_one,outy,outx);
bit |= PYR(0,outz_plus_one,outy,outx_plus_one);
bit |= PYR(0,outz_plus_one,outy_plus_one,outx);
bit |= PYR(0,outz_plus_one,outy_plus_one,outx_plus_one);
bit = PYR(0,outz,outy,outx);
bit |= PYR(0,outz,outy,outx_plus_one);
bit |= PYR(0,outz,outy_plus_one,outx);
bit |= PYR(0,outz,outy_plus_one,outx_plus_one);
bit |= PYR(0,outz_plus_one,outy,outx);
bit |= PYR(0,outz_plus_one,outy,outx_plus_one);
bit |= PYR(0,outz_plus_one,outy_plus_one,outx);
bit |= PYR(0,outz_plus_one,outy_plus_one,outx_plus_one);
WRITE_PYR(bit,0,outz,outy,outx);
WRITE_PYR(bit,0,outz,outy,outx);
}
}
}
@ -277,7 +276,7 @@ void Allocate_Pyramid_Level(address, length)
long i;
printf(" Allocating pyramid level of %ld bytes...\n",
length*sizeof(BYTE));
length*sizeof(BYTE));
/* POSSIBLE ENHANCEMENT: If you want to replicate the octree
on all processors, then replace the macro below with a regular malloc.
@ -306,7 +305,7 @@ void Compute_Pyramid_Level(level)
BOOLEAN bit;
printf(" Computing pyramid level %ld from level %ld...\n",
level,level-1);
level,level-1);
for (outz=0; outz<pyr_len[level][Z]; outz++) {
inz = outz<<1;
inz_plus_one = MIN(inz+1,pyr_len[level-1][Z]-1);
@ -314,19 +313,19 @@ void Compute_Pyramid_Level(level)
iny = outy<<1;
iny_plus_one = MIN(iny+1,pyr_len[level-1][Y]-1);
for (outx=0; outx<pyr_len[level][X]; outx++) {
inx = outx<<1;
inx_plus_one = MIN(inx+1,pyr_len[level-1][X]-1);
inx = outx<<1;
inx_plus_one = MIN(inx+1,pyr_len[level-1][X]-1);
bit = PYR(level-1,inz,iny,inx);
bit |= PYR(level-1,inz,iny,inx_plus_one);
bit |= PYR(level-1,inz,iny_plus_one,inx);
bit |= PYR(level-1,inz,iny_plus_one,inx_plus_one);
bit |= PYR(level-1,inz_plus_one,iny,inx);
bit |= PYR(level-1,inz_plus_one,iny,inx_plus_one);
bit |= PYR(level-1,inz_plus_one,iny_plus_one,inx);
bit |= PYR(level-1,inz_plus_one,iny_plus_one,inx_plus_one);
bit = PYR(level-1,inz,iny,inx);
bit |= PYR(level-1,inz,iny,inx_plus_one);
bit |= PYR(level-1,inz,iny_plus_one,inx);
bit |= PYR(level-1,inz,iny_plus_one,inx_plus_one);
bit |= PYR(level-1,inz_plus_one,iny,inx);
bit |= PYR(level-1,inz_plus_one,iny,inx_plus_one);
bit |= PYR(level-1,inz_plus_one,iny_plus_one,inx);
bit |= PYR(level-1,inz_plus_one,iny_plus_one,inx_plus_one);
WRITE_PYR(bit,level,outz,outy,outx);
WRITE_PYR(bit,level,outz,outy,outx);
}
}
}

View File

@ -21,22 +21,21 @@
* *
******************************************************************************/
#include <cstring>
#include <string.h>
#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<ystop; outy++) {
for (outx=xstart; outx<xstop; outx++) {
inx = INSET + outx;
iny = INSET + outy;
inz = INSET + outz;
inx = INSET + outx;
iny = INSET + outy;
inz = INSET + outz;
density = MAP(inz,iny,inx);
if (density > 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;
}
}
}

View File

@ -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;

View File

@ -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<NM; i++) {
ray[0][i] = out_invvertex[0][0][0][i] +
invjacobian[X][i]*foutx +
invjacobian[Y][i]*fouty;
invjacobian[Y][i]*fouty;
ray[1][i] = ray[0][i] + invjacobian[Z][i]*image_zlen;
}
@ -114,12 +114,12 @@ void Trace_Ray(foutx, fouty, pixel_address)
for (i=0; i<NM; i++) {
if (ABS(ray[1][i] - ray[0][i]) < SMALL) {
if ((ray[0][i] < 0.0 &&
ray[1][i] < 0.0) ||
(ray[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;
}
}
}

View File

@ -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;

View File

@ -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];
}
}
}

View File

@ -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)

View File

@ -15,15 +15,14 @@
/*************************************************************************/
EXTERN_ENV
#include <cstdio>
#include "cnst.h"
#include "fileio.h"
#include "frcnst.h"
#include "global.h"
#include "parameters.h"
#include <stdio.h>
#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

View File

@ -15,8 +15,7 @@
/*************************************************************************/
EXTERN_ENV
#include <cmath>
#include <math.h>
#include "global.h"
/* return the value of a with the same sign as b */

View File

@ -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()
{

View File

@ -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;

View File

@ -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)
{

View File

@ -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 */

View File

@ -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"
/************************************************************************/

View File

@ -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 */

View File

@ -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)
{

View File

@ -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
*

View File

@ -15,7 +15,7 @@
/*************************************************************************/
/* some constant definitions */
#define H1 0
#define O 1
#define H2 2

Some files were not shown because too many files have changed in this diff Show More