Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/lamont/src/compiler/c-target/fragments/par-kdtree.in
ViewVC logotype

Diff of /branches/lamont/src/compiler/c-target/fragments/par-kdtree.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2570, Wed Mar 26 21:52:00 2014 UTC revision 2571, Thu Mar 27 13:56:00 2014 UTC
# Line 1  Line 1 
1    //Debugging purpoes
2    void printTree(KDNode_t* newNode){
3        if(newNode != NULL){
4            printf("id=%d\n",newNode->strandId);
5            printTree(newNode->right);
6            printTree(newNode->left);
7        }
8    }
9    
10  /* sequential version of the merge sort for the spatial indices */  /* sequential version of the merge sort for the spatial indices */
11  void Diderot_Spatial_SeqMergeSort(@PREFIX@World_t *wrld, uint32_t * indices, uint32_t * tmpIndices, int low, int high, uint32_t dim)  void Diderot_Spatial_SeqMergeSort(@PREFIX@World_t *wrld, uint32_t * indices, uint32_t * tmpIndices, int low, int high, uint32_t dim)
12  {  {
# Line 104  Line 113 
113                                           sched->workerData[i].isDone = donePtr;                                           sched->workerData[i].isDone = donePtr;
114                                           sched->workerData[i].workerType = workerType;                                           sched->workerData[i].workerType = workerType;
115                                          retWorker = &sched->workerData[i];                                          retWorker = &sched->workerData[i];
116                         sched->jobsRunning +=1;
117                                          pthread_cond_signal (&sched->workerData[i].runWait);                                          pthread_cond_signal (&sched->workerData[i].runWait);
118                                          sched->nextWorker++;                                          sched->nextWorker++;
119                                          if(sched->nextWorker == sched->numWorkers-1)                                          if(sched->nextWorker == sched->numWorkers-1)
# Line 236  Line 246 
246          //Wait until a task is assigned to the worker          //Wait until a task is assigned to the worker
247              pthread_mutex_lock (&workerArg->sched->lock);              pthread_mutex_lock (&workerArg->sched->lock);
248              if(!workerArg->sched->buildIsDone){              if(!workerArg->sched->buildIsDone){
249                  if(workerArg->sched->numRunning - 1 > 0)                  if(workerArg->sched->numRunning - 1 > 0 || workerArg->sched->jobsRunning > 0)
250                  {                  {
251                     workerArg->isIdle = true;                     workerArg->isIdle = true;
252                     workerArg->sched->numRunning-=1;                     workerArg->sched->numRunning-=1;
253                         pthread_cond_wait (&workerArg->runWait,&workerArg->sched->lock);                         pthread_cond_wait (&workerArg->runWait,&workerArg->sched->lock);
254                       if(!workerArg->isIdle)
255                         workerArg->sched->jobsRunning -=1;
256                  }else {                  }else {
257                      workerArg->sched->buildIsDone = true;                      workerArg->sched->buildIsDone = true;
258                       // printTree(workerArg->wrld->spatialTree->root);
259                      for(unsigned int i = 0; i < workerArg->sched->numWorkers; i++){                      for(unsigned int i = 0; i < workerArg->sched->numWorkers; i++){
260                          if(i != workerArg->id)                          if(i != workerArg->id)
261                              pthread_cond_signal (&workerArg->sched->workerData[i].runWait);                              pthread_cond_signal (&workerArg->sched->workerData[i].runWait);
262                      }                      }
263                        workerArg->sched->stopTime = (airTime() - workerArg->sched->startTime);
264                  }                  }
265                  workerArg->sched->numRunning+=1;                  workerArg->sched->numRunning+=1;
266              }              }
# Line 283  Line 297 
297                                                node->dim);                                                node->dim);
298              }else if(workerArg->workerType == TREE_WORKER){              }else if(workerArg->workerType == TREE_WORKER){
299                      KDNode_t*  node = (KDNode_t  *)workerArg->data;                      KDNode_t*  node = (KDNode_t  *)workerArg->data;
300                  if((node->start + node->len)- 1> workerArg->wrld->numStrands){                 /* if((node->start + node->len)- 1> workerArg->wrld->numStrands || node->strandId  > workerArg->wrld->numStrands){
301                      printf("worker=%d, PROBLEM start = %d len = %d\n",workerArg->id,node->start,node->len);                      printf("worker=%d, PROBLEM start = %d len = %d id=%d\n",workerArg->id,node->start,node->len,node->strandId);
302                      exit(1);                      exit(1);
303                  }                  }*/
304                      node->right = Diderot_KDTree_BuildHelper(workerArg->wrld,                      node->right = Diderot_KDTree_BuildHelper(workerArg->wrld,
305                                                        workerArg->sched,                                                        workerArg->sched,
306                                                            node->start,                                                            node->start,
# Line 331  Line 345 
345      if(error)      if(error)
346          exit(1); */          exit(1); */
347          *mid = start + (end-start)/2;          *mid = start + (end-start)/2;
348      if(midIdx >  (2 * wrld->numStrands)) {     /* if(midIdx >  (2 * wrld->numStrands)) {
349          printf("MidIdx is bigger = %d\n",midIdx);          printf("MidIdx is bigger = %d\n",midIdx);
350          exit(1);          exit(1);
351      }      }*/
352          return wrld->inState[wrld->spatialIndices[midIdx]];          return wrld->inState[wrld->spatialIndices[midIdx]];
353  }  }
354  /* A recursive tree building function */  /* A recursive tree building function */
# Line 348  Line 362 
362    
363          if ((n = find_median(wrld,sched,start,start + len,axis,&mid))) {          if ((n = find_median(wrld,sched,start,start + len,axis,&mid))) {
364    
         printf("Start=%d,Len=%d,Mid=%d\n",start,len,mid);  
   
365          pthread_mutex_lock (&sched->lock);          pthread_mutex_lock (&sched->lock);
366              newNode = Diderot_KDTree_GrabNode(wrld->spatialTree);              newNode = Diderot_KDTree_GrabNode(wrld->spatialTree);
367          pthread_mutex_unlock (&sched->lock);          pthread_mutex_unlock (&sched->lock);
# Line 367  Line 379 
379              newNode->len = start + len - (mid + 1);              newNode->len = start + len - (mid + 1);
380              newNode->start = mid + 1;              newNode->start = mid + 1;
381    
382                  SpatialWorkerArgs_t * worker = Diderot_Grab_SpatailWorker(sched,TREE_WORKER,(void *)newNode,&isDone);            /*if((newNode->start + newNode->len)- 1> wrld->numStrands | newNode->strandId  > wrld->numStrands){
383                        printf("BCALL: INSIDE BUILD no worker, PROBLEM start = %d len = %d before len = %d before start=%d it should be=%d\n",newNode->start,newNode->len,len,start,start + len - (mid + 1));
384                    } */
385    
386                    SpatialWorkerArgs_t * worker = Diderot_Grab_SpatailWorker(sched,TREE_WORKER,newNode,&isDone);
387    
388    
389                  if((newNode->start + newNode->len)- 1> wrld->numStrands){                 /* if((newNode->start + newNode->len)- 1> wrld->numStrands | newNode->strandId  > wrld->numStrands){
390                      if(worker)                      if(worker)
391                      printf("INSIDE BUILD worker=%d, PROBLEM start = %d len = %d\n",worker->id,newNode->start,newNode->len);                      printf("INSIDE BUILD worker=%d, PROBLEM start = %d len = %d before len = %d before start=%d it should be=%d\n",worker->id,newNode->start,newNode->len,len,start,start + len - (mid + 1));
392                      else                      else
393                      printf("INSIDE BUILD no worker, PROBLEM start = %d len = %d\n",newNode->start,newNode->len);                      printf("INSIDE BUILD no worker, PROBLEM start = %d len = %d before len = %d before start=%d it should be=%d\n",newNode->start,newNode->len,len,start,start + len - (mid + 1));
394                      exit(1);                      exit(1);
395                  }                  }*/
396    
397                      if(!worker){                      if(!worker){
398                          newNode->left  = Diderot_KDTree_BuildHelper(wrld,sched,start,mid - start, axis);                          newNode->left  = Diderot_KDTree_BuildHelper(wrld,sched,start,mid - start, axis);
# Line 388  Line 404 
404          }          }
405          return newNode;          return newNode;
406  }  }
 //Debugging purpoes  
 void printTree(KDNode_t* newNode){  
         if(newNode != NULL){  
                 printf("id=%d\n",newNode->strandId);  
                 printTree(newNode->right);  
                 printTree(newNode->left);  
         }  
 }  
407  void Diderot_KDTree_Build(@PREFIX@World_t *wrld, uint32_t id, double * spatialTotalTime)  void Diderot_KDTree_Build(@PREFIX@World_t *wrld, uint32_t id, double * spatialTotalTime)
408  {  {
409      SpatialScheduler_t * sched  =  wrld->spatialSched;      SpatialScheduler_t * sched  =  wrld->spatialSched;
# Line 403  Line 411 
411          treeWorker(&sched->workerData[id]);          treeWorker(&sched->workerData[id]);
412          return;          return;
413      }      }
414      double spatialT0  = airTime();      sched->startTime = airTime();
415      KDTree_t * tree  = wrld->spatialTree;      KDTree_t * tree  = wrld->spatialTree;
416      int numStrands = *(tree->numOfStrands);      int numStrands = *(tree->numOfStrands);
417      memcpy(wrld->spatialTmpIndices,wrld->spatialIndices, sizeof(uint32_t)*@SPATIAL_DIMENSION@ * wrld->numStrands);      memcpy(wrld->spatialTmpIndices,wrld->spatialIndices, sizeof(uint32_t)*@SPATIAL_DIMENSION@ * wrld->numStrands);
# Line 417  Line 425 
425              Diderot_Spatial_ParMergeSort(wrld,sched,wrld->spatialIndices,wrld->spatialTmpIndices,wrld->numStrands * 2,(3 * wrld->numStrands)-1,33390,2);              Diderot_Spatial_ParMergeSort(wrld,sched,wrld->spatialIndices,wrld->spatialTmpIndices,wrld->numStrands * 2,(3 * wrld->numStrands)-1,33390,2);
426          }          }
427      }      }
428      double spatialTotalTimeS = (airTime() - spatialST0);     // double spatialTotalTimeS = (airTime() - spatialST0);
429       if(spatialTotalTimeS >= 0.03)      // if(spatialTotalTimeS >= 0.03)
430          printf("maybe fixed parallel time to sort=%f\n",spatialTotalTimeS);      //    printf("maybe fixed parallel time to sort=%f\n",spatialTotalTimeS);
431    
432      tree->root = Diderot_KDTree_BuildHelper(wrld, wrld->spatialSched,0,*(tree->numOfStrands),0);      tree->root = Diderot_KDTree_BuildHelper(wrld, wrld->spatialSched,0,*(tree->numOfStrands),0);
433      printf("!!!!!!DONE!!!!\n");     // printf("!!!!!!DONE!!!!\n");
434      pthread_mutex_lock(&sched->lock);      pthread_mutex_lock(&sched->lock);
435          sched->numWorkers +=1;          sched->numWorkers +=1;
436      pthread_mutex_unlock(&sched->lock);      pthread_mutex_unlock(&sched->lock);
437      treeWorker(&sched->workerData[id]);      treeWorker(&sched->workerData[id]);
438          //printTree(tree->root);          //printTree(tree->root);
439          *(spatialTotalTime) = *(spatialTotalTime) + (airTime() - spatialT0);          *(spatialTotalTime) = *(spatialTotalTime) + sched->stopTime;
440          printf("Build Done\n");          //printf("Build Done\n");
441  }  }
442  void Diderot_KDTree_Init(@PREFIX@World_t *wrld)  void Diderot_KDTree_Init(@PREFIX@World_t *wrld)
443  {  {

Legend:
Removed from v.2570  
changed lines
  Added in v.2571

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0