int main(int argc, char * argv[]) { int X=atoi(argv[1]); int Y=X; double ** A=malloc2D(X,Y); int i,j,k; double l; struct timeval ts,tf; double total_time; init2D(A,X,Y); gettimeofday(&ts,NULL); for (k=0;k<X-1;k++) for (i=k+1;i<X;i++) { l=A[i][k]/A[k][k]; for (j=k;j<Y;j++) A[i][j]-=l*A[k][j]; } gettimeofday(&tf,NULL); total_time=(tf.tv_sec-ts.tv_sec)+(tf.tv_usec-ts.tv_usec)*0.000001; printf("LU-Serial\t%d\t%.3lf\n",X,total_time); char * filename="output_serial"; print2DFile(A,X,Y,filename); return 0; }
void CTargetingComputer::init() { // Create material colours CRGBAColour oDiffuse = CRGBAColour(0.0f,0.0f,0.0f,1.0f); CRGBAColour oAmbient = CRGBAColour(0.0f,0.0f,0.0f,1.0f); CRGBAColour oEmissive = CRGBAColour(1.0f,1.0f,1.0f,1.0f); // Create targeting reticle m_poTargetingReticle = new CFrame; m_poTargetingReticle->init2D(0.0f, 0.0f, 0.1f, 0.1f, "Hud/hud_reticle.png"); m_poTargetingReticle->setActiveMaterial(oDiffuse, oAmbient, oEmissive); m_poFont = g_oFontManager.getFont(1); // Create offscreen texture m_auiOffScreenTexture = g_oTextureManager.create(128,128); // Change to green colour oEmissive = CRGBAColour(0.0f,1.0f,0.0f,1.0f); // Setup main frame init2D(0.0f, 0.0f, 0.175f, 0.6f,"Hud/hud_target.png"); setActiveMaterial(oDiffuse, oAmbient, oEmissive); // Change to slightly transparent green colour oDiffuse = CRGBAColour(0.0f,0.0f,0.0f,0.5f); oAmbient = CRGBAColour(0.0f,0.0f,0.0f,0.5f); oEmissive = CRGBAColour(0.0f,1.0f,0.0f,0.5f); // Create holo target m_poHoloTarget = new CFrame; m_poHoloTarget->init2D(0.015f, 0.02f, 0.145f, 0.1933f,""); m_poHoloTarget->setActiveMaterial(oDiffuse, oAmbient, oEmissive, m_auiOffScreenTexture); }
/* * BOUCLE D'AFFICHAGE */ bool SceneManager::execute(SDL_Window* window, unsigned int w, unsigned int h) { init3D(w,h); init2D(); initSounds(); unsigned int debut ,fin; /* VARIABLES DE GESTION DU TEMPS */ float period = 1.0 / FPS_LIMIT,fps,time; while(!m_input.terminer()) /* BOUCLE D'EXECUTION */ { debut = SDL_GetTicks(); /* ON RELEVE LE TEMPS DE DEBUT DE BOUCLE */ onPreRender(); /* ON MET À JOUR LES MODELES DYNAMIQUES */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* NETTOYAGE DE LA FENETRE */ m_input.update(); /* MISE A JOUR DES EVENEMENTS */ updateCameras(); /* MISE À JOUR DES CAMERAS */ if(m_input.getKey(SDL_SCANCODE_ESCAPE)) break; /* QUITTER EN APPUYANT SUR ESPACE */ if(m_input.getKeyRelease(SDL_SCANCODE_V)) changeCamera(); /* CHANGER DE CAMERA EN APPUYANT SUR ESPACE */ if(m_input.getKeyRelease(SDL_SCANCODE_SPACE)) m_soundMgr.playEffect("laser",127/2); drawAll(); /* AFFICHAGE DE TOUS LES MODELES DU MONDE 3D */ SDL_GL_SwapWindow(window); /* RAFRAICHISSEMENT DE LA FENETRE */ fin = SDL_GetTicks(); /* ON RELEVE LE TEMPS DE FIN DE BOUCLE */ time = (float)(fin - debut); /* ON CALCULE LE TEMPS D'EXECUTION DE LA BOUCLE */ fps = 1000.0/time; /* ON CALCULE LA FREQUENCE MAXIMALE */ std::ostringstream streamTitle; streamTitle << "fps: " << fps; SDL_SetWindowTitle(window,streamTitle.str().c_str()); /* ON AFFICHE LA FREQUENCE COMME TITRE DE LA FENETRE */ if(time < period) SDL_Delay((unsigned int)(period - time)); /* ON LIMITE LA FREQUENCE A 60 FPS */ } printf("toto\n"); return true; }
int main() { glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(100,100); glutCreateWindow("Assignment 1 Draw Words"); init2D(0.0, 0.75, 0.0); glutDisplayFunc(display); glutMainLoop(); }
char* initialize ( char* cmdline ) { // Get comnmand line std::string str = cmdline; std::vector<std::string> args; while ( str.length() > 0) { args.push_back ( strSplit ( str, " " ) ); } fileName = ""; for (int n=0; n < args.size(); n++ ) { if ( args[n].compare ( "-f" ) == 0 ) { startFrame = strToI ( args[n+1] ); } if ( args[n].compare ( "-d" ) == 0 ) { // max_draw maxDraw = strToI ( args[n+1] ); } if ( args[n].find_first_of ( "." ) != std::string::npos ) { fileName = args[n]; } } if ( fileName.length()== 0 || args.size()==0 ) { app_printf ( "USAGE: state_view [-f #] [-d #] filename.raw\n\n" ); app_printf ( " -f # Start at frame \n" ); app_printf ( " -d # Maximum number of draw calls to read \n" ); _getch(); exit(-1); } for (int n=0; n < 10; n++ ) bShow[n] = true; // Initialize camera cam.setPos ( 0, 0, 1 ); cam.setToPos ( -window_width*3/8, -window_height*3/8, 1 ); cam.updateMatricies (); // Initialize bin and call names setup_bins (); // Load trace file char fname[256]; strcpy ( fname, fileName.c_str() ); load_trace_raw ( fname ); // required init functions init2D ( "arial_12" ); // specify font file (.bin/tga) setText ( 1.0, -0.5 ); // scale by 0.5, kerning adjust -0.5 pixels setview2D ( window_width, window_height ); // draw visualization layer drawMatrix (); PERF_INIT ( false ); // Enable CPU perf (do not require nv-perfmarker DLL) PERF_SET ( false, 2, false, "" ); // Perf CPU?, CPU level, NV Perfmarkers, Log filename return "NVIDIA State Viewer, by Rama Hoetzlein"; // Return Window title }
int main(int argc, char **argv){ int x = atoi(argv[1]); int y = x; double ** A = malloc2D(x, y); init2D(A, x, y); print2DFile(A, x, y, argv[2]); free2D(A, x, y); return 0; }
void initialize () { // GUI addGui ( 20, 20, 200, 24, "Frame Time (ms)", GUI_PRINT, GUI_FLOAT, &frameTime, 0, 0 ); addGui ( 20, 50, 200, 24, "Number of Rectangles", GUI_SLIDER, GUI_INT, &numRects, 0, 1000 ); addGui ( 20, 80, 200, 24, "Number of Circles", GUI_SLIDER, GUI_INT, &numCircles, 0, 1000 ); addGui ( 20, 110, 200, 24, "Number of Lines", GUI_SLIDER, GUI_INT, &numLines, 0, 10000 ); addGui ( 20, 140, 200, 24, "Number of Text", GUI_SLIDER, GUI_INT, &numText, 0, 1000 ); glViewport( 0, 0, window_width, window_height ); // required init functions init2D ( "arial_24" ); // specify font file (.bin/tga) setText ( 0.5, -0.5 ); // scale by 0.5, kerning adjust -0.5 pixels setview2D ( window_width, window_height ); setorder2D ( true, -.00001 ); PERF_INIT ( false ); // Enable CPU perf (do not require nv-perfmarker DLL) PERF_SET ( true, 2, false, "" ); // Perf CPU on, Perf print depth, nv-perfmarkers off, no log file }
int main (int argc, char * argv[]) { int rank,size; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); int X,Y,x,y,X_ext,i,j,k; double ** A, ** localA, l, *msg; X=atoi(argv[1]); Y=X; //Extend dimension X with ghost cells if X%size!=0 if (X%size!=0) X_ext=X+size-X%size; else X_ext=X; if (rank==0) { //Allocate and init matrix A A=malloc2D(X_ext,Y); init2D(A,X,Y); } //Local dimensions x,y x=X_ext/size; y=Y; //Allocate local matrix and scatter global matrix localA=malloc2D(x,y); double * idx; if (rank==0) idx=&A[0][0]; MPI_Scatter(idx,x*y,MPI_DOUBLE,&localA[0][0],x*y,MPI_DOUBLE,0,MPI_COMM_WORLD); if (rank==0) { free2D(A,X_ext,Y); } //Timers struct timeval ts,tf,comps,compf,comms,commf; double total_time=0,computation_time=0,communication_time=0; MPI_Barrier(MPI_COMM_WORLD); gettimeofday(&ts,NULL); /****************************************************************************** The matrix A is distributed in contiguous blocks to the local matrices localA You have to use point-to-point communication routines Don't forget to set the timers for computation and communication! ******************************************************************************/ //******************************************************************************** msg = malloc(y * sizeof(double)); int tag =55, dest, dif, srank; MPI_Status status; MPI_Request request; for(k = 0; k < X - 1; k++){ // if is owner_of_pivot_line(k) - x*rank <= k < x*(rank+1) if ( ( x*rank <= k ) && ( k < (x * (rank + 1)) ) ) { //pack_data(lA, send_buffer); memcpy(msg, localA[ k%x ], y * sizeof(double) ); //send_data_to_all for(dest=0;dest<size;dest++) { if ((dest==rank) || (dest<rank)) continue; gettimeofday(&comms,NULL); MPI_Send(msg,y,MPI_DOUBLE,dest,tag,MPI_COMM_WORLD); gettimeofday(&commf,NULL); communication_time+=commf.tv_sec-comms.tv_sec+(commf.tv_usec-comms.tv_usec)*0.000001; } } else { //receive_data_from_owner //unpack_data(receive_buffer, lA); srank = k / x; if ((rank<srank) || (rank==srank)) continue; gettimeofday(&comms,NULL); MPI_Recv(msg,y,MPI_DOUBLE,srank,tag,MPI_COMM_WORLD,&status); gettimeofday(&commf,NULL); communication_time+=commf.tv_sec-comms.tv_sec+(commf.tv_usec-comms.tv_usec)*0.000001; } //compute(k, lA); gettimeofday(&comps,NULL); if ( k < ( x * (rank + 1) - 1 ) ) { dif = ( x * (rank + 1) - 1 ) - k; if (dif > x) dif = x; for ( i = x - dif; i < x; i++ ) { l = localA[i][k] / msg[k]; for ( j=k; j<y; j++ ) localA[i][j] -= l * msg[j]; } } gettimeofday(&compf,NULL); computation_time+=compf.tv_sec-comps.tv_sec+(compf.tv_usec-comps.tv_usec)*0.000001; } free(msg); MPI_Barrier(MPI_COMM_WORLD); //******************************************************************************** gettimeofday(&tf,NULL); total_time=tf.tv_sec-ts.tv_sec+(tf.tv_usec-ts.tv_usec)*0.000001; //Gather local matrices back to the global matrix if (rank==0) { A=malloc2D(X_ext,Y); idx=&A[0][0]; } MPI_Gather(&localA[0][0],x*y,MPI_DOUBLE,idx,x*y,MPI_DOUBLE,0,MPI_COMM_WORLD); double avg_total,avg_comp,avg_comm,max_total,max_comp,max_comm; MPI_Reduce(&total_time,&max_total,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD); MPI_Reduce(&computation_time,&max_comp,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD); MPI_Reduce(&communication_time,&max_comm,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD); MPI_Reduce(&total_time,&avg_total,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); MPI_Reduce(&computation_time,&avg_comp,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); MPI_Reduce(&communication_time,&avg_comm,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); avg_total/=size; avg_comp/=size; avg_comm/=size; if (rank==0) { printf("LU-Block-p2p\tSize\t%d\tProcesses\t%d\n",X,size); printf("Max times:\tTotal\t%lf\tComp\t%lf\tComm\t%lf\n",max_total,max_comp,max_comm); printf("Avg times:\tTotal\t%lf\tComp\t%lf\tComm\t%lf\n",avg_total,avg_comp,avg_comm); } //Print triangular matrix U to file if (rank==0) { char * filename="output_block_p2p"; print2DFile(A,X,Y,filename); } MPI_Finalize(); return 0; }
void REV_init() { //Local variables f32 yscale; u32 xfbHeight; //Load the right IOS, so keyboard works fin u32 iosVersion = IOS_GetVersion(); if(iosVersion != 36) { IOS_ReloadIOS(36); } //// VIDEO_Init();//Video Library Init PAD_Init();//Gamecube Pad Library Init WPAD_Init();//Wiimote Library Init rMode = VIDEO_GetPreferredMode(NULL);//Set render mode // allocate 2 framebuffers for double buffering frameBuffer[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rMode)); frameBuffer[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rMode)); //Configure Video System VIDEO_Configure(rMode); VIDEO_SetNextFramebuffer(frameBuffer[fb]);//Initial Framebuffer VIDEO_Flush(); VIDEO_WaitVSync(); if(rMode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); fb ^= 1;//Set next index //Set up the FIFO void *gp_fifo = memalign(32,DEFAULT_FIFO_SIZE);//Allocate memset(gp_fifo,0,DEFAULT_FIFO_SIZE);//and Clear //Init GX hardware GX_Init(gp_fifo,DEFAULT_FIFO_SIZE); // clears the bg to color and clears the z buffer GX_SetCopyClear(DEF_BG_COLOR , 0x00ffffff); //More initialization w = rMode->viWidth; h = rMode->viHeight; yscale = GX_GetYScaleFactor(rMode->efbHeight,rMode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetDispCopySrc(0,0,rMode->fbWidth,rMode->efbHeight); GX_SetDispCopyDst(rMode->fbWidth,xfbHeight); GX_SetFieldMode(rMode->field_rendering,((h==2*rMode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (rMode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_CopyDisp(frameBuffer[fb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); for(u8 i = 0; i < 4; i++) WPAD_SetVRes(i,w,h); //Hardware Initialized, now engine initialization //Init filesystem fatInitDefault(); //First create a Root mainRoot = new ROOT; mainRoot->init((f32)w,(f32)h); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetColorUpdate(GX_ENABLE); GX_SetAlphaUpdate(GX_ENABLE); GX_SetZCompLoc(GX_TRUE); GX_SetZMode (GX_TRUE, GX_LEQUAL, GX_TRUE); init3dConfig(); init2dConfig(); init2D(w, h); transQueue = NULL; solidQueue = NULL; zQueue = NULL; REV_fontsInit(); KEYBOARD_Init(NULL); keyboardInit(); }
int main (int argc, char * argv[]) { int rank,size; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); int X,Y,x,y,X_ext,i; double **A, **localA; X=atoi(argv[1]); Y=X; //Extend dimension X with ghost cells if X%size!=0 if (X%size!=0) X_ext=X+size-X%size; else X_ext=X; if (rank==0) { //Allocate and init matrix A A=malloc2D(X_ext,Y); init2D(A,X,Y); } //Local dimensions x,y x=X_ext/size; y=Y; //Allocate local matrix and scatter global matrix localA=malloc2D(x,y); double * idx; for (i=0;i<x;i++) { if (rank==0) idx=&A[i*size][0]; MPI_Scatter(idx,Y,MPI_DOUBLE,&localA[i][0],y,MPI_DOUBLE,0,MPI_COMM_WORLD); } if (rank==0) free2D(A,X_ext,Y); //Timers struct timeval ts,tf,comps,compf,comms,commf; double total_time,computation_time,communication_time; MPI_Barrier(MPI_COMM_WORLD); gettimeofday(&ts,NULL); /****************************************************************************** The matrix A is distributed in a round-robin fashion to the local matrices localA You have to use point-to-point communication routines. Don't forget the timers for computation and communication! ******************************************************************************/ int line_index, line_owner; int k, start; double *k_row, *temp; MPI_Status status; temp = malloc(y * sizeof(*temp)); // k_row = malloc(y * sizeof(*k_row)); /* omoia me to allo cyclic, vriskoume ton line_owner */ for (k=0; k<y-1; k++){ line_owner = k % size; line_index = k / size; if (rank <= line_owner) start = k / size + 1; else start = k / size; if (rank == line_owner) k_row = localA[line_index]; else k_row = temp; /* set communication timer */ gettimeofday(&comms, NULL); /* COMM */ // if (rank != line_owner){ // if (rank == 0) // MPI_Recv( k_row, y, MPI_DOUBLE, size-1, MPI_ANY_SOURCE, MPI_COMM_WORLD, &status); // else // MPI_Recv( k_row, y, MPI_DOUBLE, rank-1, MPI_ANY_SOURCE, MPI_COMM_WORLD, &status); // } // // /* autos pou einai prin ton line_owner den prepei na steilei */ // if (rank != line_owner -1){ // /* o teleutaios prepei na steilei ston prwto, ektos an o prwtos einai o line_owner */ // if (rank == size-1) { // if (line_owner != 0) // MPI_Send( k_row, y, MPI_DOUBLE, 0, rank, MPI_COMM_WORLD); // } // else // MPI_Send(k_row, y, MPI_DOUBLE, rank+1, rank, MPI_COMM_WORLD); // } /* o line_owner stelnei se olous (ektos tou eautou tou) kai oloi oi alloi kanoun * receive */ if (rank == line_owner){ for (i=0; i<size; i++) if (i != line_owner) MPI_Send( k_row, y, MPI_DOUBLE, i, line_owner, MPI_COMM_WORLD); } else MPI_Recv(k_row, y, MPI_DOUBLE, line_owner, line_owner, MPI_COMM_WORLD, &status); /* stop communication timer */ gettimeofday(&commf, NULL); communication_time += commf.tv_sec - comms.tv_sec + (commf.tv_usec - comms.tv_usec)*0.000001; /* set computation timer */ gettimeofday(&comps, NULL); /* Compute */ go_to_work( localA, k_row, x, y, rank, start, k ); /* stop computation timer */ gettimeofday(&compf, NULL); computation_time += compf.tv_sec - comps.tv_sec + (compf.tv_usec - comps.tv_usec)*0.000001; } gettimeofday(&tf,NULL); total_time=tf.tv_sec-ts.tv_sec+(tf.tv_usec-ts.tv_usec)*0.000001; //Gather local matrices back to the global matrix if (rank==0) A=malloc2D(X_ext,Y); for (i=0;i<x;i++) { if (rank==0) idx=&A[i*size][0]; MPI_Gather(&localA[i][0],y,MPI_DOUBLE,idx,Y,MPI_DOUBLE,0,MPI_COMM_WORLD); } double avg_total,avg_comp,avg_comm,max_total,max_comp,max_comm; MPI_Reduce(&total_time,&max_total,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD); MPI_Reduce(&computation_time,&max_comp,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD); MPI_Reduce(&communication_time,&max_comm,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD); MPI_Reduce(&total_time,&avg_total,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); MPI_Reduce(&computation_time,&avg_comp,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); MPI_Reduce(&communication_time,&avg_comm,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); avg_total/=size; avg_comp/=size; avg_comm/=size; if (rank==0) { printf("LU-Cyclic-p2p\tSize\t%d\tProcesses\t%d\n",X,size); printf("Max times:\tTotal\t%lf\tComp\t%lf\tComm\t%lf\n",max_total,max_comp,max_comm); printf("Avg times:\tTotal\t%lf\tComp\t%lf\tComm\t%lf\n",avg_total,avg_comp,avg_comm); } //Print triangular matrix U to file if (rank==0) { char * filename="output_cyclic_p2p"; print2DFile(A,X,Y,filename); } MPI_Finalize(); return 0; }
//////////////////////////////////////////////////////////////////////////////////////////////// ///// ********** PUBLIC METHODS //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// RRSchedule::RRSchedule(int _max_weeks, int _max_times, int _max_courts, int _max_teams, char* _FILENAME, int SKIP_FIRST) { max_weeks = _max_weeks; max_times = _max_times; max_courts = _max_courts; max_teams = _max_teams; skip_first = SKIP_FIRST; FILENAME = _FILENAME; week0 = (skip_first > 0); // Check if special considerations need to be made for the first week (allowing a meeting) min_per_night = (max_courts * max_times * 2) / max_teams; w0_min_per_night = (max_courts * (max_times-skip_first) * 2) / max_teams; max_per_night = (max_courts * max_times * 2) / max_teams + ( ((max_courts * max_times * 2) % max_teams) != 0); w0_max_per_night = (max_courts * (max_times - skip_first) * 2) / max_teams + ( ((max_courts * (max_times - skip_first) * 2) % max_teams) != 0); MAX_PLAYED_GAP = 1; // <= Gap between min times played and max times played if (max_per_night > 2) then: { MAX_WAIT_TIME = min_per_night; // <= Max time a team can wait each night } else { MAX_WAIT_TIME = min_per_night; } MAX_WAIT_GAP = 1; //*max_times ; // /2; // <= Gap between min team wait time and max team wait time MAX_TIMESLOT_GAP = 2 ; //max_weeks / 2; // <= Gap between count of min timeslot vs. max timeslot appearances TIMESLOT_FUDGE = 0; // *max_per_night; // Allow teams to play in a timeslot # over "ideal" max_per_time = (max_weeks * max_courts * 2) / max_teams + ( ((max_weeks * max_courts * 2) % max_teams) != 0) + TIMESLOT_FUDGE; // std::cout << "**" <<std:endl; fullSolution = false; total_wait_time = 0; init1D(this_week_played, max_teams); allocate1D(courts, max_courts*2); init1D(total_played, max_teams); init1D(total_waiting_by_team, max_teams); init2D(opponent_counts, max_teams, max_teams); allocate2D(timeslots, max_times, max_courts*2); allocate2D(matchups, max_weeks * max_times * max_courts, 2); init2D(this_week_matchups, (max_times-skip_first)*max_courts, 2); init2D(timeslots_played, max_teams, max_times); init2D(courts_played, max_teams, max_courts); allocate2D(timePermutes, FACTS[max_times], max_times); compute_permutations(); allocate2D(total_this_week_played,max_weeks, max_teams); allocate3D(weeks, max_weeks, max_times, max_courts*2); // clear old file std::ofstream outputfile; outputfile.open(FILENAME); outputfile.close(); }
bool RRSchedule::add_week() // Add a full set of timeslots to the week { // Guarantee everyone played a sufficient number of times bool mincheck = (min_per_night <= VectMin(this_week_played)); if (week0) { int temp_min_per_night = (max_courts * (max_times - skip_first) * 2) / max_teams; mincheck = temp_min_per_night <= VectMin(this_week_played); } bool goodSort = false; bool acceptableWait = false; if (mincheck) { // Check to ensure sorting is acceptable? goodSort = sort_times_new(timeslots); if (goodSort) { Vector temp_team_waits = total_waiting_by_team; VectDotSum(temp_team_waits, compute_team_waits_for_week(timeslots)); acceptableWait = ( VectMax(temp_team_waits) - VectMin(temp_team_waits) <= MAX_WAIT_GAP); if (acceptableWait) { // Roll up timeslot information into the week and log weeks.push_back(timeslots); store_timeslot(); // No longer first week after successful addition of timeslot week0 = false; // Reset the timeslots and matchups for this week allocate2D(timeslots, max_times, max_courts*2); init2D(this_week_matchups, max_teams, max_teams); total_this_week_played.push_back(this_week_played); init1D(this_week_played,max_teams); compute_total_team_waits(); compute_fitness(); // Note progress for user printf ("Current Size: %d weeks (Max Weeks: %d). Total Wait Time: %d Fitness Level: %d (Scaled Fitness: %.2f) Printed Solutions: %d\n", int(weeks.size()), max_weeks, total_wait_time, fitness_level, scaled_fitness_level, PRINTED_SOLUTIONS); std::cout << weeks.size() << std::endl; if (weeks.size() == max_weeks) { printf("Full Solution?\n"); fullSolution = true; } else{ printf ("Not full Solution\n"); } } } } return mincheck and goodSort and acceptableWait; }
int main (int argc, char * argv[]) { int rank,size; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); int X,Y,x,y,X_ext, i; double ** A, ** localA; X=atoi(argv[1]); Y=X; //Extend dimension X with ghost cells if X%size!=0 if (X%size!=0) X_ext=X+size-X%size; else X_ext=X; if (rank==0) { //Allocate and init matrix A A=malloc2D(X_ext,Y); init2D(A,X,Y); } //Local dimensions x,y x=X_ext/size; y=Y; //Allocate local matrix and scatter global matrix localA=malloc2D(x,y); double * idx; if (rank==0) idx=&A[0][0]; MPI_Scatter(idx,x*y,MPI_DOUBLE,&localA[0][0],x*y,MPI_DOUBLE,0,MPI_COMM_WORLD); if (rank==0) { free2D(A,X_ext,Y); } //Timers struct timeval ts,tf,comps,compf,comms,commf; double total_time,computation_time,communication_time; MPI_Barrier(MPI_COMM_WORLD); gettimeofday(&ts,NULL); /****************************************************************************** The matrix A is distributed in contiguous blocks to the local matrices localA You have to use point-to-point communication routines Don't forget to set the timers for computation and communication! ******************************************************************************/ int line_index, line_owner; int k, start; MPI_Status status; double *k_row, *temp; temp = malloc(y * sizeof(*k_row)); for (k=0; k<y-1; k++){ start = 0; line_owner = k / x; line_index = k % x; if (rank == line_owner){ start = line_index+1; k_row = localA[line_index]; } else k_row = temp; /* set communication timer */ gettimeofday(&comms, NULL); /* o line_owner stelnei se olous (ektos tou eautou tou) kai oi alloi * kanoun receive th k_row */ if (rank == line_owner){ for (i=0; i<size; i++) if (i != line_owner) MPI_Send( k_row, y, MPI_DOUBLE, i, line_owner, MPI_COMM_WORLD); } else MPI_Recv(k_row, y, MPI_DOUBLE, line_owner, line_owner, MPI_COMM_WORLD, &status); /* stop communication timer */ gettimeofday(&commf, NULL); communication_time += commf.tv_sec - comms.tv_sec + (commf.tv_usec - comms.tv_usec)*0.000001; /* set computation timer */ gettimeofday(&comps, NULL); /* Compute */ go_to_work( localA, k_row, x, y, rank, line_owner, start, k ); /* stop computation timer */ gettimeofday(&compf, NULL); computation_time += compf.tv_sec - comps.tv_sec + (compf.tv_usec - comps.tv_usec)*0.000001; } gettimeofday(&tf,NULL); total_time=tf.tv_sec-ts.tv_sec+(tf.tv_usec-ts.tv_usec)*0.000001; //Gather local matrices back to the global matrix if (rank==0) { A=malloc2D(X_ext,Y); idx=&A[0][0]; } MPI_Gather(&localA[0][0],x*y,MPI_DOUBLE,idx,x*y,MPI_DOUBLE,0,MPI_COMM_WORLD); double avg_total,avg_comp,avg_comm,max_total,max_comp,max_comm; MPI_Reduce(&total_time,&max_total,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD); MPI_Reduce(&computation_time,&max_comp,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD); MPI_Reduce(&communication_time,&max_comm,1,MPI_DOUBLE,MPI_MAX,0,MPI_COMM_WORLD); MPI_Reduce(&total_time,&avg_total,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); MPI_Reduce(&computation_time,&avg_comp,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); MPI_Reduce(&communication_time,&avg_comm,1,MPI_DOUBLE,MPI_SUM,0,MPI_COMM_WORLD); avg_total/=size; avg_comp/=size; avg_comm/=size; if (rank==0) { printf("LU-Block-p2p\tSize\t%d\tProcesses\t%d\n",X,size); printf("Max times:\tTotal\t%lf\tComp\t%lf\tComm\t%lf\n",max_total,max_comp,max_comm); printf("Avg times:\tTotal\t%lf\tComp\t%lf\tComm\t%lf\n",avg_total,avg_comp,avg_comm); } //Print triangular matrix U to file if (rank==0) { char * filename="output_block_p2p"; print2DFile(A,X,Y,filename); } MPI_Finalize(); return 0; }