Пример #1
0
void
ConstructGrid (long my_id, time_info *local_time, long time_all)
{
   unsigned long init = 0, start = 0, finish;

   if (time_all)
      CLOCK(init);
   DetermineGridSize(my_id);   /* Finds the four corners of the grid. */
   FreeBoxes(my_id);
   InitPartition(my_id);
   if (time_all)
      CLOCK(start);
   if (MY_NUM_PARTICLES > 0) {
      ConstructLocalGrid(my_id);  /* Each processor constructs their own tree
				     based on only their particles */
      MergeLocalGrid(my_id);   /* The processors combine their trees into one
				  global tree. This step contains
				  communication between processors. */
   }
   BARRIER(G_Memory->synch, Number_Of_Processors);
   CleanupGrid(my_id);
   if (time_all)
      CLOCK(finish);

   if (time_all) {
      local_time[MY_TIME_STEP].other_time = start - init;
      local_time[MY_TIME_STEP].construct_time = finish - start;
   }
}
Пример #2
0
void
CostZones (long my_id)
{
   PartitionIterate(my_id, ComputeSubTreeCosts, BOTTOM);
   {
#line 50
	unsigned long	Error, Cycle;
#line 50
	long		Cancel, Temp;
#line 50

#line 50
	Error = pthread_mutex_lock(&(G_Memory->synch).mutex);
#line 50
	if (Error != 0) {
#line 50
		printf("Error while trying to get lock in barrier.\n");
#line 50
		exit(-1);
#line 50
	}
#line 50

#line 50
	Cycle = (G_Memory->synch).cycle;
#line 50
	if (++(G_Memory->synch).counter != (Number_Of_Processors)) {
#line 50
		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &Cancel);
#line 50
		while (Cycle == (G_Memory->synch).cycle) {
#line 50
			Error = pthread_cond_wait(&(G_Memory->synch).cv, &(G_Memory->synch).mutex);
#line 50
			if (Error != 0) {
#line 50
				break;
#line 50
			}
#line 50
		}
#line 50
		pthread_setcancelstate(Cancel, &Temp);
#line 50
	} else {
#line 50
		(G_Memory->synch).cycle = !(G_Memory->synch).cycle;
#line 50
		(G_Memory->synch).counter = 0;
#line 50
		Error = pthread_cond_broadcast(&(G_Memory->synch).cv);
#line 50
	}
#line 50
	pthread_mutex_unlock(&(G_Memory->synch).mutex);
#line 50
};
   Local[my_id].Total_Work = Grid->subtree_cost;
   Local[my_id].Min_Work = ((Local[my_id].Total_Work / Number_Of_Processors)
			   * 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));
   InitPartition(my_id);
   CostZonesHelper(my_id, Grid, 0, RIGHT);
   {
#line 62
	unsigned long	Error, Cycle;
#line 62
	long		Cancel, Temp;
#line 62

#line 62
	Error = pthread_mutex_lock(&(G_Memory->synch).mutex);
#line 62
	if (Error != 0) {
#line 62
		printf("Error while trying to get lock in barrier.\n");
#line 62
		exit(-1);
#line 62
	}
#line 62

#line 62
	Cycle = (G_Memory->synch).cycle;
#line 62
	if (++(G_Memory->synch).counter != (Number_Of_Processors)) {
#line 62
		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &Cancel);
#line 62
		while (Cycle == (G_Memory->synch).cycle) {
#line 62
			Error = pthread_cond_wait(&(G_Memory->synch).cv, &(G_Memory->synch).mutex);
#line 62
			if (Error != 0) {
#line 62
				break;
#line 62
			}
#line 62
		}
#line 62
		pthread_setcancelstate(Cancel, &Temp);
#line 62
	} else {
#line 62
		(G_Memory->synch).cycle = !(G_Memory->synch).cycle;
#line 62
		(G_Memory->synch).counter = 0;
#line 62
		Error = pthread_cond_broadcast(&(G_Memory->synch).cv);
#line 62
	}
#line 62
	pthread_mutex_unlock(&(G_Memory->synch).mutex);
#line 62
};
}