void StepSimulation (long my_id, time_info *local_time, long time_all) { unsigned long start, finish; unsigned long upward_end, interaction_end, downward_end, barrier_end; if (time_all) CLOCK(start); PartitionIterate(my_id, UpwardPass, BOTTOM); if (time_all) CLOCK(upward_end); PartitionIterate(my_id, ComputeInteractions, BOTTOM); if (time_all) CLOCK(interaction_end); BARRIER(G_Memory->synch, Number_Of_Processors); if (time_all) CLOCK(barrier_end); PartitionIterate(my_id, DownwardPass, TOP); if (time_all) CLOCK(downward_end); PartitionIterate(my_id, ComputeParticlePositions, CHILDREN); if (time_all) CLOCK(finish); if (time_all) { local_time[MY_TIME_STEP].pass_time = upward_end - start; local_time[MY_TIME_STEP].inter_time = interaction_end - upward_end; local_time[MY_TIME_STEP].barrier_time = barrier_end - interaction_end; local_time[MY_TIME_STEP].pass_time += downward_end - barrier_end; local_time[MY_TIME_STEP].intra_time = finish - downward_end; } }
void ConstructLists (long my_id, time_info *local_time, long time_all) { unsigned long start, finish; if (time_all) CLOCK(start); PartitionIterate(my_id, ConstructGridLists, TOP); BARRIER(G_Memory->synch, Number_Of_Processors); PartitionIterate(my_id, ConstructInteractionLists, BOTTOM); if (time_all) CLOCK(finish); if (time_all) { local_time[MY_TIME_STEP].list_time = finish - start; } }
/* * PrintGrid (long my_id) * * Args : none. * * Returns : nothing. * * Side Effects : Prints the entire box structure of the grid to stdout. * */ void PrintGrid (long my_id) { if (Grid != NULL) { if (my_id == 0) { printf("Info for Adaptive Grid :\n"); printf("Boxes :\n\n"); } fflush(stdout); BARRIER(G_Memory->synch, Number_Of_Processors); PartitionIterate(my_id, (partition_function)PrintBox, TOP); BARRIER(G_Memory->synch, Number_Of_Processors); if (my_id == 0) { printf("\n"); } fflush(stdout); BARRIER(G_Memory->synch, Number_Of_Processors); } else printf("Adaptive grid has not been initialized yet.\n"); }
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 }; }