void TestInsertSort_NonIncreasing() { int nArrary[50]; assert(GetRandArray(nArrary, sizeof(nArrary)/sizeof(int))); DumpArray(nArrary, sizeof(nArrary)/sizeof(int)); assert(Insertation_Sort_NonIncreasing(nArrary, sizeof(nArrary)/sizeof(int))); DumpArray(nArrary, sizeof(nArrary)/sizeof(int)); }
void Test_Selection_Sort() { int nArrary[50]; assert(GetRandArray(nArrary, sizeof(nArrary)/sizeof(int))); DumpArray(nArrary, sizeof(nArrary)/sizeof(int)); assert(Selection_Sort(nArrary, sizeof(nArrary)/sizeof(int))); DumpArray(nArrary, sizeof(nArrary)/sizeof(int)); }
void Test_Merge_Sort_No_Sentinel() { int nArrary[50]; assert(GetRandArray(nArrary, sizeof(nArrary)/sizeof(int))); DumpArray(nArrary, sizeof(nArrary)/sizeof(int)); Merge_Sort_No_Sentinel(nArrary, 0, sizeof(nArrary)/sizeof(int)-1); DumpArray(nArrary, sizeof(nArrary)/sizeof(int)); }
// Write exram (aram or mem2) to file void CMemoryWindow::OnDumpMem2( wxCommandEvent& event ) { if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) { DumpArray(File::GetUserPath(F_ARAMDUMP_IDX), Memory::m_pEXRAM, Memory::EXRAM_SIZE); } else { DumpArray(File::GetUserPath(F_ARAMDUMP_IDX), DSP::GetARAMPtr(), DSP::ARAM_SIZE); } }
void Test_Bubble_Sort() { int len = ARRARY_SIZE; int *nArrary = new int[len] ; assert(GetRandArray(nArrary, len)); DumpArray(nArrary, len); int interval = GetTickCount(); Bubble_Sort(nArrary, len); interval = GetTickCount() - interval; printf("Bubble_Sort with InsertionSort: Consume %d millisecond to sort %d items \r\n", interval, len); DumpArray(nArrary, len); delete nArrary; nArrary = NULL; }
void Test_ComputeNumberofInversion() { int len = ARRARY_SIZE; int *nArrary = new int[len] ; assert(GetRandArray(nArrary, len)); DumpArray(nArrary, len); int interval = GetTickCount(); int inversions = 0; ComputeNumberofInversion(nArrary, 0, len-1, &inversions); interval = GetTickCount() - interval; printf("ComputeNumberofInversion with InsertionSort: Inversions = % d, Consume %d millisecond to sort %d items \r\n", inversions, interval, len); DumpArray(nArrary, len); delete nArrary; nArrary = NULL; }
void Test_Binary_Search() { int nArrary[50]; assert(GetRandArray(nArrary, sizeof(nArrary)/sizeof(int))); Merge_Sort(nArrary, 0, sizeof(nArrary)/sizeof(int)-1); DumpArray(nArrary, sizeof(nArrary)/sizeof(int)); int index = BinarySearch(nArrary, sizeof(nArrary)/sizeof(int)-1, nArrary[10]); printf("the index of %d = %d \r\n", nArrary[10], index); }
void Test_ExistTwoElementWithSum() { int nArrary[50]; assert(GetRandArray(nArrary, sizeof(nArrary)/sizeof(int))); Merge_Sort(nArrary, 0, sizeof(nArrary)/sizeof(int)-1); point val; int sum = nArrary[10]+nArrary[33]; bool bExist = ExistTwoElementWithSum(nArrary, sizeof(nArrary)/sizeof(int)-1, sum, &val); DumpArray(nArrary, sizeof(nArrary)/sizeof(int)); if (bExist) { printf("the sum of %d + %d = %d \r\n", val.x, val.y, sum); } }
void Test_EvaluatingPolynomial() { int len = ARRARY_SIZE; int *nArrary = new int[len] ; int x = 3; int y = 0; assert(GetRandArray(nArrary, len)); Merge_Sort_With_Internal_InsertionSort(nArrary, 0, len-1, 8); DumpArray(nArrary, len); y = HornerEvaluatingPolynomial(nArrary, len-1, x); printf("HornerEvaluatingPolynomial --- x = %d, the value of the polynomial = %d \r\n", x, y); y = NaivePolynomialEvaluation(nArrary, len-1, x); printf("NaivePolynomialEvaluation --- x = %d, the value of the polynomial = %d \r\n", x, y); y = NaivePolynomialEvaluation_Improved(nArrary, len-1, x); printf("NaivePolynomialEvaluation_Improved --- x = %d, the value of the polynomial = %d \r\n", x, y); delete nArrary; nArrary = NULL; }
static void DumpTail( TYPEPTR typ, SYMPTR funcsym, type_modifiers pointer_flags, STRCHUNK *pch ) { TYPEPTR top_typ; TYPEPTR obj; top_typ = typ; for( ;; ) { if( typ->decl_type == TYPE_FUNCTION ) { ChunkSaveChar( pch, '(' ); if( typ == top_typ || typ->u.fn.parms != NULL ) { DumpParmList( typ->u.fn.parms, funcsym, pch); funcsym = NULL; } ChunkSaveChar( pch, ')' ); } typ = Object( typ ); while( typ->decl_type == TYPE_POINTER ) { typ = Object( typ ); } if( typ->decl_type == TYPE_ARRAY ) { ChunkSaveChar( pch, ')' ); if( pointer_flags & FLAG_WAS_ARRAY ) { /* we don't know the dimension anymore. just put out [1] */ ChunkSaveStr( pch, "[1]" ); pointer_flags = 0; } DumpArray( typ, pch) ; for( ;; ) { obj = Object( typ ); if( obj->decl_type != TYPE_ARRAY ) break; typ = obj; } } else { if( typ->decl_type != TYPE_FUNCTION ) break; ChunkSaveChar( pch, ')' ); } } }
// Write fake vmem to file void CMemoryWindow::OnDumpFakeVMEM( wxCommandEvent& event ) { DumpArray(File::GetUserPath(F_FAKEVMEMDUMP_IDX), Memory::m_pFakeVMEM, Memory::FAKEVMEM_SIZE); }
// Write mram to file void CMemoryWindow::OnDumpMemory( wxCommandEvent& event ) { DumpArray(File::GetUserPath(F_RAMDUMP_IDX), Memory::m_pRAM, Memory::REALRAM_SIZE); }
// // By default, user_init is called before the remote hosts are spawned, // so any changes to "non-shared" data items that are performed here get // propagated to the children. // // Note: you CAN NOT create threads here, because the remote hosts have // not been created. Basically, this should contain the sequential // initialization code for the program. // // int main(unsigned argc, char **argv){ char hostname[128]; char *cp; unsigned start_time, start_clicks, end_time, end_clicks; unsigned init_time, init_clicks; double total_time, create_time, compute_time; int i, j, c; extern char *optarg; int rc, status; ParamStruct param[NPROCS]; while ((c = getopt(argc, argv, "s:vb:dDpqB")) != -1) { int done = 0; switch (c) { case 's': if ((size = atoi(optarg)) > MAX_SORT_SIZE) { //Tmk_errexit("Max sort size is %d\n", MAX_SORT_SIZE); char buffer[100]; memset(buffer, '\0', 100); sprintf(buffer, "Max sort size is %d\n", MAX_SORT_SIZE); pthread_errexit(buffer); } done++; break; case 'b': BubbleThresh = atoi(optarg); done++; break; case 'h': usage(); break; case 'B': bubble = 1; break; case 'd': debug++; break; case 'D': dump_array++; break; case 'p': performance = 1; break; case 'q': quiet = 1; break; case 'v': verify = 1; break; } } //Tmk_startup(argc, argv); Sequential = (Tmk_nprocs == 1); showMode(Sequential); InitData(); // // REAL work starts here // // build PThreads' parameters' list for(i= 0; i< NPROCS; i++){ param[i].threadID = i; } // create parallel threads to work on the tasks for(i= 0; i< NPROCS; i++){ pthread_create(&pthreads[i], NULL, thread_work, (void *) (¶m[i])); // code inside thread_work starts parallel work } /* pthread_barrier(); gettimeofday(&start, NULL); Worker(); pthread_barrier(); gettimeofday(&finish, NULL); printf("Elapsed time: %.2f seconds\n", (((finish.tv_sec * 1000000.0) + finish.tv_usec) - ((start.tv_sec * 1000000.0) + start.tv_usec)) / 1000000.0); */ // wait for all threads to finish their work before continue for(i=0; i < NPROCS; i++){ rc = pthread_join(pthreads[i], (void **)&status); if (rc){ printf("ERROR; return code from pthread_join() of thread %d is %d\n", i, rc); exit(-1); } } // all pthreads joined, sequential mode resumed if (dump_array) { DumpArray(); } if (verify) { VerifyArray(); } // // REAL work ends here // ClearData(); return 0; }