void Letterbox::writeFile() { outputResults(); setModified(false); statusBar()->showMessage(tr("Saved results to file.")); }
bool Sobel::runHalideGPU(Image input, Image output, const Params& params) { #if ENABLE_HALIDE // Create halide buffers buffer_t inputBuffer = createHalideBuffer(input); buffer_t outputBuffer = createHalideBuffer(output); reportStatus("Running Halide GPU filter"); // Warm-up run inputBuffer.host_dirty = true; halide_sobel_gpu(&inputBuffer, &outputBuffer); halide_dev_sync(NULL); // Timed runs startTiming(); for (int i = 0; i < params.iterations; i++) { halide_sobel_gpu(&inputBuffer, &outputBuffer); } halide_dev_sync(NULL); stopTiming(); halide_copy_to_host(NULL, &outputBuffer); halide_release(NULL); return outputResults(input, output, params); #else reportStatus("Halide not enabled during build."); return false; #endif }
bool Bilateral::runHalideCPU(Image input, Image output, const Params& params) { #if ENABLE_HALIDE // Create halide buffers buffer_t inputBuffer = createHalideBuffer(input); buffer_t outputBuffer = createHalideBuffer(output); reportStatus("Running Halide CPU filter"); // Warm-up run halide_bilateral_cpu(&inputBuffer, &outputBuffer); // Timed runs startTiming(); for (int i = 0; i < params.iterations; i++) { halide_bilateral_cpu(&inputBuffer, &outputBuffer); } stopTiming(); halide_release(NULL); return outputResults(input, output, params); #else reportStatus("Halide not enabled during build."); return false; #endif }
/* Create a steady state solver, solve the constraints. */ void solveSteadyStates(const string & path_to_model, const Model & model) { // Create the output file and label columns ofstream output_file = initFile(path_to_model, model.name); outputLegend(model.species, output_file); // Create the solver together with the constraints SpaceSolver<SteadySpace> solver(new SteadySpace(model.species.size(), model.max_value)); for (const size_t i : cscope(model.species)) solver->boundSpecie(i, model.species[i].max_val); solver->applyModel(model); // Output the results outputResults(output_file, solver); }
int main(int argc,char* argv[]){ time_t timer_start,timer_end; setGlobalParameters(argc,argv); registerProNdAlg(); setAddtParameters(); time(&timer_start); run(); time(&timer_end); cout<<"Time used: "<<difftime(timer_end,timer_start)<<" seconds"<<endl; outputResults(); return 0; }
int main() { srand(time(NULL)); //Declare Variables FILE *fp; char *line = NULL; size_t len = 0; ssize_t read; char filename[99]; char *numLine; char *userInput = (char*) malloc(100); char *valueLine; char buffer[100]; int n = 0; clock_t start, end; float elapsed_time; //For random generation int maxValue = 10000; int maxNumOfCoins = 5; int maxCoinValue = 50; //regular variables int v[maxNumOfCoins]; int c[maxNumOfCoins]; int a, m; //start value //prep arrays for(int x = 0; x < maxNumOfCoins; x++) { c[x] = 0; v[x] = 0; } //ask user for file or random generator printf("What do you want to run:\n"); printf("1) Load from File\n"); printf("2) Random Generator\n"); //Get user input scanf ("%[^\n]%*c", userInput); if (strcmp(userInput,"1") == 0) { //Run LoadFile } else if (strcmp(userInput,"2") == 0) { //Run Random Generator randomNum(&v, &a, maxNumOfCoins, maxCoinValue, maxValue); } //start = clock(); runGreedyAlgorithm(v, a, &c, &m, maxNumOfCoins); //end = clock(); //elapsed_time = (float)(end - start) / (1.0*CLOCKS_PER_SEC); printf("%d\n", a); //fprintf(fp,"%d %s %f %s",a, "\t", elapsed_time ,"\n"); printf("\nmaxNumOfCoins=%d\n", maxNumOfCoins); printf("maxCoinValue=%d\n", maxCoinValue); printf("maxValue=%d\n", maxValue); outputResults(v, maxNumOfCoins, a, 'V'); printf("Elapsed time: %f seconds\n", elapsed_time); printf("\nResults:\n"); outputResults(c, maxNumOfCoins, m, 'C'); // printf("Enter filename: "); // fgets(filename, 99, stdin); // char *p = strchr(filename, '\n'); // p will point to the newline in filename // if(p) *p = 0; // if p is not null, terminate filename at p // fp = fopen(filename, "r"); // if(!fp) // perror("File not found"); // else // { // printf("opening file: %s...\n", filename); // while ((read = getline(&line, &len, fp)) != -1) { // if (n == 1) // { // numLine = (char *) realloc (numLine, strlen(line)+1); // strncpy(numLine, line, strlen(line)); // *p = strchr(numLine, '\n'); // p will point to the newline in filename // if(p) *p = 0; // if p is not null, terminate filename at p // } // if (n == 2) // { // printf("n=2\n"); // printf("strlen=%d\n",strlen(line)); // valueLine = (char *) realloc (valueLine, strlen(line)+1); //strncpy(valueLine, line, strlen(line)); // } // n++; // } // } // printf("numLine=%s\n", numLine); // printf("valueLine=%s\n", valueLine); /* //parse numbers from lines into array for (int i = 0; i < line[0].noOfLines; i++) { line[i].noOfnums = 0; //printf("Words[%d]=%s\n", i, line[i].words); //Test Only char *pt; pt = strtok(line[i].words,","); while (pt != NULL) { if (pt[0] == '[') pt[0] = ' '; line[i].num[line[i].noOfnums] = atoi(pt); pt = strtok (NULL, ","); line[i].noOfnums++; } } */ //close file //fclose(fp); //Exit printf("\nHave a nice day.\n"); return 0; }
// std::cout << currentRead.BPLeft << " " << BoxSize << " " << NumBoxes << " " << TempBoxIndex << std::endl; int SearchVariant::Search(BDData & g_bdData, ControlState& currentState, const unsigned NumBoxes, const SearchWindow& window) { std::vector<unsigned> Vars[NumBoxes]; unsigned TempBoxIndex; unsigned int farEndExists = 0; unsigned int readsUsed = 0; unsigned int bpSum = 0; for (unsigned ReadIndex = 0; ReadIndex < currentState.Reads_SR.size(); ReadIndex++) { SPLIT_READ& currentRead = currentState.Reads_SR[ReadIndex]; if (currentRead.Used) { readsUsed++; } if (!currentRead.UP_Far.empty()) { farEndExists++; bpSum += currentRead.UP_Far[ currentRead.UP_Far.size()-1 ].AbsLoc; } if (bpSum>1000000000) { bpSum -= 1000000000; } } *logStream << "Reads already used: " << readsUsed << std::endl; *logStream << "Far ends already mapped " << farEndExists << std::endl; *logStream << "Checksum of far ends: " << bpSum << std::endl; //UserDefinedSettings* userSettings = UserDefinedSettings::Instance(); LOG_INFO(*logStream << "Searching " << typeOfVariant << " ... " << std::endl); const std::string ChrSeq = window.getChromosome()->getSeq(); for (unsigned ReadIndex = 0; ReadIndex < currentState.Reads_SR.size(); ReadIndex++) { SPLIT_READ& currentRead = currentState.Reads_SR[ReadIndex]; //std::cout << ReadIndex << std::endl; //std::cout << currentRead << std::endl; if (currentRead.FragName != currentRead.FarFragName) { //std::cout << "inter-chromosome split-read" << std::endl; continue; } if (currentRead.Used || currentRead.UP_Far.empty()) { continue; } if (currentRead.MatchedD == Plus) { for (short MAX_SNP_ERROR_index = 0; MAX_SNP_ERROR_index <= currentRead.getMAX_SNP_ERROR(); MAX_SNP_ERROR_index++) { if (currentRead.Used) { break; } for (unsigned int CloseIndex = 0; CloseIndex < currentRead.UP_Close.size(); CloseIndex++) { if (currentRead.Used) { break; } if (currentRead.UP_Close[CloseIndex].Mismatches > MAX_SNP_ERROR_index) { continue; } for (int FarIndex = currentRead.UP_Far.size() - 1; FarIndex >= 0; FarIndex--) { if (currentRead.Used) { break; } if (currentRead.UP_Far[FarIndex]. Mismatches > MAX_SNP_ERROR_index) { continue; } if (currentRead.UP_Far[FarIndex]. Mismatches + currentRead.UP_Close[CloseIndex]. Mismatches > MAX_SNP_ERROR_index) { continue; } if (currentRead.UP_Far[FarIndex]. Direction == Minus) { if (decisionBranch1(currentRead, CloseIndex, FarIndex)) { currentRead.Left = currentRead. UP_Close[CloseIndex].AbsLoc - currentRead. UP_Close[CloseIndex].LengthStr + 1; currentRead.Right = currentRead.UP_Far[FarIndex]. AbsLoc + currentRead.UP_Far[FarIndex]. LengthStr - 1; currentRead.BP = currentRead. UP_Close[CloseIndex].LengthStr - 1; currentRead.IndelSize = calculateIndelSize(currentRead); currentRead.NT_str = getInsertedStr1(currentRead); currentRead.BPLeft = currentRead. UP_Close[CloseIndex].AbsLoc - g_SpacerBeforeAfter; currentRead.BPRight = currentRead.UP_Far[FarIndex]. AbsLoc - g_SpacerBeforeAfter; unsigned RealBP_left= currentRead.BPLeft; unsigned RealBP_right = currentRead.BPRight;//, DIFF; if (ChrSeq.size() < RealBP_left || ChrSeq.size() < RealBP_right) { currentRead.Used = true; break; } if (currentRead.NT_str.size()) { //std::cout << "ns i currentRead.NT_str.size()" << std::endl; //std::cout << currentRead.NT_str << " " << RealBP_left << " " << RealBP_right << std::endl; GetRealStart4Insertion(ChrSeq, currentRead.NT_str, RealBP_left, RealBP_right); //std::cout << "ne i currentRead.NT_str.size()" << std::endl; } else { //std::cout << "no_ns d currentRead.NT_str.size()" << std::endl; //std::cout << RealBP_left << " " << RealBP_right << std::endl; GetRealStart4Deletion(ChrSeq, RealBP_left, RealBP_right); //std::cout << "no_ns d currentRead.NT_str.size()" << std::endl; } short DIFF = currentRead.BPLeft - RealBP_left; DIFF = !((currentRead.BP - 1)<DIFF)?DIFF:(currentRead.BP - 1); // min(DIFF, currentRead.BP - 1); if (DIFF > 0) { //std::cout << "DIFF " << DIFF << std::endl; currentRead.BP -= DIFF; currentRead.BPLeft -= DIFF; currentRead.BPRight -= DIFF; } if (readTransgressesBinBoundaries( currentRead, window.getEnd())) { saveReadForNextCycle( currentRead, currentState.FutureReads_SR); } else { if (readInSpecifiedRegion( currentRead, userSettings->getRegion())) { TempBoxIndex = (int) (currentRead. BPLeft) / BoxSize; //std::cout << currentRead.BPLeft << " " << BoxSize << " " << NumBoxes << " " << TempBoxIndex << std::endl; if (TempBoxIndex < NumBoxes) { Vars[TempBoxIndex].push_back(ReadIndex); currentRead.Used = true; Count_Var_Plus++; Count_Var++; } } } } } } } } } else if (currentRead.MatchedD == Minus) { for (short MAX_SNP_ERROR_index = 0; MAX_SNP_ERROR_index <= currentRead.getMAX_SNP_ERROR(); MAX_SNP_ERROR_index++) { if (currentRead.Used) { break; } for (int CloseIndex = currentRead.UP_Close.size() - 1; CloseIndex >= 0; CloseIndex--) { if (currentRead.Used) { break; } if (currentRead.UP_Close[CloseIndex]. Mismatches > MAX_SNP_ERROR_index) { continue; } for (int FarIndex = currentRead.UP_Far.size() - 1; FarIndex >= 0; FarIndex--) { if (currentRead.Used) { break; } if (currentRead.UP_Far[FarIndex]. Mismatches > MAX_SNP_ERROR_index) { continue; } if (currentRead.UP_Far[FarIndex]. Mismatches + currentRead.UP_Close[CloseIndex]. Mismatches > MAX_SNP_ERROR_index) { continue; } if (currentRead.UP_Far[FarIndex]. Direction == Plus) { if (decisionBranch2(currentRead, CloseIndex, FarIndex)) { currentRead.Left = currentRead.UP_Far[FarIndex]. AbsLoc - currentRead.UP_Far[FarIndex]. LengthStr + 1; currentRead.Right = currentRead. UP_Close[CloseIndex].AbsLoc + currentRead. UP_Close[CloseIndex].LengthStr - 1; currentRead.BP = currentRead.UP_Far[FarIndex]. LengthStr - 1; currentRead.IndelSize = calculateIndelSize(currentRead); currentRead.NT_str = getInsertedStr2(currentRead); currentRead.BPLeft = currentRead.UP_Far[FarIndex].AbsLoc - g_SpacerBeforeAfter; currentRead.BPRight = currentRead.UP_Close[CloseIndex].AbsLoc - g_SpacerBeforeAfter; unsigned RealBP_left= currentRead.BPLeft; unsigned RealBP_right = currentRead.BPRight;//, DIFF; if (ChrSeq.size() < RealBP_left || ChrSeq.size() < RealBP_right) { currentRead.Used = true; break; } if (currentRead.NT_str.size()) { //std::cout << "ns i currentRead.NT_str.size()" << std::endl; //std::cout << currentRead.NT_str << " " << RealBP_left << " " << RealBP_right << std::endl; GetRealStart4Insertion(ChrSeq, currentRead.NT_str, RealBP_left, RealBP_right); //std::cout << "ne i currentRead.NT_str.size()" << std::endl; } else { //std::cout << "no_ns d currentRead.NT_str.size()" << std::endl; //std::cout << RealBP_left << " " << RealBP_right << std::endl; GetRealStart4Deletion(ChrSeq, RealBP_left, RealBP_right); //std::cout << "no_ne d currentRead.NT_str.size()" << std::endl; } short DIFF = currentRead.BPLeft - RealBP_left; DIFF = !((currentRead.BP - 1)<DIFF)?DIFF:(currentRead.BP - 1); if (DIFF > 0) { // std::cout << DIFF << std::endl; //std::cout << "DIFF " << DIFF << std::endl; currentRead.BP -= DIFF; currentRead.BPLeft -= DIFF; currentRead.BPRight -= DIFF; } if (readTransgressesBinBoundaries( currentRead, window.getEnd())) { saveReadForNextCycle( currentRead, currentState.FutureReads_SR); } else { if (readInSpecifiedRegion( currentRead, userSettings->getRegion())) { TempBoxIndex = (int) (currentRead. BPLeft) / BoxSize; //std::cout << currentRead.BPLeft << " " << BoxSize << " " << NumBoxes << " " << TempBoxIndex << std::endl; if (TempBoxIndex < NumBoxes) { Vars[TempBoxIndex]. push_back(ReadIndex); currentRead.Used = true; Count_Var++; Count_Var_Minus++; } } } } } } } } } } LOG_INFO(*logStream << "Total: " << Count_Var << "\t+" << Count_Var_Plus << "\t-" << Count_Var_Minus << std::endl); outputResults(g_bdData, currentState, Vars, NumBoxes, window); for (unsigned int i = 0; i < NumBoxes; i++) { Vars[i].clear(); } return EXIT_SUCCESS; }
int main(int argc, char** argv) { if(argc < 6) { printf("usage: sum <distr. mode = 0/1> <block cyclic factor = R [1, n/P]> <N: matrix is NxN> <input file name> <output ux = 0/1>\n"); return 0; } // Read arguments DISTRIBUTE_READ = atoi(argv[1]); R = atoi(argv[2]); N = atoi(argv[3]); OUTPUT_UX = atoi(argv[5]); char* inputFile = argv[4]; // Initialize MPI MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &P); MPI_Comm_rank(MPI_COMM_WORLD, &PID); RPP = N / P; if(R < 1 || R > N / P) { printf("ERROR: R (%d) must be between 1 and N/P (%d)\n", R, N/P); return -1; } // Broadcast matrix size and block cyclic factor MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(&R, 1, MPI_INT, 0, MPI_COMM_WORLD); // This array stores the rows of the augmented matrix associated to this processor. double* localRows = malloc(RPP * (N + 1) * sizeof(double)); double x[MAX_N]; memset(x, 0, MAX_N * sizeof(double)); // These variables will store times for data loading (and distribution) // Forward elimination and back substitution. float ddtime; float fetime; float bstime; float pvtime; // Load the matrix data loadMatrix(inputFile, localRows, &ddtime); // Solve the system solve(localRows, x, &fetime, &bstime, &pvtime); // Output solution and statistics outputResults(inputFile, localRows, x, ddtime, bstime, fetime, pvtime); // Free memory //free(localRowIds); //free(localRows); // Finalize MPI MPI_Finalize(); return 0; }
int _tmain(int argc, _TCHAR* argv[]) { //In order to accelerate the access to the system state, we code the system state into a double which is calculated as followed //for each server, state_index = (cpu_residual+mem_residual+disk_residual) * server_id //for the whole system, state_index = sum the state_index over the all servers. //With this method, we can quickly locate the state and its corresponding value. vector<cConfiguration> config_vec; initialInputfile(config_vec); vector<cConfiguration>::iterator iter_config_vec = config_vec.begin(); for (;iter_config_vec != config_vec.end();iter_config_vec++) { //reset the seed of random number generator for generating arrival times interval_timeSeed = 10; //reset the seed of random number generator for generating duration times duration_time_seed = 100; //reset the system state value system_state_value_map.clear(); //store the system state visited ever system_state_policy_map.clear(); //initial the set of policies policy_vec.clear(); //initial the input parameters initialInputParameter(iter_config_vec); average_accepted_rate = 0; average_allocation_fail_rate = 0; system_value_map *p_system_value_map = new system_value_map[total_request + 1]; system_policy_map *p_system_policy_map = new system_policy_map[total_request + 1]; global_point_system_value_map = p_system_value_map; global_point_system_policy_map = p_system_policy_map; //unsigned int sample_index; for (sample_index = 0;sample_index < sample_request_num; sample_index++) { accepted_requests_num = 0; allocation_fail_num = 0; cout<<"The "<<sample_index<<" sample path"<<endl; //initial request sequence //vector<cRequest> request_vec; vector<cRequest> *p_request_vec = new vector<cRequest>; multimap<double,cEvent> *p_event_multimap = new multimap<double,cEvent>; //multimap<double,cEvent> event_multimap; //initial the set of physical servers vector<cServer> *p_server_vec = new vector<cServer>; //vector<cServer> server_vec; initialPhyServers(*p_server_vec); if (iter_config_vec == config_vec.begin() && sample_index == 0) { initialCommuCost(*p_server_vec); //initialBasisFuncParameters(server_vec); } initialSystemState(*p_server_vec); generateSampleEvent(*p_request_vec,*p_event_multimap); obtainOptimalStateValue(*p_event_multimap,*p_server_vec); //reset the event indicator event_id = 1; average_accepted_rate += accepted_requests_num/total_request; average_allocation_fail_rate += allocation_fail_num/total_request; delete p_request_vec; delete p_server_vec; delete p_event_multimap; }//end...for (sample_index...) outputResults(); delete[] p_system_policy_map; delete[] p_system_value_map; //outputResultsBasisFunct(); }//end...for (iter_config_vec) return 0; }