// in the special case of vectors of integers, this could be done // more efficiently by just copying the vectors. Complex2D::Complex2D(const Complex2D& rhs) { num_of_edges_cache = rhs.num_of_edges_cache; stored_geometry_complex2D dummy(*this); ConstructGrid(*this,dummy, rhs,stored_geometry_complex2D(rhs)); }
void ConstructGrid(OstreamGMV3DFmt& Out, GRID const& G, GEOM const& GEO) { typedef heterogeneous_list::END END; heterogeneous_list::List<END,END> L; ConstructGrid(Out,G,GEO,L); }
Complex2D& Complex2D::operator=(const Complex2D& rhs) { if(this != &rhs) { clear(); stored_geometry_complex2D dummy(*this); ConstructGrid(*this,dummy, rhs,stored_geometry_complex2D(rhs)); num_of_edges_cache = rhs.num_of_edges_cache; } return (*this); }
void ParallelExecute () { long my_id; long num_boxes; unsigned long start, finish = 0; time_info *local_time; long time_all = 0; time_info *timing; unsigned long local_init_done = 0; BARINCLUDE(G_Memory->synch); local_time = (time_info *) malloc(sizeof(struct _Time_Info) * MAX_TIME_STEPS); BARRIER(G_Memory->synch, Number_Of_Processors); LOCK(G_Memory->count_lock); my_id = G_Memory->id; G_Memory->id++; UNLOCK(G_Memory->count_lock); /* POSSIBLE ENHANCEMENT: Here is where one might pin processes to processors to avoid migration */ if (my_id == 0) { time_all = 1; } else if (do_stats) { time_all = 1; } if (my_id == 0) { /* have to allocate extra space since it will construct the grid by * itself for the first time step */ CreateParticleList(my_id, Total_Particles); InitParticleList(my_id, Total_Particles, 0); } else { CreateParticleList(my_id, ((Total_Particles * PDF) / Number_Of_Processors)); InitParticleList(my_id, 0, 0); } // num_boxes = 1333 * (Total_Particles / (OCCUPANCY * MAX_PARTICLES_PER_BOX)) /1000; num_boxes = 1333 * 4 * Total_Particles / (3 * MAX_PARTICLES_PER_BOX * 1000 ); if (my_id == 0) CreateBoxes(my_id, TOLERANCE * num_boxes); else CreateBoxes(my_id, TOLERANCE * num_boxes * BDF / Number_Of_Processors); if (my_id == 0) { LockedPrint("Starting FMM with %d processor%s\n", Number_Of_Processors, (Number_Of_Processors == 1) ? "" : "s"); } BARRIER(G_Memory->synch, Number_Of_Processors); Local[my_id].Time = 0.0; for (MY_TIME_STEP = 0; MY_TIME_STEP < Time_Steps; MY_TIME_STEP++) { if (MY_TIME_STEP == 2) { /* POSSIBLE ENHANCEMENT: Here is where one might reset the statistics that one is measuring about the parallel execution */ } if (MY_TIME_STEP == 2) { if (do_stats || my_id == 0) { CLOCK(local_init_done); } } if (MY_TIME_STEP == 0) { CLOCK(start); } else start = finish; ConstructGrid(my_id,local_time,time_all); ConstructLists(my_id,local_time,time_all); PartitionGrid(my_id,local_time,time_all); StepSimulation(my_id,local_time,time_all); DestroyGrid(my_id,local_time,time_all); CLOCK(finish); Local[my_id].Time += Timestep_Dur; MY_TIMING[MY_TIME_STEP].total_time = finish - start; } if (my_id == 0) { CLOCK(endtime); } BARRIER(G_Memory->synch, Number_Of_Processors); for (MY_TIME_STEP = 0; MY_TIME_STEP < Time_Steps; MY_TIME_STEP++) { timing = &(MY_TIMING[MY_TIME_STEP]); timing->other_time = local_time[MY_TIME_STEP].other_time; timing->construct_time = local_time[MY_TIME_STEP].construct_time; timing->list_time = local_time[MY_TIME_STEP].list_time; timing->partition_time = local_time[MY_TIME_STEP].partition_time; timing->pass_time = local_time[MY_TIME_STEP].pass_time; timing->inter_time = local_time[MY_TIME_STEP].inter_time; timing->barrier_time = local_time[MY_TIME_STEP].barrier_time; timing->intra_time = local_time[MY_TIME_STEP].intra_time; } Local[my_id].init_done_times = local_init_done; BARRIER(G_Memory->synch, Number_Of_Processors); }
int main (int args, char *argc[]) { FILE *f; char buf[64]; char temp[64]; char path[64]; int add; long oldscore; unsigned int oldtime; unsigned int start = time(NULL); unsigned int spent; srand(time(NULL)); printf("\n"); printf("*********************************************************\n"); printf("Welcome to TAWS (Text Adventure Without Swords) volume 2!\n"); printf("*********************************************************\n"); printf("\n"); ConstructGrid(); DisplayGrid(); timestart = time(NULL); while (1) { printf("\n"); printf("Enter command here: "); scanf("%s", buf); if (!strcmp(buf, "show")) DisplayGrid(); else if (buf[0] == '5' || !strcmp(buf, "new")) { ConstructGrid(); DisplayGrid(); timestart = time(NULL); } else if (!strcmp(buf, "score")) printf("Score: %li\n", score); else if (!strcmp(buf, "help")) { printf("The object of TAWS v2 is to enter a sequence\n"); printf("of numbers (on the numpad) that matches a path to\n"); printf("the finish (F) from the start (S). Avoid mines (*).\n"); printf("For example, 8 moves up, 9 moves up and right, and 2 moves down.\n"); printf("-- Commands --\n"); printf("#####: Type a series of numbers and hit enter to enter a path.\n"); printf("'score': Show your current score.\n"); printf("'new' or '5': Generate a new board.\n"); printf("'show': Display current board.\n"); printf("'help': Show this help.\n"); printf("'highscore': See a saved highscore.\n"); printf("'exit': Exit the game, but why would you want that?\n"); printf("-- Tips --\n"); printf("The shorter your path and faster you do it, the more points you get!\n"); } else if (!strcmp(buf, "TAWS")) { printf("TAWS is most commonly known as Text Adventure Without Swords.\n"); printf("However, it has other meanings as well, including:\n"); printf("Timed Avoidance Withstanding Simulation\n"); printf("Torrential Admission of Watery Soup\n"); printf("Timetable Antithesis Waking Somebody\n"); printf("Top Ankle Wise Surrender\n"); printf("... or just TAWS.\n"); } else if (!strcmp(buf, "highscore")) { printf("Please enter a name: "); scanf("%s", temp); sprintf(path, "%s.sav", temp); f = fopen(path, "rb"); if (f) { fread(&oldscore, sizeof(long), 1, f); fread(&oldtime, sizeof(unsigned int), 1, f); fclose(f); printf("Old score for %s: %li in %u seconds.\n", temp, oldscore, oldtime); } else printf("Failed to open save file %s.\n", path); } else if (!strcmp(buf, "quit") || !strcmp(buf, "exit")) break; else if (IsANumber(buf[0])) { int result = CheckPath(buf); if(result == FINISH) { float timediff = (float)(time(NULL)-timestart); if (timediff > 0) add = 50-(strlen(buf)-4)*4 + (int)(50.0f*(float)strlen(buf)/(float)(time(NULL)-timestart)); else add = 50-(strlen(buf)-4)*4 + (int)(50.0f*(float)strlen(buf)); printf("Score: %li+%i=%li\n", score, add, score+add); score += add; } else { printf("You didn't make it to the finish!\n"); printf("Score: %li-250=%li\n", score, score-250); score -= 250; } ConstructGrid(); DisplayGrid(); timestart = time(NULL); } else printf("Come on, type something real (try 'help').\n"); } spent = time(NULL)-start; printf("You got %li points in %u minutes and %u seconds. Good job!\n", score, (spent/60), (spent%60)); printf("Please enter your name: "); scanf("%s", buf); sprintf(temp, "%s.sav", buf); f = fopen(temp, "rb"); if (f) { fread(&oldscore, sizeof(long), 1, f); fread(&oldtime, sizeof(unsigned int), 1, f); fclose(f); } else { oldscore = 0; oldtime = 0; } if (score > oldscore) { f = fopen(temp, "wb"); if (f) { printf("New personal highscore: %li in %u seconds!\n", score, spent); fwrite(&score, sizeof(long), 1, f); fwrite(&spent, sizeof(unsigned int), 1, f); } } if (oldscore > 0) printf("Old personal highscore: %li in %u seconds.\n", oldscore, oldtime); printf("Well wasn't that fun? See you next time!\n\n"); return 0; }