int main() { printf("Project Euler - Problem 12:\n" "What is the value of the first triangle number to have over five hundred divisors?\n\n"); // Begin time tracking struct timeval start; gettimeofday(&start, NULL); int index=0, triangle=0, divisors=0; int nprimes = 1500; int primes[nprimes]; primeSieve(primes, nprimes); // Calculate Triangles index = 0; while(index<1000000) { index++; triangle += index; // Skip numbers not divisible by 3 or 5 if ( (triangle % 3 != 0) || (triangle % 5 != 0) ) continue; divisors = findDivisors(triangle, primes, nprimes); if (divisors > 500) break; } printf("Triangle Value: %d, Divisors: %d\n", triangle, divisors); printElapsedTime(start); return 0; }
int main() { printf("Project Euler - Problem 2:\n" "By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.\n\n"); // Begin time tracking struct timeval start; gettimeofday(&start, NULL); const int limit = 4000000; int previousNum = 0, nextNum = 0, currentNum = 1; int total = 0; while (currentNum < limit) { nextNum = previousNum + currentNum; previousNum = currentNum; currentNum = nextNum; if ( currentNum % 2 == 0) total += currentNum; } printf("Sum: %d\n", total); printElapsedTime(start); return 0; }
VOID ILDJIT_startLoop(THREADID tid, ADDRINT ip, ADDRINT loop) { // This is for when there are serial loops within an executing parallel loop. if (simulating_parallel_loop) { thread_state_t* tstate = get_tls(tid); lk_lock(&tstate->lock, tid + 1); tstate->ignore = true; lk_unlock(&tstate->lock); } string loop_string = (string)(char*) loop; // Increment invocation counter for this loop if (invocation_counts.count(loop_string) == 0) { invocation_counts[loop_string] = 0; } else { invocation_counts[loop_string]++; } if (KnobWarmLLC.Value()) { if ((!reached_warm_invocation) && (warm_loop == loop_string) && (invocation_counts[loop_string] == warm_loop_invocation)) { assert(invocation_counts[loop_string] == warm_loop_invocation); cerr << "Called warmLoop() for the warm invocation!:" << loop_string << endl; reached_warm_invocation = true; cerr << "Detected that we need to warm!:" << loop_string << endl; cerr << "FastWarm runtime:"; printElapsedTime(); cerr << "Do late!" << endl; doLateILDJITInstrumentation(); cerr << "Done late!" << endl; } } if ((!reached_start_invocation) && (start_loop == loop_string) && (invocation_counts[loop_string] == start_loop_invocation)) { assert(invocation_counts[loop_string] == start_loop_invocation); cerr << "Called startLoop() for the start invocation!:" << loop_string << endl; reached_start_invocation = true; if (start_loop_iteration == (UINT32)-1) { cerr << "Detected that we need to start the next parallel loop!:" << loop_string << endl; reached_start_iteration = true; } } if ((!reached_end_invocation) && (end_loop == loop_string) && (invocation_counts[loop_string] == end_loop_invocation)) { assert(invocation_counts[loop_string] == end_loop_invocation); cerr << "Called startLoop() for the end invocation!:" << (CHAR*)loop << endl; reached_end_invocation = true; if (end_loop_iteration == (UINT32)-1) { cerr << "Detected that we need to end the next parallel loop!:" << loop_string << endl; reached_end_iteration = true; } } }
int ProgramHandler::runDown(IDEGateway& ideGateway) { shared_ptr<LinkedTokenList> tokenList = nullptr; shared_ptr<LinkedActionList> compiledList = nullptr; try { //=============START-CLOCK============= if (ideGateway.doPrintElapsedTime()) { sttime = clock(); } //=============TOKENIZER============= tokenList = runTokenizer(ideGateway.getCode(), ideGateway.doPrintTokenList()); if (errors()) { return -1; } //=============COMPILER============= compiledList = runCompiler(tokenList, ideGateway.doPrintCompiledList()); if (errors()) { return -1; } //=============VM============= if (!ideGateway.doBuild()) { runVirtualMachine(compiledList); } if (errors()) { return -1; } //=============END-CLOCK============= if (ideGateway.doPrintElapsedTime()) { printElapsedTime(); } } catch (...) { cleanup(tokenList, compiledList); } cleanup(tokenList, compiledList); return 0; }
// Assumes that start iteration calls _always_ happen in sequential order, // in a thread safe manner! Have to take Simon's word on this one for now... // Must be called from within the body of MOLECOOL_beforeWait! VOID ILDJIT_startIteration(THREADID tid) { if (KnobWarmLLC.Value()) { if (!reached_warm_invocation) { assert(!reached_start_invocation); assert(!reached_end_invocation); return; } } if ((!reached_start_invocation) && (!reached_end_invocation)) { return; } assert(loop_state != NULL); loop_state->iterationCount++; // Check if this is the first iteration if ((!reached_start_iteration) && loopMatches(start_loop, start_loop_invocation, start_loop_iteration)) { cerr << "FastForward runtime:"; printElapsedTime(); reached_start_iteration = true; loop_state->simmed_iteration_count = 0; if (KnobWarmLLC.Value()) { assert(reached_warm_invocation); } else { cerr << "Do late!" << endl; doLateILDJITInstrumentation(); cerr << "Done late!" << endl; } cerr << "Starting simulation, TID: " << tid << endl; initializePerThreadLoopState(tid); simulating_parallel_loop = true; StartSimSlice(1); ResumeSimulation(false); } // Check if this is the last iteration if (reached_end_iteration || loopMatches(end_loop, end_loop_invocation, end_loop_iteration)) { assert(reached_start_invocation && reached_end_invocation && reached_start_iteration); shutdownSimulation(); } if (reached_start_iteration) { assert(reached_start_invocation); loop_state->simmed_iteration_count++; } }
/* ========================================================================== */ VOID ILDJIT_startParallelLoop(THREADID tid, ADDRINT ip, ADDRINT loop, ADDRINT rc) { if (reached_start_invocation) { loop_states.push(loop_state_t()); loop_state = &(loop_states.top()); loop_state->simmed_iteration_count = 0; loop_state->current_loop = loop; loop_state->invocationCount = invocation_counts[(string)(char*) loop]; loop_state->iterationCount = -1; CHAR* loop_name = (CHAR*)loop; cerr << "Starting loop: " << loop_name << "[" << invocation_counts[(string)(char*) loop] << "]" << endl; *ss_curr = rc; loop_state->use_ring_cache = (rc > 0); if (disable_wait_signal) { loop_state->use_ring_cache = false; } } // If we didn't get to the start of the phase, return if (!reached_start_iteration) { return; } assert(reached_start_iteration); ignoreSignalZero = false; initializePerThreadLoopState(tid); simulating_parallel_loop = true; if (ExecMode != EXECUTION_MODE_SIMULATE) { if (KnobWarmLLC.Value()) { assert(reached_warm_invocation); } else { cerr << "Do late!" << endl; doLateILDJITInstrumentation(); cerr << "Done late!" << endl; } cerr << "FastForward runtime:"; printElapsedTime(); cerr << "Starting simulation, TID: " << tid << endl; StartSimSlice(1); first_invocation = false; } else { cerr << tid << ": resuming simulation" << endl; } ResumeSimulation(false); }
bool ProgramHandler::errors() { if (!ErrorHandler::getInstance()->getErrors().empty()) { cerr << ErrorHandler::getInstance()->asJson(); if(ideGateway.doPrintElapsedTime()) printElapsedTime(); return true; } return false; }
int main() { printf("Project Euler - Problem 22:\n" "Sort 5000 names and calculate the sum of their name scores.\n\n"); // Begin time tracking struct timeval start; gettimeofday(&start, NULL); char names[6000][maxNameSize];// = {}; int nameIndex = 0; nameFile = fopen ("problem_022.txt", "rt"); // Read in names to array int ch; int charIndex = 0; while((ch = fgetc(nameFile))) { if (ch == EOF) break; if (ch == '"') continue; if (ch == ',') { nameIndex++; charIndex = 0; continue; } names[nameIndex][charIndex++] = ch; } fclose(nameFile); // Sort array qsort(names, nameIndex+1, sizeof(names[0]), compare); // Score names int score = 0; for(int i=0; i <= nameIndex; i++) score += (i + 1) * wordScore(names[i], maxNameSize); printf("Total name score: %d\n", score); printElapsedTime(start); return 0; }
int main() { printf("Project Euler - Problem 15:\n" "Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?\n\n"); // Begin time tracking struct timeval start; gettimeofday(&start, NULL); unsigned long long pascal[100][100] = {}; int n = 0, i = 0; bool debug = false; pascal[0][0]=1; while (i < 40) { i++; for (n=0 ; n<100 ; n++) if (n-1 < 0) pascal[i][n]=pascal[i-1][n]; else pascal[i][n]=pascal[i-1][n]+pascal[i-1][n-1]; // DEBUG - Print row if (debug == true) { printf("%2i: ", i); for (n=0 ; n<100 ; n++) if (pascal[i][n]==0) break; else printf("%6llu ", pascal[i][n]); printf("\n\n"); } } printf("Answer: %llu\n", pascal[40][20]); printElapsedTime(start); return 0; }
int main() { printf("Project Euler - Problem 125:\n" "Find the sum of all numbers less than 10^8 that are both palindromic and can be written as the sum of consecutive squares.\n\n"); // Begin time tracking struct timeval start; gettimeofday(&start, NULL); unsigned long long sum = 0; unsigned long long limit = pow(10, 8); int squarelim = sqrt(limit)+1; bool *history = malloc(limit*sizeof(bool)); bool debug = false; // Find sums for (int start=1; start<squarelim; start++) { unsigned long long n = start * start; for (int end=start+1; end<squarelim; end++) { n += end * end; if (n >= limit) break; if (isPalindromic(n)) { if (history[n] == false) { history[n] = true; sum += n; if (debug == true) printf("%llu\n", n); } } } } printf("Sum: %llu\n", sum); printElapsedTime(start); free(history); return 0; }
int main() { printf("Project Euler - Problem 1:\n" "Find the sum of all the multiples of 3 or 5 below 1000.\n\n"); // Begin time tracking struct timeval start; gettimeofday(&start, NULL); int total = 0; for ( int number=0 ; number<1000 ; number++ ) if ( number % 3 == 0 || number % 5 == 0 ) total += number; printf("Sum: %d\n", total); printElapsedTime(start); return 0; }
int main() { printf("Project Euler - Problem 25:\n" "What is the index of the first term in the Fibonacci sequence to contain 1000 digits?\n\n"); // Begin time tracking struct timeval start; gettimeofday(&start, NULL); int index = 1; short a[1000] = {0}; short b[1000] = {0}; short c[1000] = {0}; int l = sizeof(a)/sizeof(short); bool debug = false; a[0] = 1; while (a[l-1] == 0) { index++; copyArray(c, a, l); addArray(a, b, l); copyArray(b, c, l); if (debug == true) { printf("%d ", index); printArray(a, l); } } printf("Total: %d\n", index); printElapsedTime(start); return 0; }
int main(int argc, char** argv) { char c; unsigned int i, j, k; MMPool *mmPool; dictionary *programInput, *ini; char argumentText[11] = "argument:0"; double startTime; double elapsedTime = 0, totalElapsedTime = 0; BWT *bwt; HSP *hsp; unsigned char charMap[256]; unsigned char *convertedKey; unsigned int *packedKey; unsigned int found; unsigned int numberOfPattern, numberOfPatternFound; unsigned int saIndexLeft, saIndexRight; SaIndexGroupNew *saIndexGroup; SaIndexList *tempSaIndex1, *tempSaIndex2; unsigned int numberOfSaIndexGroup; HitList *hitList; unsigned int textPositionMatched, textPositionRetrieved; unsigned long long totalTextPositionMatched, totalTextPositionRetrieved; BWTSaRetrievalStatistics BWTSaRetrievalStatistics; FILE *logFile; init(textPositionRetrieved); // to avoid compiler warning only init(textPositionMatched); // to avoid compiler warning only programInput = ParseInput(argc, argv); ini = ParseIniFile(); ProcessIni(); ValidateIni(); PrintIni(); if (Confirmation == TRUE) { printf("BWT Search. Press Y to go or N to cancel. "); c = (char)getchar(); while (c != 'y' && c != 'Y' && c != 'n' && c!= 'N') { c = (char)getchar(); } if (c == 'n' || c == 'N') { exit(0); } } startTime = setStartTime(); MMMasterInitialize(1, 0, FALSE, NULL); mmPool = MMPoolCreate(PoolSize); // Load Database printf("Loading Database.."); fflush(stdout); bwt = BWTLoad(mmPool, BWTCodeFileName, BWTOccValueFileName, SaValueFileName, NULL, SaIndexFileName, NULL); HSPFillCharMap(charMap); hsp = HSPLoad(mmPool, PackedDNAFileName, AnnotationFileName, AmbiguityFileName, MAX_SEARCH_PATTERN_LENGTH / CHAR_PER_WORD); if (bwt->textLength != hsp->dnaLength) { fprintf(stderr, "BWT-BLAST: Database length inconsistent!\n"); exit(1); } if (LogFileName[0] != '\0') { logFile = fopen64(LogFileName, "w"); if (logFile == NULL) { fprintf(stderr, "Cannot open log file!\n"); exit(1); } } else { logFile = NULL; } packedKey = MMPoolDispatch(mmPool, WordPackedLengthFromText(MAX_SEARCH_PATTERN_LENGTH, BIT_PER_CHAR)); convertedKey = MMPoolDispatch(mmPool, MAX_SEARCH_PATTERN_LENGTH); saIndexGroup = MMUnitAllocate(MaxNumberOfHitGroups * sizeof(SaIndexGroup)); hitList = MMUnitAllocate(MaxNumberOfTextPosition * sizeof(HitList)); tempSaIndex1 = MMUnitAllocate(MaxNumberOfTextPosition * sizeof(SaIndexList)); tempSaIndex2 = MMUnitAllocate(MaxNumberOfTextPosition * sizeof(SaIndexList)); elapsedTime = getElapsedTime(startTime) - totalElapsedTime; printf("Elapsed time = "); printElapsedTime(stdout, FALSE, FALSE, TRUE, 4, elapsedTime); totalElapsedTime += elapsedTime; printf("\n"); // Process search pattern files for (i=1; i<=NumberOfSearchPatternFile; i++) { argumentText[9] = '0' + (char)(i + 2); iniparser_copystring(programInput, argumentText, PatternFileName, PatternFileName, MAX_FILENAME_LEN); printf("Loading search pattern : %s\n", PatternFileName); numberOfPattern = ProcessSearchPattern(); printf("Finished loading search pattern.\n"); elapsedTime = getElapsedTime(startTime) - totalElapsedTime; printf("Elapsed time = "); printElapsedTime(stdout, FALSE, FALSE, TRUE, 4, elapsedTime); totalElapsedTime += elapsedTime; printf("\n"); if (LogFileName[0] != '\0') { fprintf(logFile, "Searching for pattern : %s\n", PatternFileName); } if (SABinarySearch == TRUE) { printf("Start forward search with SA index.\n"); if (LogFileName[0] != '\0') { fprintf(logFile, "Forward search with SA index.\n"); } numberOfPatternFound = 0; totalTextPositionMatched = 0; totalTextPositionRetrieved = 0; BWTInitializeSaRetrievalStatistics(&BWTSaRetrievalStatistics); for (j=0; j<numberOfPattern; j++) { //ConvertTextToWordPacked(searchPattern + searchPatternPosition[j], packedKey, charMap, ALPHABET_SIZE, // searchPatternPosition[j+1] - searchPatternPosition[j]); //found = BWTForwardSearchSaIndex(packedKey, searchPatternPosition[j+1] - searchPatternPosition[j], // bwt, hsp->packedDNA, &saIndexLeft, &saIndexRight); ConvertTextToCode(searchPattern + searchPatternPosition[j], convertedKey, charMap, searchPatternPosition[j+1] - searchPatternPosition[j]); found = BWTSaBinarySearch(convertedKey, searchPatternPosition[j+1] - searchPatternPosition[j], bwt, hsp->packedDNA, &saIndexLeft, &saIndexRight, packedKey); if (found) { numberOfPatternFound++; textPositionMatched = saIndexRight - saIndexLeft + 1; totalTextPositionMatched += textPositionMatched; if (FindTextPosition) { saIndexGroup->startSaIndex = saIndexLeft; if (textPositionMatched <= MaxNumberOfTextPosition) { saIndexGroup->numOfMatch = textPositionMatched; } else { saIndexGroup->numOfMatch = MaxNumberOfTextPosition; printf("Max no of text positions reached! Only %u out of %u text positions retrieved.\n", MaxNumberOfTextPosition, textPositionMatched); } saIndexGroup->posQuery = 0; saIndexGroup->info = 0; textPositionRetrieved = BWTTextPosition(bwt, saIndexGroup, 1, hitList, tempSaIndex1, tempSaIndex2, &BWTSaRetrievalStatistics, FALSE); totalTextPositionRetrieved += textPositionRetrieved; } } if (LogFileName[0] != '\0') { if (found) { fprintf(logFile, "Pattern number %u found. SA Index from %u to %u. ", j + 1, saIndexLeft, saIndexRight); if (FindTextPosition) { fprintf(logFile, "%u matches of %u located. ", textPositionRetrieved, textPositionMatched); for (k=0; k<textPositionRetrieved; k++) { fprintf(logFile, "%u ", hitList[k].posText); } } } else { fprintf(logFile, "Pattern number %u not found.", j + 1); } fprintf(logFile, "\n"); } } printf("Finished forward search with SA index.\n"); printf("%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { printf("Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } elapsedTime = getElapsedTime(startTime) - totalElapsedTime; printf("Elapsed time = "); printElapsedTime(stdout, FALSE, FALSE, TRUE, 4, elapsedTime); totalElapsedTime += elapsedTime; printf("\n"); if (LogFileName[0] != '\0') { fprintf(logFile, "Finished forward search with SA index.\n"); fprintf(logFile, "%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { fprintf(logFile, "Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } fprintf(logFile, "Elapsed time = "); printElapsedTime(logFile, FALSE, FALSE, TRUE, 4, elapsedTime); fprintf(logFile, "\n"); } } if (BackwardSearch == TRUE) { printf("Start backward search.\n"); if (LogFileName[0] != '\0') { fprintf(logFile, "Backward search.\n"); } numberOfPatternFound = 0; totalTextPositionMatched = 0; totalTextPositionRetrieved = 0; BWTInitializeSaRetrievalStatistics(&BWTSaRetrievalStatistics); for (j=0; j<numberOfPattern; j++) { ConvertTextToCode(searchPattern + searchPatternPosition[j], convertedKey, charMap, searchPatternPosition[j+1] - searchPatternPosition[j]); found = BWTBackwardSearch(convertedKey, searchPatternPosition[j+1] - searchPatternPosition[j], bwt, &saIndexLeft, &saIndexRight); if (found) { numberOfPatternFound++; textPositionMatched = saIndexRight - saIndexLeft + 1; totalTextPositionMatched += textPositionMatched; if (FindTextPosition) { saIndexGroup->startSaIndex = saIndexLeft; if (textPositionMatched <= MaxNumberOfTextPosition) { saIndexGroup->numOfMatch = textPositionMatched; } else { saIndexGroup->numOfMatch = MaxNumberOfTextPosition; printf("Max no of text positions reached! Only %u out of %u text positions retrieved.\n", MaxNumberOfTextPosition, textPositionMatched); } saIndexGroup->posQuery = 0; saIndexGroup->info = 0; textPositionRetrieved = BWTTextPosition(bwt, saIndexGroup, 1, hitList, tempSaIndex1, tempSaIndex2, &BWTSaRetrievalStatistics, FALSE); totalTextPositionRetrieved += textPositionRetrieved; } } if (LogFileName[0] != '\0') { if (found) { fprintf(logFile, "Pattern number %u found. SA Index from %u to %u. Total %u occurrences ", j + 1, saIndexLeft, saIndexRight, saIndexRight - saIndexLeft + 1); if (FindTextPosition) { fprintf(logFile, "%u matches of %u located. ", textPositionRetrieved, textPositionMatched); for (k=0; k<textPositionRetrieved; k++) { fprintf(logFile, "%u ", hitList[k].posText); } } } else { fprintf(logFile, "Pattern number %u not found.", j + 1); } fprintf(logFile, "\n"); } } printf("Finished backward search.\n"); printf("%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { printf("Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } elapsedTime = getElapsedTime(startTime) - totalElapsedTime; printf("Elapsed time = "); printElapsedTime(stdout, FALSE, FALSE, TRUE, 4, elapsedTime); totalElapsedTime += elapsedTime; printf("\n"); if (LogFileName[0] != '\0') { fprintf(logFile, "Finished backward search.\n"); fprintf(logFile, "%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { fprintf(logFile, "Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } fprintf(logFile, "Elapsed time = "); printElapsedTime(logFile, FALSE, FALSE, TRUE, 4, elapsedTime); fprintf(logFile, "\n"); } } if (BackwardSearchCheck == TRUE) { printf("Start backward search with text.\n"); if (LogFileName[0] != '\0') { fprintf(logFile, "Backward search with text.\n"); } numberOfPatternFound = 0; totalTextPositionMatched = 0; totalTextPositionRetrieved = 0; BWTInitializeSaRetrievalStatistics(&BWTSaRetrievalStatistics); for (j=0; j<numberOfPattern; j++) { ConvertTextToCode(searchPattern + searchPatternPosition[j], convertedKey, charMap, searchPatternPosition[j+1] - searchPatternPosition[j]); ConvertTextToWordPacked(searchPattern + searchPatternPosition[j], packedKey, charMap, ALPHABET_SIZE, searchPatternPosition[j+1] - searchPatternPosition[j]); found = BWTBackwardSearchCheckWithText(convertedKey, packedKey, searchPatternPosition[j+1] - searchPatternPosition[j], bwt, hsp->packedDNA, TextCheckCostFactor, MaxNumberOfTextPosition, hitList, &saIndexLeft, &saIndexRight); if (found) { numberOfPatternFound++; textPositionMatched = saIndexRight - saIndexLeft + 1; totalTextPositionMatched += textPositionMatched; // Find text position if text check not used if (FindTextPosition && saIndexLeft != 0) { saIndexGroup->startSaIndex = saIndexLeft; if (textPositionMatched <= MaxNumberOfTextPosition) { saIndexGroup->numOfMatch = textPositionMatched; } else { saIndexGroup->numOfMatch = MaxNumberOfTextPosition; printf("Max no of text positions reached! Only %u out of %u text positions retrieved.\n", MaxNumberOfTextPosition, textPositionMatched); } saIndexGroup->posQuery = 0; saIndexGroup->info = 0; textPositionRetrieved = BWTTextPosition(bwt, saIndexGroup, 1, hitList, tempSaIndex1, tempSaIndex2, &BWTSaRetrievalStatistics, FALSE); totalTextPositionRetrieved += textPositionRetrieved; } else { textPositionRetrieved = textPositionMatched; totalTextPositionRetrieved += textPositionRetrieved; } } if (LogFileName[0] != '\0') { if (found) { fprintf(logFile, "Pattern number %u found. ", j + 1); if (FindTextPosition) { fprintf(logFile, "%u matches of %u located. ", textPositionRetrieved, textPositionMatched); for (k=0; k<textPositionRetrieved; k++) { fprintf(logFile, "%u ", hitList[k].posText); } } } else { fprintf(logFile, "Pattern number %u not found.", j + 1); } fprintf(logFile, "\n"); } } printf("Finished backward search with text.\n"); printf("%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { printf("Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } elapsedTime = getElapsedTime(startTime) - totalElapsedTime; printf("Elapsed time = "); printElapsedTime(stdout, FALSE, FALSE, TRUE, 4, elapsedTime); totalElapsedTime += elapsedTime; printf("\n"); if (LogFileName[0] != '\0') { fprintf(logFile, "Finished backward search with text.\n"); fprintf(logFile, "%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { fprintf(logFile, "Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } fprintf(logFile, "Elapsed time = "); printElapsedTime(logFile, FALSE, FALSE, TRUE, 4, elapsedTime); fprintf(logFile, "\n"); } } if (HammingDistSearch == TRUE) { printf("Start hamming distance %u approximate match.\n", MaxErrorAllowed); if (LogFileName[0] != '\0') { fprintf(logFile, "Hamming distance %u approximate match.\n", MaxErrorAllowed); } numberOfPatternFound = 0; totalTextPositionMatched = 0; totalTextPositionRetrieved = 0; BWTInitializeSaRetrievalStatistics(&BWTSaRetrievalStatistics); for (j=0; j<numberOfPattern; j++) { ConvertTextToCode(searchPattern + searchPatternPosition[j], convertedKey, charMap, searchPatternPosition[j+1] - searchPatternPosition[j]); numberOfSaIndexGroup = BWTHammingDistMatchOld(convertedKey, searchPatternPosition[j+1] - searchPatternPosition[j], bwt, MaxErrorAllowed, saIndexGroup, MaxNumberOfHitGroups, 0, 0); if (numberOfSaIndexGroup) { numberOfPatternFound++; textPositionMatched = 0; for (k=0; k<numberOfSaIndexGroup; k++) { textPositionMatched += saIndexGroup[k].numOfMatch; } if (textPositionMatched > MaxNumberOfTextPosition) { textPositionMatched = 0; for (k=0; k<numberOfSaIndexGroup && textPositionMatched < MaxNumberOfTextPosition; k++) { textPositionMatched += saIndexGroup[k].numOfMatch; } numberOfSaIndexGroup = k - 1; saIndexGroup[numberOfSaIndexGroup].numOfMatch -= textPositionMatched - MaxNumberOfTextPosition; for (; k<numberOfSaIndexGroup; k++) { textPositionMatched += saIndexGroup[k].numOfMatch; } printf("Max no of text positions reached! Only %u out of %u text positions retrieved.\n", MaxNumberOfTextPosition, textPositionMatched); } totalTextPositionMatched += textPositionMatched; if (FindTextPosition) { textPositionRetrieved = BWTTextPosition(bwt, saIndexGroup, numberOfSaIndexGroup, hitList, tempSaIndex1, tempSaIndex2, &BWTSaRetrievalStatistics, FALSE); totalTextPositionRetrieved += textPositionRetrieved; } } if (LogFileName[0] != '\0') { if (numberOfSaIndexGroup) { fprintf(logFile, "Pattern number %u found. %u matches", j + 1, textPositionMatched); if (FindTextPosition) { fprintf(logFile, "%u matches of %u located. ", textPositionRetrieved, textPositionMatched); for (k=0; k<textPositionRetrieved; k++) { fprintf(logFile, "%u ", hitList[k].posText); } } } else { fprintf(logFile, "Pattern number %u not found.", j + 1); } fprintf(logFile, "\n"); } } printf("Finished hamming distance search.\n"); printf("%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { printf("Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } elapsedTime = getElapsedTime(startTime) - totalElapsedTime; printf("Elapsed time = "); printElapsedTime(stdout, FALSE, FALSE, TRUE, 4, elapsedTime); totalElapsedTime += elapsedTime; printf("\n"); if (LogFileName[0] != '\0') { fprintf(logFile, "Finished hamming distance search.\n"); fprintf(logFile, "%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { fprintf(logFile, "Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } fprintf(logFile, "Elapsed time = "); printElapsedTime(logFile, FALSE, FALSE, TRUE, 4, elapsedTime); fprintf(logFile, "\n"); } } if (EditDistSearch == TRUE) { printf("Start edit distance %u approximate match.\n", MaxErrorAllowed); if (LogFileName[0] != '\0') { fprintf(logFile, "Edit distance %u approximate match.\n", MaxErrorAllowed); } numberOfPatternFound = 0; totalTextPositionMatched = 0; totalTextPositionRetrieved = 0; BWTInitializeSaRetrievalStatistics(&BWTSaRetrievalStatistics); for (j=0; j<numberOfPattern; j++) { ConvertTextToCode(searchPattern + searchPatternPosition[j], convertedKey, charMap, searchPatternPosition[j+1] - searchPatternPosition[j]); numberOfSaIndexGroup = BWTEditDistMatchOld(convertedKey, searchPatternPosition[j+1] - searchPatternPosition[j], bwt, MaxErrorAllowed, (SaIndexGroupWithLengthError*)saIndexGroup, MaxNumberOfHitGroups); if (numberOfSaIndexGroup > MaxNumberOfHitGroups) { fprintf(stderr, "numberOfSaIndexGroup > MaxNumberOfHitGroups!\n"); } if (numberOfSaIndexGroup) { numberOfPatternFound++; textPositionMatched = 0; for (k=0; k<numberOfSaIndexGroup; k++) { textPositionMatched += saIndexGroup[k].numOfMatch; } if (textPositionMatched > MaxNumberOfTextPosition) { textPositionMatched = 0; for (k=0; k<numberOfSaIndexGroup && textPositionMatched < MaxNumberOfTextPosition; k++) { textPositionMatched += saIndexGroup[k].numOfMatch; } numberOfSaIndexGroup = k - 1; saIndexGroup[numberOfSaIndexGroup].numOfMatch -= textPositionMatched - MaxNumberOfTextPosition; for (; k<numberOfSaIndexGroup; k++) { textPositionMatched += saIndexGroup[k].numOfMatch; } printf("Max no of text positions reached! Only %u out of %u text positions retrieved.\n", MaxNumberOfTextPosition, textPositionMatched); } totalTextPositionMatched += textPositionMatched; if (FindTextPosition) { textPositionRetrieved = BWTTextPosition(bwt, saIndexGroup, numberOfSaIndexGroup, hitList, tempSaIndex1, tempSaIndex2, &BWTSaRetrievalStatistics, FALSE); totalTextPositionRetrieved += textPositionRetrieved; } } if (LogFileName[0] != '\0') { if (numberOfSaIndexGroup) { fprintf(logFile, "Pattern number %u found. %u matches. ", j + 1, textPositionMatched); if (FindTextPosition) { fprintf(logFile, "%u matches of %u located. ", textPositionRetrieved, textPositionMatched); for (k=0; k<textPositionRetrieved; k++) { fprintf(logFile, "%u ", hitList[k].posText); } } } else { fprintf(logFile, "Pattern number %u not found.", j + 1); } fprintf(logFile, "\n"); } } printf("Finished edit distance search.\n"); printf("%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { printf("Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } elapsedTime = getElapsedTime(startTime) - totalElapsedTime; printf("Elapsed time = "); printElapsedTime(stdout, FALSE, FALSE, TRUE, 4, elapsedTime); totalElapsedTime += elapsedTime; printf("\n"); if (LogFileName[0] != '\0') { fprintf(logFile, "Finished edit distance search.\n"); fprintf(logFile, "%u patterns out of %u found. %llu of %llu matches located.\n", numberOfPatternFound, numberOfPattern, totalTextPositionRetrieved, totalTextPositionMatched); if (FindTextPosition) { fprintf(logFile, "Hits: BWT/Cached/Diag/Dup : %u/%u/%u/%u\n", BWTSaRetrievalStatistics.bwtSaRetrieved, BWTSaRetrievalStatistics.cachedSaRetrieved, BWTSaRetrievalStatistics.saDiagonalLinked, BWTSaRetrievalStatistics.saDuplicated); } fprintf(logFile, "Elapsed time = "); printElapsedTime(logFile, FALSE, FALSE, TRUE, 4, elapsedTime); fprintf(logFile, "\n"); } } } MMPoolReturn(mmPool, packedKey, WordPackedLengthFromText(MAX_SEARCH_PATTERN_LENGTH, BIT_PER_CHAR)); MMPoolReturn(mmPool, convertedKey, MAX_SEARCH_PATTERN_LENGTH); HSPFree(mmPool, hsp, MAX_SEARCH_PATTERN_LENGTH / CHAR_PER_WORD); BWTFree(mmPool, bwt); if (searchPattern != NULL) { MMUnitFree(searchPattern, searchPatternAllocated); } if (searchPatternPosition != NULL) { MMUnitFree(searchPatternPosition, searchPatternPositionAllocated); } MMUnitFree(saIndexGroup, MaxNumberOfHitGroups * sizeof(unsigned int)); MMUnitFree(hitList, MaxNumberOfTextPosition * sizeof(unsigned int)); MMPoolFree(mmPool); iniparser_freedict(programInput); iniparser_freedict(ini); return 0; }
int main(int argc, char** argv) { unsigned int* __restrict address; unsigned int* __restrict memory; unsigned int i, j; unsigned int t=0; unsigned int numberOfMemoryLocation; dictionary *programInput; double startTime; double elapsedTime = 0, totalElapsedTime = 0; double initializationTime, experimentTime; programInput = ParseInput(argc, argv); ValidateParameters(); // Initialize memory manager MMMasterInitialize(0, 0, FALSE, NULL); numberOfMemoryLocation = MemorySize / sizeof(int); // Allocate memory address = MMUnitAllocate((NumberOfAccess + 8) * sizeof(unsigned int)); memory = MMUnitAllocate((numberOfMemoryLocation + 32) * sizeof(unsigned int)); // Set random seed r250_init(getRandomSeed()); // Set start time startTime = setStartTime(); printf("Initialize memory pointers with random values.."); for (i=0; i<numberOfMemoryLocation + 32; i++) { memory[i] = r250(); } // Initialize address and memory for (i=0; i<NumberOfAccess + 8; i++) { address[i] = (r250() % numberOfMemoryLocation) / 4 * 4; } printf("finished.\n"); elapsedTime = getElapsedTime(startTime) - totalElapsedTime; totalElapsedTime += elapsedTime; initializationTime = elapsedTime; // Test memory speed for read if (ReadWrite[0] == 'R' || ReadWrite[0] == 'r') { for (i=0; i<NumberOfIteration; i++) { for (j=0; j<NumberOfAccess; j++) { t += memory[address[j]]; } } } // Test memory speed for write if (ReadWrite[0] == 'W' || ReadWrite[0] == 'w') { for (i=0; i<NumberOfIteration; i++) { for (j=0; j<NumberOfAccess; j++) { memory[address[j]] += address[j]; } } } elapsedTime = getElapsedTime(startTime) - totalElapsedTime; totalElapsedTime += elapsedTime; experimentTime = elapsedTime; // So that compiler does not remove code for variables t and r if (t==0) { printf("\n"); } printf("Experiment completed.\n"); printf("Initialization time = "); printElapsedTime(stdout, FALSE, FALSE, TRUE, 2, initializationTime); printf("Experiment time = "); printElapsedTime(stdout, FALSE, FALSE, TRUE, 2, experimentTime); MMUnitFree(address, (NumberOfAccess + 8) * sizeof(unsigned int)); MMUnitFree(memory, (numberOfMemoryLocation + 32) * sizeof(unsigned int)); iniparser_freedict(programInput); return 0; }