/*************************************************************************
- * *
+ * *
* N A S P A R A L L E L B E N C H M A R K S 3.3 *
* *
* D T *
* *
- *************************************************************************
+ *************************************************************************
* *
* This benchmark is part of the NAS Parallel Benchmark 3.3 suite. *
* *
* E-mail: npb@nas.nasa.gov *
* Fax: (650) 604-3957 *
* *
- *************************************************************************
+ *************************************************************************
* *
* Author: M. Frumkin * *
* *
}
static int ipowMod(int a,long long int n,int md){
- int seed=1,q=a,r=1;
+ int seed=1;
+ int q=a;
+ int r=1;
int exp = n;
if(n<0){
fprintf(stderr,"ipowMod: exponent must be nonnegative exp=%lld\n",n);
exp=-n; /* temp fix */
- /* return 1; */
}
if(md<=0){
fprintf(stderr,"ipowMod: module must be positive mod=%d",md);
/* Nodes of the graph must be topologically sorted to avoid MPI deadlock. */
DGraph *dg;
unsigned int numSources=num_sources; /* must be power of 2 */
- int numOfLayers=0;
+ unsigned int numOfLayers=0;
unsigned int tmpS=numSources>>1;
int firstLayerNode=0;
DGArc *ar=NULL;
DGNode *nd=NULL;
unsigned int mask=0x0;
int ndid=0,ndoff=0;
- unsigned int i=0,j=0;
+ unsigned int i=0;
+ unsigned int j=0;
char nm[BLOCK_SIZE];
snprintf(nm,BLOCK_SIZE,"DT_SH.%c",cls);
tmpS>>=1;
}
for(i=0;i<numSources;i++){
- snprintf(nm,BLOCK_SIZE,"Source.%d",i);
- nd=newNode(nm);
- AttachNode(dg,nd);
+ snprintf(nm, BLOCK_SIZE, "Source.%u", i);
+ nd = newNode(nm);
+ AttachNode(dg, nd);
}
for(j=0;j<numOfLayers;j++){
mask=0x00000001<<j;
for(i=0;i<numSources;i++){
- snprintf(nm,BLOCK_SIZE,"Comparator.%d",(i+j*firstLayerNode));
+ snprintf(nm, BLOCK_SIZE, "Comparator.%u", (i + j * firstLayerNode));
nd=newNode(nm);
AttachNode(dg,nd);
ndoff=i&(~mask);
}
mask=0x00000001<<numOfLayers;
for(i=0;i<numSources;i++){
- snprintf(nm,BLOCK_SIZE,"Sink.%d",i);
+ snprintf(nm, BLOCK_SIZE, "Sink.%u", i);
nd=newNode(nm);
AttachNode(dg,nd);
ndoff=i&(~mask);
AttachNode(dg,nd);
}
totComparators=0;
- numPrevLayerNodes=numLayerNodes;
while(numLayerNodes>maxInDeg){
numLayerNodes=numLayerNodes/maxInDeg;
- if(numLayerNodes*maxInDeg<numPrevLayerNodes)numLayerNodes++;
+ if(numLayerNodes*maxInDeg<numPrevLayerNodes)
+ numLayerNodes++;
for(i=0;i<numLayerNodes;i++){
snprintf(nm,BLOCK_SIZE,"Comparator.%d",totComparators);
totComparators++;
id=AttachNode(dg,nd);
for(j=0;j<maxInDeg;j++){
sid=i*maxInDeg+j;
- if(sid>=numPrevLayerNodes) break;
+ if(sid>=numPrevLayerNodes)
+ break;
snd=dg->node[firstLayerNode+sid];
ar=newArc(dg->node[id],snd);
AttachArc(dg,ar);
numPrevLayerNodes=numLayerNodes;
}
source=newNode((char*)"Source");
- AttachNode(dg,source);
+ AttachNode(dg,source);
for(i=0;i<numPrevLayerNodes;i++){
nd=dg->node[firstLayerNode+i];
ar=newArc(source,nd);
}
while(numLayerNodes>maxInDeg){
numLayerNodes=numLayerNodes/maxInDeg;
- if(numLayerNodes*maxInDeg<numPrevLayerNodes)numLayerNodes++;
+ if(numLayerNodes*maxInDeg<numPrevLayerNodes)
+ numLayerNodes++;
for(i=0;i<numLayerNodes;i++){
snprintf(nm,BLOCK_SIZE,"Comparator.%d",totComparators);
totComparators++;
id=AttachNode(dg,nd);
for(j=0;j<maxInDeg;j++){
sid=i*maxInDeg+j;
- if(sid>=numPrevLayerNodes) break;
+ if(sid>=numPrevLayerNodes)
+ break;
snd=dg->node[firstLayerNode+sid];
ar=newArc(snd,dg->node[id]);
AttachArc(dg,ar);
numPrevLayerNodes=numLayerNodes;
}
sink=newNode((char*)"Sink");
- AttachNode(dg,sink);
+ AttachNode(dg,sink);
for(i=0;i<numPrevLayerNodes;i++){
nd=dg->node[firstLayerNode+i];
ar=newArc(nd,sink);
int i=0,j=0,k=0;
double rms0=0.0,rms1=0.0,rmsm1=0.0;
double weight=((double) (w+1))/(w+2);
-
+
w+=1;
if(timer_on){
timer_clear(w);
}
if(rmsm1<rms0) k=-1;
if(k==0){
- j=i+fielddim;
a->val[i]=weight*b->val[i];
a->val[i+1]=weight*b->val[i+1];
a->val[i+2]=weight*b->val[i+2];
int i=0,tag=0;
DGArc *ar=NULL;
DGNode *head=NULL;
- if(!feat) return 0;
+ if(feat == 0)
+ return 0;
TRACE_smpi_set_category ("SendResults");
for(i=0;i<nd->outDegree;i++){
ar=nd->outArc[i];
- if(ar->tail!=nd) continue;
- head=ar->head;
- tag=ar->id;
- if(head->address!=nd->address){
- MPI_Send(&feat->len,1,MPI_INT,head->address,tag,MPI_COMM_WORLD);
- MPI_Send(feat->val,feat->len,MPI_DOUBLE,head->address,tag,MPI_COMM_WORLD);
+ if(ar->tail ==nd){
+ head=ar->head;
+ tag=ar->id;
+ if(head->address!=nd->address){
+ MPI_Send(&feat->len,1,MPI_INT,head->address,tag,MPI_COMM_WORLD);
+ MPI_Send(feat->val,feat->len,MPI_DOUBLE,head->address,tag,MPI_COMM_WORLD);
+ }
}
}
TRACE_smpi_set_category (NULL);
if(nd->inDegree==0) return NULL;
for(i=0;i<nd->inDegree;i++){
ar=nd->inArc[i];
- if(ar->head!=nd) continue;
- tail=ar->tail;
- if(tail->address!=nd->address){
- len=0;
- tag=ar->id;
- MPI_Recv(&len,1,MPI_INT,tail->address,tag,MPI_COMM_WORLD,&status);
- feat=newArr(len);
- MPI_Recv(feat->val,feat->len,MPI_DOUBLE,tail->address,tag,MPI_COMM_WORLD,&status);
- resfeat=WindowFilter(resfeat,feat,nd->id);
- free(feat);//SMPI_SHARED_FREE(feat);
- }else{
- featp=(Arr *)tail->feat;
- feat=newArr(featp->len);
- memcpy(feat->val,featp->val,featp->len*sizeof(double));
- resfeat=WindowFilter(resfeat,feat,nd->id);
- free(feat);//SMPI_SHARED_FREE(feat);
+ if(ar->head == nd){
+ tail=ar->tail;
+ if(tail->address!=nd->address){
+ len=0;
+ tag=ar->id;
+ MPI_Recv(&len,1,MPI_INT,tail->address,tag,MPI_COMM_WORLD,&status);
+ feat=newArr(len);
+ MPI_Recv(feat->val,feat->len,MPI_DOUBLE,tail->address,tag,MPI_COMM_WORLD,&status);
+ resfeat=WindowFilter(resfeat,feat,nd->id);
+ free(feat);//SMPI_SHARED_FREE(feat);
+ }else{
+ featp=(Arr *)tail->feat;
+ feat=newArr(featp->len);
+ memcpy(feat->val,featp->val,featp->len*sizeof(double));
+ resfeat=WindowFilter(resfeat,feat,nd->id);
+ free(feat);//SMPI_SHARED_FREE(feat);
+ }
}
}
- for(i=0;i<resfeat->len;i++) resfeat->val[i]=((int)resfeat->val[i])/nd->inDegree;
+ for(i=0;i<resfeat->len;i++)
+ resfeat->val[i]=((int)resfeat->val[i])/nd->inDegree;
nd->feat=resfeat;
return nd->feat;
}
int main(int argc,char **argv ){
int my_rank,comm_size;
int i;
- DGraph *dg=NULL;
+ DGraph *dg = NULL;
int verified=0, featnum=0;
double bytes_sent=2.0,tot_time=0.0;
dg=buildBH(class);
}else if(strncmp(argv[3],"WH",2)==0){
dg=buildWH(class);
- }else if(strncmp(argv[3],"SH",2)==0){
+ }else /* (strncmp(argv[3],"SH",2)==0) */ {
dg=buildSH(class);
}
- if(timer_on && dg->numNodes+1>timers_tot){
+ if(timer_on != 0 && dg->numNodes+1>timers_tot){
timer_on=0;
if(my_rank==0)
- fprintf(stderr,"Not enough timers. Node timeing is off. \n");
+ fprintf(stderr,"Not enough timers. Node timing is off. \n");
}
- if(dg->numNodes>comm_size){
+ if(dg->numNodes && dg->numNodes>comm_size){
if(my_rank==0){
fprintf(stderr,"** The number of MPI processes should not be less than \n");
fprintf(stderr,"** the number of nodes in the graph\n");
MPI_Finalize();
exit(0);
}
- for(i=0;i<dg->numNodes;i++){
+ for(i=0; i<dg->numNodes; i++){
dg->node[i]->address=i;
}
if( my_rank == 0 ){