/*! Clears the result set and releases any resources held by the query. Sets the query state to inactive. You should rarely if ever need to call this function. */ void QSqlQuery::clear() { *this = QSqlQuery(driver()->createResult()); }
/*! \internal */ void QSqlResult::detachFromResultSet() { if (driver()->hasFeature(QSqlDriver::FinishQuery) || driver()->hasFeature(QSqlDriver::SimpleLocking)) virtual_hook(DetachFromResultSet, 0); }
// Test that the label decorator hook hangs a new label off the // taskinfo message during master launch task. TEST_F(HookTest, VerifyMasterLaunchTaskHook) { Try<PID<Master>> master = StartMaster(CreateMasterFlags()); ASSERT_SOME(master); MockExecutor exec(DEFAULT_EXECUTOR_ID); TestContainerizer containerizer(&exec); // Start a mock slave since we aren't testing the slave hooks yet. Try<PID<Slave>> slave = StartSlave(&containerizer); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); TaskInfo task; task.set_name(""); task.mutable_task_id()->set_value("1"); task.mutable_slave_id()->CopyFrom(offers.get()[0].slave_id()); task.mutable_resources()->CopyFrom(offers.get()[0].resources()); task.mutable_executor()->CopyFrom(DEFAULT_EXECUTOR_INFO); // Add label which will be removed by the hook. Labels* labels = task.mutable_labels(); Label* label = labels->add_labels(); label->set_key(testRemoveLabelKey); label->set_value(testRemoveLabelValue); vector<TaskInfo> tasks; tasks.push_back(task); Future<RunTaskMessage> runTaskMessage = FUTURE_PROTOBUF(RunTaskMessage(), _, _); EXPECT_CALL(exec, registered(_, _, _, _)); EXPECT_CALL(exec, launchTask(_, _)) .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING)); Future<TaskStatus> status; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&status)) .WillRepeatedly(Return()); driver.launchTasks(offers.get()[0].id(), tasks); AWAIT_READY(runTaskMessage); AWAIT_READY(status); // At launchTasks, the label decorator hook inside should have been // executed and we should see the labels now. Also, verify that the // hook module has stripped the first 'testRemoveLabelKey' label. // We do this by ensuring that only one label is present and that it // is the new 'testLabelKey' label. const Labels &labels_ = runTaskMessage.get().task().labels(); ASSERT_EQ(1, labels_.labels_size()); EXPECT_EQ(labels_.labels().Get(0).key(), testLabelKey); EXPECT_EQ(labels_.labels().Get(0).value(), testLabelValue); driver.stop(); driver.join(); Shutdown(); // Must shutdown before 'containerizer' gets deallocated. }
int SummarySharedCommand::process(vector<SharedRAbundVector*> thisLookup, string sumFileName, string sumAllFileName) { try { vector< vector< vector<seqDist> > > calcDistsTotals; //each iter, one for each calc, then each groupCombos dists. this will be used to make .dist files vector< vector<seqDist> > calcDists; calcDists.resize(sumCalculators.size()); for (int thisIter = 0; thisIter < iters+1; thisIter++) { vector<SharedRAbundVector*> thisItersLookup = thisLookup; if (subsample && (thisIter != 0)) { //we want the summary results for the whole dataset, then the subsampling SubSample sample; vector<string> tempLabels; //dont need since we arent printing the sampled sharedRabunds //make copy of lookup so we don't get access violations vector<SharedRAbundVector*> newLookup; for (int k = 0; k < thisItersLookup.size(); k++) { SharedRAbundVector* temp = new SharedRAbundVector(); temp->setLabel(thisItersLookup[k]->getLabel()); temp->setGroup(thisItersLookup[k]->getGroup()); newLookup.push_back(temp); } //for each bin for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } } tempLabels = sample.getSample(newLookup, subsampleSize); thisItersLookup = newLookup; } if(processors == 1){ driver(thisItersLookup, 0, numGroups, sumFileName+".temp", sumAllFileName+".temp", calcDists); m->appendFiles((sumFileName + ".temp"), sumFileName); m->mothurRemove((sumFileName + ".temp")); if (mult) { m->appendFiles((sumAllFileName + ".temp"), sumAllFileName); m->mothurRemove((sumAllFileName + ".temp")); } }else{ int process = 1; vector<int> processIDS; #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) //loop through and create all the processes you want while (process != processors) { pid_t pid = fork(); if (pid > 0) { processIDS.push_back(pid); process++; }else if (pid == 0){ driver(thisItersLookup, lines[process].start, lines[process].end, sumFileName + m->mothurGetpid(process) + ".temp", sumAllFileName + m->mothurGetpid(process) + ".temp", calcDists); //only do this if you want a distance file if (createPhylip) { string tempdistFileName = m->getRootName(m->getSimpleName(sumFileName)) + m->mothurGetpid(process) + ".dist"; ofstream outtemp; m->openOutputFile(tempdistFileName, outtemp); for (int i = 0; i < calcDists.size(); i++) { outtemp << calcDists[i].size() << endl; for (int j = 0; j < calcDists[i].size(); j++) { outtemp << calcDists[i][j].seq1 << '\t' << calcDists[i][j].seq2 << '\t' << calcDists[i][j].dist << endl; } } outtemp.close(); } exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } exit(0); } } //parent do your part driver(thisItersLookup, lines[0].start, lines[0].end, sumFileName + m->mothurGetpid(process) + ".temp", sumAllFileName + m->mothurGetpid(process) + ".temp", calcDists); m->appendFiles((sumFileName + m->mothurGetpid(process) + ".temp"), sumFileName); m->mothurRemove((sumFileName + m->mothurGetpid(process) + ".temp")); if (mult) { m->appendFiles((sumAllFileName + m->mothurGetpid(process) + ".temp"), sumAllFileName); } //force parent to wait until all the processes are done for (int i = 0; i < processIDS.size(); i++) { int temp = processIDS[i]; wait(&temp); } for (int i = 0; i < processIDS.size(); i++) { m->appendFiles((sumFileName + toString(processIDS[i]) + ".temp"), sumFileName); m->mothurRemove((sumFileName + toString(processIDS[i]) + ".temp")); if (mult) { m->mothurRemove((sumAllFileName + toString(processIDS[i]) + ".temp")); } if (createPhylip) { string tempdistFileName = m->getRootName(m->getSimpleName(sumFileName)) + toString(processIDS[i]) + ".dist"; ifstream intemp; m->openInputFile(tempdistFileName, intemp); for (int k = 0; k < calcDists.size(); k++) { int size = 0; intemp >> size; m->gobble(intemp); for (int j = 0; j < size; j++) { int seq1 = 0; int seq2 = 0; float dist = 1.0; intemp >> seq1 >> seq2 >> dist; m->gobble(intemp); seqDist tempDist(seq1, seq2, dist); calcDists[k].push_back(tempDist); } } intemp.close(); m->mothurRemove(tempdistFileName); } } #else ////////////////////////////////////////////////////////////////////////////////////////////////////// //Windows version shared memory, so be careful when passing variables through the summarySharedData struct. //Above fork() will clone, so memory is separate, but that's not the case with windows, //Taking advantage of shared memory to pass results vectors. ////////////////////////////////////////////////////////////////////////////////////////////////////// vector<summarySharedData*> pDataArray; DWORD dwThreadIdArray[processors-1]; HANDLE hThreadArray[processors-1]; //Create processor worker threads. for( int i=1; i<processors; i++ ){ //make copy of lookup so we don't get access violations vector<SharedRAbundVector*> newLookup; for (int k = 0; k < thisLookup.size(); k++) { SharedRAbundVector* temp = new SharedRAbundVector(); temp->setLabel(thisLookup[k]->getLabel()); temp->setGroup(thisLookup[k]->getGroup()); newLookup.push_back(temp); } //for each bin for (int k = 0; k < thisItersLookup[0]->getNumBins(); k++) { if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } for (int j = 0; j < thisItersLookup.size(); j++) { newLookup[j]->push_back(thisItersLookup[j]->getAbundance(k), thisItersLookup[j]->getGroup()); } } // Allocate memory for thread data. summarySharedData* tempSum = new summarySharedData((sumFileName+toString(i)+".temp"), m, lines[i].start, lines[i].end, Estimators, newLookup); pDataArray.push_back(tempSum); processIDS.push_back(i); hThreadArray[i-1] = CreateThread(NULL, 0, MySummarySharedThreadFunction, pDataArray[i-1], 0, &dwThreadIdArray[i-1]); } //parent do your part driver(thisItersLookup, lines[0].start, lines[0].end, sumFileName +"0.temp", sumAllFileName + "0.temp", calcDists); m->appendFiles((sumFileName + "0.temp"), sumFileName); m->mothurRemove((sumFileName + "0.temp")); if (mult) { m->appendFiles((sumAllFileName + "0.temp"), sumAllFileName); } //Wait until all threads have terminated. WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE); //Close all thread handles and free memory allocations. for(int i=0; i < pDataArray.size(); i++){ if (pDataArray[i]->count != (pDataArray[i]->end-pDataArray[i]->start)) { m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end-pDataArray[i]->start) + " groups assigned to it, quitting. \n"); m->control_pressed = true; } m->appendFiles((sumFileName + toString(processIDS[i]) + ".temp"), sumFileName); m->mothurRemove((sumFileName + toString(processIDS[i]) + ".temp")); for (int j = 0; j < pDataArray[i]->thisLookup.size(); j++) { delete pDataArray[i]->thisLookup[j]; } if (createPhylip) { for (int k = 0; k < calcDists.size(); k++) { int size = pDataArray[i]->calcDists[k].size(); for (int j = 0; j < size; j++) { calcDists[k].push_back(pDataArray[i]->calcDists[k][j]); } } } CloseHandle(hThreadArray[i]); delete pDataArray[i]; } #endif } if (subsample && (thisIter != 0)) { //we want the summary results for the whole dataset, then the subsampling calcDistsTotals.push_back(calcDists); //clean up memory for (int i = 0; i < thisItersLookup.size(); i++) { delete thisItersLookup[i]; } thisItersLookup.clear(); }else { if (createPhylip) { for (int i = 0; i < calcDists.size(); i++) { if (m->control_pressed) { break; } //initialize matrix vector< vector<double> > matrix; //square matrix to represent the distance matrix.resize(thisLookup.size()); for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } for (int j = 0; j < calcDists[i].size(); j++) { int row = calcDists[i][j].seq1; int column = calcDists[i][j].seq2; double dist = calcDists[i][j].dist; matrix[row][column] = dist; matrix[column][row] = dist; } map<string, string> variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[calc]"] = sumCalculators[i]->getName(); variables["[distance]"] = thisLookup[0]->getLabel(); variables["[outputtag]"] = output; variables["[tag2]"] = ""; string distFileName = getOutputFileName("phylip",variables); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outDist; m->openOutputFile(distFileName, outDist); outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint); printSims(outDist, matrix); outDist.close(); } } } for (int i = 0; i < calcDists.size(); i++) { calcDists[i].clear(); } } if (iters != 0) { //we need to find the average distance and standard deviation for each groups distance vector< vector<seqDist> > calcAverages = m->getAverages(calcDistsTotals); //find standard deviation vector< vector<seqDist> > stdDev = m->getStandardDeviation(calcDistsTotals, calcAverages); //print results for (int i = 0; i < calcDists.size(); i++) { vector< vector<double> > matrix; //square matrix to represent the distance matrix.resize(thisLookup.size()); for (int k = 0; k < thisLookup.size(); k++) { matrix[k].resize(thisLookup.size(), 0.0); } vector< vector<double> > stdmatrix; //square matrix to represent the stdDev stdmatrix.resize(thisLookup.size()); for (int k = 0; k < thisLookup.size(); k++) { stdmatrix[k].resize(thisLookup.size(), 0.0); } for (int j = 0; j < calcAverages[i].size(); j++) { int row = calcAverages[i][j].seq1; int column = calcAverages[i][j].seq2; float dist = calcAverages[i][j].dist; float stdDist = stdDev[i][j].dist; matrix[row][column] = dist; matrix[column][row] = dist; stdmatrix[row][column] = stdDist; stdmatrix[column][row] = stdDist; } map<string, string> variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); variables["[calc]"] = sumCalculators[i]->getName(); variables["[distance]"] = thisLookup[0]->getLabel(); variables["[outputtag]"] = output; variables["[tag2]"] = "ave"; string distFileName = getOutputFileName("phylip",variables); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outAve; m->openOutputFile(distFileName, outAve); outAve.setf(ios::fixed, ios::floatfield); outAve.setf(ios::showpoint); printSims(outAve, matrix); outAve.close(); variables["[tag2]"] = "std"; distFileName = getOutputFileName("phylip",variables); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outSTD; m->openOutputFile(distFileName, outSTD); outSTD.setf(ios::fixed, ios::floatfield); outSTD.setf(ios::showpoint); printSims(outSTD, stdmatrix); outSTD.close(); } } return 0; } catch(exception& e) { m->errorOut(e, "SummarySharedCommand", "process"); exit(1); } }
int AlignCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } templateDB = new AlignmentDB(templateFileName, search, kmerSize, gapOpen, gapExtend, match, misMatch, rand()); for (int s = 0; s < candidateFileNames.size(); s++) { if (m->control_pressed) { outputTypes.clear(); return 0; } m->mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); m->mothurOutEndLine(); if (outputDir == "") { outputDir += m->hasPath(candidateFileNames[s]); } map<string, string> variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])); string alignFileName = getOutputFileName("fasta", variables); string reportFileName = getOutputFileName("alignreport", variables); string accnosFileName = getOutputFileName("accnos", variables); bool hasAccnos = true; int numFastaSeqs = 0; for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); int start = time(NULL); vector<unsigned long long> positions; #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) positions = m->divideFile(candidateFileNames[s], processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); } #else if (processors == 1) { lines.push_back(new linePair(0, 1000)); }else { positions = m->setFilePosFasta(candidateFileNames[s], numFastaSeqs); if (numFastaSeqs < processors) { processors = numFastaSeqs; } //figure out how many sequences you have to process int numSeqsPerProcessor = numFastaSeqs / processors; for (int i = 0; i < processors; i++) { int startIndex = i * numSeqsPerProcessor; if(i == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor; } lines.push_back(new linePair(positions[startIndex], numSeqsPerProcessor)); } } #endif if(processors == 1){ numFastaSeqs = driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); }else{ numFastaSeqs = createProcesses(alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); } if (m->control_pressed) { m->mothurRemove(accnosFileName); m->mothurRemove(alignFileName); m->mothurRemove(reportFileName); outputTypes.clear(); return 0; } //delete accnos file if its blank else report to user if (m->isBlank(accnosFileName)) { m->mothurRemove(accnosFileName); hasAccnos = false; } else { m->mothurOut("[WARNING]: Some of your sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); if (!flip) { m->mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); }else{ m->mothurOut(" If the reverse compliment proved to be better it was reported."); } m->mothurOutEndLine(); } outputNames.push_back(alignFileName); outputTypes["fasta"].push_back(alignFileName); outputNames.push_back(reportFileName); outputTypes["alignreport"].push_back(reportFileName); if (hasAccnos) { outputNames.push_back(accnosFileName); outputTypes["accnos"].push_back(accnosFileName); } m->mothurOut("It took " + toString(time(NULL) - start) + " secs to align " + toString(numFastaSeqs) + " sequences."); m->mothurOutEndLine(); m->mothurOutEndLine(); } //set align file as new current fastafile string currentFasta = ""; itTypes = outputTypes.find("fasta"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { currentFasta = (itTypes->second)[0]; m->setFastaFile(currentFasta); } } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine(); return 0; } catch(exception& e) { m->errorOut(e, "AlignCommand", "execute"); exit(1); } }
int main(int argc, char *argv[]) { char mapset[GMAPSET_MAX]; char name[GNAME_MAX]; char *camera; struct GModule *module; struct Option *group_opt, *map_opt, *target_map_opt; struct Cell_head cellhd; int ok; int nfiles; /* must run in a term window */ G_putenv("GRASS_UI_TERM", "1"); G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("imagery, orthorectify"); module->description = _("Creates control points on an image " "to be ortho-rectified."); group_opt = G_define_option(); group_opt->key = "group"; group_opt->type = TYPE_STRING; group_opt->required = YES; group_opt->multiple = NO; group_opt->description = _("Name of imagery group"); map_opt = G_define_standard_option(G_OPT_R_MAP); map_opt->required = NO; map_opt->description = _("Name of image to be rectified which will " "be initially drawn on screen"); target_map_opt = G_define_standard_option(G_OPT_R_MAP); target_map_opt->key = "target"; target_map_opt->required = NO; target_map_opt->description = _("Name of a map from target mapset which " "will be initially drawn on screen"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); G_suppress_masking(); /* need to do this for target location */ camera = (char *)G_malloc(40 * sizeof(char)); strcpy(name, group_opt->answer); interrupt_char = G_intr_char(); tempfile1 = G_tempfile(); tempfile2 = G_tempfile(); tempfile_dot = G_tempfile(); tempfile_dot2 = G_tempfile(); tempfile_win = G_tempfile(); tempfile_win2 = G_tempfile(); cell_list = G_tempfile(); vect_list = G_tempfile(); group_list = G_tempfile(); digit_points = G_tempfile(); if (R_open_driver() != 0) G_fatal_error(_("No graphics device selected")); /* get group ref */ strcpy(group.name, name); if (!I_find_group(group.name)) G_fatal_error(_("Group [%s] not found"), group.name); /* get the group ref */ I_get_group_ref(group.name, &group.group_ref); nfiles = group.group_ref.nfiles; /* write block files to block list file */ prepare_group_list(); /** look for camera info for this group**/ G_suppress_warnings(1); if (!I_get_group_camera(group.name, camera)) G_fatal_error(_("No camera reference file selected for group [%s]"), group.name); if (!I_get_cam_info(camera, &group.camera_ref)) G_fatal_error(_("Bad format in camera file for group [%s]"), group.name); G_suppress_warnings(0); /* get initial camera exposure station, if any */ if (!(ok = I_find_initial(group.name))) G_warning(_("No initial camera exposure station for group [%s]"), group.name); if (ok && (!I_get_init_info(group.name, &group.camera_exp)) ) G_warning(_("Bad format in initial camera exposure station for group [%s]"), group.name); /* get target info and environment */ G_suppress_warnings(1); get_target(); find_target_files(); G_suppress_warnings(0); /* read group reference points, if any */ G_suppress_warnings(1); if (!I_get_ref_points(group.name, &group.photo_points)) { G_suppress_warnings(0); if (group.photo_points.count == 0) G_fatal_error(_("No photo points for group [%s]"), group.name); else if (group.ref_equation_stat == 0) G_fatal_error(_("Poorly placed photo points for group [%s]"), group.name); } G_suppress_warnings(0); /* determine transformation equation */ Compute_ref_equation(); /* read group control points, format: image x,y,cfl; target E,N,Z */ G_suppress_warnings(1); if (!I_get_con_points(group.name, &group.control_points)) group.control_points.count = 0; G_suppress_warnings(0); /* compute image coordinates of photo control points */ /******** I_convert_con_points (group.name, &group.control_points, &group.control_points, group.E12, group.N12); ********/ /* determine transformation equation */ G_message(_("Computing equations ...")); if (group.control_points.count > 0) Compute_ortho_equation(); /* signal (SIGINT, SIG_IGN); */ /* signal (SIGQUIT, SIG_IGN); */ select_current_env(); Init_graphics(); display_title(VIEW_MAP1); select_target_env(); display_title(VIEW_MAP2); select_current_env(); Begin_curses(); G_set_error_routine(error); /* #ifdef SIGTSTP signal (SIGTSTP, SIG_IGN); #endif */ /* Set image to be rectified */ if (map_opt->answer) { char *ms; ms = G_find_cell(map_opt->answer, ""); if (ms == NULL) { G_fatal_error(_("Raster map <%s> not found"), map_opt->answer); } strcpy(name, map_opt->answer); strcpy(mapset, ms); if (G_get_cellhd(name, mapset, &cellhd) < 0) { G_fatal_error(_("Unable to read raster header of <%s>"), map_opt->answer); } } else { /* ask user for group file to be displayed */ do { if (!choose_groupfile(name, mapset)) quit(EXIT_SUCCESS); /* display this file in "map1" */ } while (G_get_cellhd(name, mapset, &cellhd) < 0); } G_adjust_window_to_box(&cellhd, &VIEW_MAP1->cell.head, VIEW_MAP1->nrows, VIEW_MAP1->ncols); Configure_view(VIEW_MAP1, name, mapset, cellhd.ns_res, cellhd.ew_res); drawcell(VIEW_MAP1); /* Set target map if specified */ if (target_map_opt->answer) { char *ms; select_target_env(); ms = G_find_cell(target_map_opt->answer, ""); if (ms == NULL) { G_fatal_error(_("Raster map <%s> not found"), target_map_opt->answer); } strcpy(name, target_map_opt->answer); strcpy(mapset, ms); if (G_get_cellhd(name, mapset, &cellhd) < 0) { G_fatal_error(_("Unable to read raster header of <%s>"), target_map_opt->answer); } G_adjust_window_to_box(&cellhd, &VIEW_MAP2->cell.head, VIEW_MAP2->nrows, VIEW_MAP2->ncols); Configure_view(VIEW_MAP2, name, mapset, cellhd.ns_res, cellhd.ew_res); drawcell(VIEW_MAP2); from_flag = 1; from_keyboard = 0; from_screen = 1; } display_conz_points(1); Curses_clear_window(PROMPT_WINDOW); /* determine initial input method. */ setup_digitizer(); if (use_digitizer) { from_digitizer = 1; from_keyboard = 0; from_flag = 1; } /* go do the work */ driver(); quit(EXIT_SUCCESS); }
bool Camera_ASCOMLateClass::Connect(const wxString& camId) { DispatchClass driver_class; DispatchObj driver(&driver_class); // create the COM object if (!Create(&driver, &driver_class)) { pFrame->Alert(_("Could not create ASCOM camera object. See the debug log for more information.")); return true; } struct ConnectInBg : public ConnectCameraInBg { Camera_ASCOMLateClass *cam; ConnectInBg(Camera_ASCOMLateClass *cam_) : cam(cam_) { } bool Entry() { GITObjRef dobj(cam->m_gitEntry); // ... set the Connected property to true.... if (!dobj.PutProp(L"Connected", true)) { SetErrorMsg(ExcepMsg(dobj.Excep())); return true; } return false; } }; ConnectInBg bg(this); if (bg.Run()) { pFrame->Alert(_("ASCOM driver problem: Connect") + ":\n" + bg.GetErrorMsg()); return true; } Variant vname; if (driver.GetProp(&vname, L"Name")) { Name = vname.bstrVal; Debug.AddLine(wxString::Format("setting camera Name = %s", Name)); } // See if we have an onboard guider output Variant vRes; if (!driver.GetProp(&vRes, L"CanPulseGuide")) { Debug.AddLine(ExcepMsg("CanPulseGuide", driver.Excep())); pFrame->Alert(_("ASCOM driver missing the CanPulseGuide property. Please report this error to your ASCOM driver provider.")); return true; } m_hasGuideOutput = ((vRes.boolVal != VARIANT_FALSE) ? true : false); if (!driver.GetProp(&vRes, L"CanAbortExposure")) { Debug.AddLine(ExcepMsg("CanAbortExposure", driver.Excep())); pFrame->Alert(_("ASCOM driver missing the CanAbortExposure property. Please report this error to your ASCOM driver provider.")); return true; } m_canAbortExposure = vRes.boolVal != VARIANT_FALSE ? true : false; if (!driver.GetProp(&vRes, L"CanStopExposure")) { Debug.AddLine(ExcepMsg("CanStopExposure", driver.Excep())); pFrame->Alert(_("ASCOM driver missing the CanStopExposure property. Please report this error to your ASCOM driver provider.")); return true; } m_canStopExposure = vRes.boolVal != VARIANT_FALSE ? true : false; // Check if we have a shutter if (driver.GetProp(&vRes, L"HasShutter")) { HasShutter = ((vRes.boolVal != VARIANT_FALSE) ? true : false); } // Get the image size of a full frame if (!driver.GetProp(&vRes, L"CameraXSize")) { Debug.AddLine(ExcepMsg("CameraXSize", driver.Excep())); pFrame->Alert(_("ASCOM driver missing the CameraXSize property. Please report this error to your ASCOM driver provider.")); return true; } m_maxSize.SetWidth((int) vRes.lVal); if (!driver.GetProp(&vRes, L"CameraYSize")) { Debug.AddLine(ExcepMsg("CameraYSize", driver.Excep())); pFrame->Alert(_("ASCOM driver missing the CameraYSize property. Please report this error to your ASCOM driver provider.")); return true; } m_maxSize.SetHeight((int) vRes.lVal); if (!driver.GetProp(&vRes, L"MaxADU")) { Debug.AddLine(ExcepMsg("MaxADU", driver.Excep())); m_bitsPerPixel = 16; // assume 16 BPP } else { m_bitsPerPixel = vRes.intVal <= 255 ? 8 : 16; } // Get the interface version of the driver DriverVersion = 1; if (driver.GetProp(&vRes, L"InterfaceVersion")) { DriverVersion = vRes.iVal; } if (DriverVersion > 1 && // We can check the color sensor status of the cam driver.GetProp(&vRes, L"SensorType") && vRes.iVal > 1) { Color = true; } // Get pixel size in micons if (!driver.GetProp(&vRes, L"PixelSizeX")) { Debug.AddLine(ExcepMsg("PixelSizeX", driver.Excep())); pFrame->Alert(_("ASCOM driver missing the PixelSizeX property. Please report this error to your ASCOM driver provider.")); return true; } PixelSize = (double) vRes.dblVal; if (!driver.GetProp(&vRes, L"PixelSizeY")) { Debug.AddLine(ExcepMsg("PixelSizeY", driver.Excep())); pFrame->Alert(_("ASCOM driver missing the PixelSizeY property. Please report this error to your ASCOM driver provider.")); return true; } if ((double) vRes.dblVal > PixelSize) PixelSize = (double) vRes.dblVal; short maxBinX = 1, maxBinY = 1; if (driver.GetProp(&vRes, L"MaxBinX")) maxBinX = vRes.iVal; if (driver.GetProp(&vRes, L"MaxBinY")) maxBinY = vRes.iVal; MaxBinning = wxMin(maxBinX, maxBinY); Debug.AddLine("ASCOM camera: MaxBinning is %hu", MaxBinning); if (Binning > MaxBinning) Binning = MaxBinning; m_curBin = Binning; // Get the dispids we'll need for more routine things if (!GetDispid(&dispid_setxbin, driver, L"BinX")) return true; if (!GetDispid(&dispid_setybin, driver, L"BinY")) return true; if (!GetDispid(&dispid_startx, driver, L"StartX")) return true; if (!GetDispid(&dispid_starty, driver, L"StartY")) return true; if (!GetDispid(&dispid_numx, driver, L"NumX")) return true; if (!GetDispid(&dispid_numy, driver, L"NumY")) return true; if (!GetDispid(&dispid_imageready, driver, L"ImageReady")) return true; if (!GetDispid(&dispid_imagearray, driver, L"ImageArray")) return true; if (!GetDispid(&dispid_startexposure, driver, L"StartExposure")) return true; if (!GetDispid(&dispid_abortexposure, driver, L"AbortExposure")) return true; if (!GetDispid(&dispid_stopexposure, driver, L"StopExposure")) return true; if (!GetDispid(&dispid_pulseguide, driver, L"PulseGuide")) return true; if (!GetDispid(&dispid_ispulseguiding, driver, L"IsPulseGuiding")) return true; // Program some defaults -- full size and binning EXCEPINFO excep; if (ASCOM_SetBin(driver.IDisp(), Binning, &excep)) { // only make this error fatal if the camera supports binning > 1 if (MaxBinning > 1) { pFrame->Alert(_("The ASCOM camera failed to set binning. See the debug log for more information.")); return true; } } FullSize = wxSize(m_maxSize.x / Binning, m_maxSize.y / Binning); m_roi = FullSize; ASCOM_SetROI(driver.IDisp(), FullSize, &excep); Connected = true; return false; }
void filter_object::test<2>() { set_test_name("LLEventTimeout::actionAfter()"); LLEventPump& driver(pumps.obtain("driver")); TestEventTimeout filter(driver); listener0.reset(0); LLTempBoundListener temp1( listener0.listenTo(filter)); // Use listener1.call() as the Action for actionAfter(), since it // already provides a way to sense the call listener1.reset(0); // driver --> filter --> listener0 filter.actionAfter(20, boost::bind(&Listener::call, boost::ref(listener1), LLSD("timeout"))); // Okay, (fake) timer is ticking. 'filter' can only sense the timer // when we pump mainloop. Do that right now to take the logic path // before either the anticipated event arrives or the timer expires. mainloop.post(17); check_listener("no timeout 1", listener1, LLSD(0)); // Expected event arrives... driver.post(1); check_listener("event passed thru", listener0, LLSD(1)); // Should have canceled the timer. Verify that by asserting that the // time has expired, then pumping mainloop again. filter.forceTimeout(); mainloop.post(17); check_listener("no timeout 2", listener1, LLSD(0)); // Verify chained actionAfter() calls, that is, that a second // actionAfter() resets the timer established by the first // actionAfter(). filter.actionAfter(20, boost::bind(&Listener::call, boost::ref(listener1), LLSD("timeout"))); // Since our TestEventTimeout class isn't actually manipulating time // (quantities of seconds), only a bool "elapsed" flag, sense that by // forcing the flag between actionAfter() calls. filter.forceTimeout(); // Pumping mainloop here would result in a timeout (as we'll verify // below). This state simulates a ticking timer that has not yet timed // out. But now, before a mainloop event lets 'filter' recognize // timeout on the previous actionAfter() call, pretend we're pushing // that timeout farther into the future. filter.actionAfter(20, boost::bind(&Listener::call, boost::ref(listener1), LLSD("timeout"))); // Look ma, no timeout! mainloop.post(17); check_listener("no timeout 3", listener1, LLSD(0)); // Now let the updated actionAfter() timer expire. filter.forceTimeout(); // Notice the timeout. mainloop.post(17); check_listener("timeout", listener1, LLSD("timeout")); // Timing out cancels the timer. Verify that. listener1.reset(0); filter.forceTimeout(); mainloop.post(17); check_listener("no timeout 4", listener1, LLSD(0)); // Reset the timer and then cancel() it. filter.actionAfter(20, boost::bind(&Listener::call, boost::ref(listener1), LLSD("timeout"))); // neither expired nor satisified mainloop.post(17); check_listener("no timeout 5", listener1, LLSD(0)); // cancel filter.cancel(); // timeout! filter.forceTimeout(); mainloop.post(17); check_listener("no timeout 6", listener1, LLSD(0)); }
int ChopSeqsCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } map<string, string> variables; string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); string outputFileName = getOutputFileName("fasta", variables); outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); string outputFileNameAccnos = getOutputFileName("accnos", variables); string fastafileTemp = ""; if (qualfile != "") { fastafileTemp = outputFileName + ".qualFile.Positions.temp"; } vector<unsigned long long> positions; vector<linePair> lines; #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) positions = m->divideFile(fastafile, processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } #else int numSeqs = 0; positions = m->setFilePosFasta(fastafile, numSeqs); if (numSeqs < processors) { processors = numSeqs; } //figure out how many sequences you have to process int numSeqsPerProcessor = numSeqs / processors; for (int i = 0; i < processors; i++) { int startIndex = i * numSeqsPerProcessor; if(i == (processors - 1)){ numSeqsPerProcessor = numSeqs - i * numSeqsPerProcessor; } lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor)); } #endif bool wroteAccnos = false; if(processors == 1) { wroteAccnos = driver(lines[0], fastafile, outputFileName, outputFileNameAccnos, fastafileTemp); } else { wroteAccnos = createProcesses(lines, fastafile, outputFileName, outputFileNameAccnos, fastafileTemp); } if (m->control_pressed) { return 0; } if (qualfile != "") { thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); } variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)); string outputQualFileName = getOutputFileName("qfile", variables); outputNames.push_back(outputQualFileName); outputTypes["qfile"].push_back(outputQualFileName); processQual(outputQualFileName, fastafileTemp); m->mothurRemove(fastafileTemp); } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } if (wroteAccnos) { outputNames.push_back(outputFileNameAccnos); outputTypes["accnos"].push_back(outputFileNameAccnos); //use remove.seqs to create new name, group and count file if ((countfile != "") || (namefile != "") || (groupfile != "")) { string inputString = "accnos=" + outputFileNameAccnos; if (countfile != "") { inputString += ", count=" + countfile; } else{ if (namefile != "") { inputString += ", name=" + namefile; } if (groupfile != "") { inputString += ", group=" + groupfile; } } m->mothurOut("/******************************************/"); m->mothurOutEndLine(); m->mothurOut("Running command: remove.seqs(" + inputString + ")"); m->mothurOutEndLine(); m->mothurCalling = true; Command* removeCommand = new RemoveSeqsCommand(inputString); removeCommand->execute(); map<string, vector<string> > filenames = removeCommand->getOutputFiles(); delete removeCommand; m->mothurCalling = false; m->mothurOut("/******************************************/"); m->mothurOutEndLine(); if (groupfile != "") { thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); string outGroup = getOutputFileName("group", variables); m->renameFile(filenames["group"][0], outGroup); outputNames.push_back(outGroup); outputTypes["group"].push_back(outGroup); } if (namefile != "") { thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); string outName = getOutputFileName("name", variables); m->renameFile(filenames["name"][0], outName); outputNames.push_back(outName); outputTypes["name"].push_back(outName); } if (countfile != "") { thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); string outCount = getOutputFileName("count", variables); m->renameFile(filenames["count"][0], outCount); outputNames.push_back(outCount); outputTypes["count"].push_back(outCount); } } } else { m->mothurRemove(outputFileNameAccnos); } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } //set fasta file as new current fastafile string current = ""; itTypes = outputTypes.find("fasta"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); } } if (wroteAccnos) { //set accnos file as new current accnosfile itTypes = outputTypes.find("accnos"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); } } itTypes = outputTypes.find("name"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); } } itTypes = outputTypes.find("group"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); } } itTypes = outputTypes.find("count"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setCountTableFile(current); } } } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine(); return 0; } catch(exception& e) { m->errorOut(e, "ChopSeqsCommand", "execute"); exit(1); } }
bool ChopSeqsCommand::createProcesses(vector<linePair> lines, string filename, string outFasta, string outAccnos, string fastafileTemp) { try { int process = 1; bool wroteAccnos = false; vector<int> processIDS; vector<string> nonBlankAccnosFiles; bool recalc = false; #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) //loop through and create all the processes you want while (process != processors) { pid_t pid = fork(); if (pid > 0) { processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ string fastafileTempThisProcess = fastafileTemp; if (fastafileTempThisProcess != "") { fastafileTempThisProcess = fastafileTempThisProcess + m->mothurGetpid(process) + ".temp"; } wroteAccnos = driver(lines[process], filename, outFasta + m->mothurGetpid(process) + ".temp", outAccnos + m->mothurGetpid(process) + ".temp", fastafileTempThisProcess); //pass numSeqs to parent ofstream out; string tempFile = fastafile + m->mothurGetpid(process) + ".bool.temp"; m->openOutputFile(tempFile, out); out << wroteAccnos << endl; out.close(); exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } //wait to die for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; wait(&temp); } m->control_pressed = false; recalc = true; break; } } if (recalc) { //test line, also set recalc to true. //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; wait(&temp); } m->control_pressed = false; processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); lines.clear(); vector<unsigned long long> positions = m->divideFile(filename, processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); } processIDS.resize(0); process = 1; while (process != processors) { pid_t pid = fork(); if (pid > 0) { processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ string fastafileTempThisProcess = fastafileTemp; if (fastafileTempThisProcess != "") { fastafileTempThisProcess = fastafileTempThisProcess + m->mothurGetpid(process) + ".temp"; } wroteAccnos = driver(lines[process], filename, outFasta + m->mothurGetpid(process) + ".temp", outAccnos + m->mothurGetpid(process) + ".temp", fastafileTempThisProcess); //pass numSeqs to parent ofstream out; string tempFile = fastafile + m->mothurGetpid(process) + ".bool.temp"; m->openOutputFile(tempFile, out); out << wroteAccnos << endl; out.close(); exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } exit(0); } } } //do your part wroteAccnos = driver(lines[0], filename, outFasta, outAccnos, fastafileTemp); //force parent to wait until all the processes are done for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; wait(&temp); } if (wroteAccnos) { nonBlankAccnosFiles.push_back(outAccnos); } else { m->mothurRemove(outAccnos); } //remove so other files can be renamed to it //parent reads in and combine Filter info for (int i = 0; i < processIDS.size(); i++) { string tempFilename = fastafile + toString(processIDS[i]) + ".bool.temp"; ifstream in; m->openInputFile(tempFilename, in); bool temp; in >> temp; m->gobble(in); if (temp) { wroteAccnos = temp; nonBlankAccnosFiles.push_back(outAccnos + toString(processIDS[i]) + ".temp"); } else { m->mothurRemove((outAccnos + toString(processIDS[i]) + ".temp")); } in.close(); m->mothurRemove(tempFilename); } #else ////////////////////////////////////////////////////////////////////////////////////////////////////// //Windows version shared memory, so be careful when passing variables through the seqSumData struct. //Above fork() will clone, so memory is separate, but that's not the case with windows, //Taking advantage of shared memory to allow both threads to add info to vectors. ////////////////////////////////////////////////////////////////////////////////////////////////////// vector<chopData*> pDataArray; DWORD dwThreadIdArray[processors-1]; HANDLE hThreadArray[processors-1]; //Create processor worker threads. for( int i=0; i<processors-1; i++ ){ string extension = ""; if (i != 0) { extension = toString(i) + ".temp"; processIDS.push_back(i); } // Allocate memory for thread data. string fastafileTempThisProcess = fastafileTemp; if (fastafileTempThisProcess != "") { fastafileTempThisProcess = fastafileTempThisProcess + extension; } chopData* tempChop = new chopData(filename, (outFasta+extension), (outAccnos+extension), m, lines[i].start, lines[i].end, keep, countGaps, numbases, Short, keepN, qualfile, fastafileTempThisProcess); pDataArray.push_back(tempChop); //MyChopThreadFunction is in header. It must be global or static to work with the threads. //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier hThreadArray[i] = CreateThread(NULL, 0, MyChopThreadFunction, pDataArray[i], 0, &dwThreadIdArray[i]); } //do your part string fastafileTempThisProcess = fastafileTemp; if (fastafileTempThisProcess != "") { fastafileTempThisProcess = fastafileTempThisProcess + toString(processors-1) + ".temp"; } wroteAccnos = driver(lines[processors-1], filename, (outFasta + toString(processors-1) + ".temp"), (outAccnos + toString(processors-1) + ".temp"), fastafileTempThisProcess); processIDS.push_back(processors-1); //Wait until all threads have terminated. WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE); if (wroteAccnos) { nonBlankAccnosFiles.push_back(outAccnos); } else { m->mothurRemove(outAccnos); } //remove so other files can be renamed to it //Close all thread handles and free memory allocations. for(int i=0; i < pDataArray.size(); i++){ if (pDataArray[i]->wroteAccnos) { wroteAccnos = pDataArray[i]->wroteAccnos; nonBlankAccnosFiles.push_back(outAccnos + toString(processIDS[i]) + ".temp"); } else { m->mothurRemove((outAccnos + toString(processIDS[i]) + ".temp")); } //check to make sure the process finished if (pDataArray[i]->count != pDataArray[i]->end) { m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; } CloseHandle(hThreadArray[i]); delete pDataArray[i]; } #endif for (int i = 0; i < processIDS.size(); i++) { if (fastafileTemp != "") { m->appendFiles((fastafileTemp + toString(processIDS[i]) + ".temp"), fastafileTemp); m->mothurRemove((fastafileTemp + toString(processIDS[i]) + ".temp")); } m->appendFiles((outFasta + toString(processIDS[i]) + ".temp"), outFasta); m->mothurRemove((outFasta + toString(processIDS[i]) + ".temp")); } if (nonBlankAccnosFiles.size() != 0) { m->renameFile(nonBlankAccnosFiles[0], outAccnos); for (int h=1; h < nonBlankAccnosFiles.size(); h++) { m->appendFiles(nonBlankAccnosFiles[h], outAccnos); m->mothurRemove(nonBlankAccnosFiles[h]); } }else { //recreate the accnosfile if needed ofstream out; m->openOutputFile(outAccnos, out); out.close(); } return wroteAccnos; } catch(exception& e) { m->errorOut(e, "ChopSeqsCommand", "createProcesses"); exit(1); } }
int sc_main(int argc , char *argv[]) { sc_signal< sc_uint<NN_DIGIT_BITS> > in_a, in_b; sc_signal< sc_uint<3> > write_select; sc_signal< bool > write_enable; sc_signal< sc_uint<3> > read_a_select, read_b_select; sc_signal< bool > read_enable, input_load; sc_signal< sc_uint<2> > input_mux_select; sc_signal< bool > reg_file_in_mux_select; sc_signal< sc_uint<NN_DIGIT_BITS> > out_a; sc_signal< sc_uint<NN_DIGIT_BITS> > out_b; sc_signal< sc_uint<NN_DIGIT_BITS> > b_high, b_low, c_high, c_low; sc_signal< sc_uint<NN_DIGIT_BITS> > input_reg_value, data_path_calculated_value, regfile_input; sc_signal< sc_uint<2> > adder_mux_select, output_mux_select; sc_signal< bool > mult_enable, adder_enable; sc_signal< bool > shifter_enable, shifter_direction; sc_signal< bool > comp_eq, comp_gt, comp_lt; sc_signal< sc_uint<NN_DIGIT_BITS> > high_1_value, low_1_value, zero_value; sc_signal< sc_uint<NN_DIGIT_BITS> > adder_mux_output, adder_output, shifter_output, mult_output; sc_clock Clk("Clock", 10, SC_NS); Driver driver("driver"); hw_const<NN_DIGIT_BITS> high_1_const("high_1_const", 0x00010000), low_1_const("low_1_const", 0x00000001), zero_const("zero_const", 0x00000000); register_wt_half_index b_reg("b_reg"), c_reg("c_reg"); mux4 input_mux("input_mux"), adder_mux("adder_mux"), output_mux("output_mux"); mux2 reg_file_in_mux("reg_file_in_mux"); register_file reg_file("reg_file"); multiplier mult("mult"); adder add("add"); shifter16 shifter("shifter"); comparator comparison("comparison"); Viewer viewer("viewer"); // Constant Connections high_1_const.output(high_1_value); low_1_const.output(low_1_value); zero_const.output(zero_value); // Driver driver.CLK(Clk); driver.in_a(in_a); driver.in_b(in_b); driver.write_enable(write_enable); driver.write_select(write_select); driver.read_a_select(read_a_select); driver.read_b_select(read_b_select); driver.read_enable(read_enable); driver.input_load(input_load); driver.input_mux_select(input_mux_select); driver.reg_file_in_mux_select(reg_file_in_mux_select); driver.adder_mux_select(adder_mux_select); driver.output_mux_select(output_mux_select); driver.mult_enable(mult_enable); driver.adder_enable(adder_enable); driver.shifter_enable(shifter_enable); driver.shifter_direction(shifter_direction); driver.comp_eq(comp_eq); driver.comp_gt(comp_gt); driver.comp_lt(comp_lt); // Init Load b_reg.in(in_a); b_reg.out_high(b_high); b_reg.out_low(b_low); b_reg.clk(Clk); b_reg.load(input_load); c_reg.in(in_b); c_reg.out_high(c_high); c_reg.out_low(c_low); c_reg.clk(Clk); c_reg.load(input_load); // FSM Input Mux input_mux.in_a(b_high); input_mux.in_b(b_low); input_mux.in_c(c_high); input_mux.in_d(c_low); input_mux.out(input_reg_value); input_mux.select(input_mux_select); // Register File Input Mux reg_file_in_mux.in_a(input_reg_value); reg_file_in_mux.in_b(data_path_calculated_value); reg_file_in_mux.out(regfile_input); reg_file_in_mux.select(reg_file_in_mux_select); reg_file.clk(Clk); reg_file.in_a(regfile_input); reg_file.write_enable(write_enable); reg_file.write_select(write_select); reg_file.read_a_select(read_a_select); reg_file.read_b_select(read_b_select); reg_file.read_enable(read_enable); reg_file.out_a(out_a); reg_file.out_b(out_b); // Multiplier mult.in_a(out_a); mult.in_b(out_b); mult.out(mult_output); mult.enable(mult_enable); // Adder Input Mux adder_mux.in_a(out_b); adder_mux.in_b(high_1_value); adder_mux.in_c(low_1_value); adder_mux.in_d(zero_value); adder_mux.out(adder_mux_output); adder_mux.select(adder_mux_select); // Adder add.in_a(out_a); add.in_b(adder_mux_output); add.out(adder_output); add.enable(adder_enable); // Shifter shifter.in(out_a); shifter.out(shifter_output); shifter.direction(shifter_direction); shifter.enable(shifter_enable); // Comparator comparison.in_a(out_a); comparison.in_b(out_b); comparison.eq(comp_eq); comparison.lt(comp_lt); comparison.gt(comp_gt); // Output Mux output_mux.in_a(mult_output); output_mux.in_b(adder_output); output_mux.in_c(shifter_output); output_mux.in_d(zero_value); output_mux.out(data_path_calculated_value); output_mux.select(output_mux_select); // Viewer viewer.out_a(out_a); viewer.out_b(out_b); sc_start(); return(0); }
// This test verifies that the slave run task label decorator can add // and remove labels from a task during the launch sequence. A task // with two labels ("foo":"bar" and "bar":"baz") is launched and will // get modified by the slave hook to strip the "foo":"bar" pair and // add a new "baz":"qux" pair. TEST_F(HookTest, VerifySlaveRunTaskHook) { Try<PID<Master>> master = StartMaster(); ASSERT_SOME(master); MockExecutor exec(DEFAULT_EXECUTOR_ID); TestContainerizer containerizer(&exec); Try<PID<Slave>> slave = StartSlave(&containerizer); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); ASSERT_EQ(1u, offers.get().size()); TaskInfo task; task.set_name(""); task.mutable_task_id()->set_value("1"); task.mutable_slave_id()->CopyFrom(offers.get()[0].slave_id()); task.mutable_resources()->CopyFrom(offers.get()[0].resources()); task.mutable_executor()->CopyFrom(DEFAULT_EXECUTOR_INFO); // Add two labels: (1) will be removed by the hook to ensure that // runTaskHook can remove labels (2) will be preserved to ensure // that the framework can add labels to the task and have those be // available by the end of the launch task sequence when hooks are // used (to protect against hooks removing labels completely). Labels* labels = task.mutable_labels(); Label* label1 = labels->add_labels(); label1->set_key("foo"); label1->set_value("bar"); Label* label2 = labels->add_labels(); label2->set_key("bar"); label2->set_value("baz"); vector<TaskInfo> tasks; tasks.push_back(task); EXPECT_CALL(exec, registered(_, _, _, _)); Future<TaskInfo> taskInfo; EXPECT_CALL(exec, launchTask(_, _)) .WillOnce(DoAll( FutureArg<1>(&taskInfo), SendStatusUpdateFromTask(TASK_RUNNING))); driver.launchTasks(offers.get()[0].id(), tasks); AWAIT_READY(taskInfo); // The master hook will hang an extra label off. const Labels& labels_ = taskInfo.get().labels(); ASSERT_EQ(3, labels_.labels_size()); // The slave run task hook will prepend a new "baz":"qux" label. EXPECT_EQ(labels_.labels(0).key(), "baz"); EXPECT_EQ(labels_.labels(0).value(), "qux"); // Master launch task hook will still hang off test label. EXPECT_EQ(labels_.labels(1).key(), testLabelKey); EXPECT_EQ(labels_.labels(1).value(), testLabelValue); // And lastly, we only expect the "foo":"bar" pair to be stripped by // the module. The last pair should be the original "bar":"baz" // pair set by the test. EXPECT_EQ(labels_.labels(2).key(), "bar"); EXPECT_EQ(labels_.labels(2).value(), "baz"); driver.stop(); driver.join(); Shutdown(); // Must shutdown before 'containerizer' gets deallocated. }
// Test executor environment decorator hook and remove executor hook // for slave. We expect the environment-decorator hook to create a // temporary file and the remove-executor hook to delete that file. TEST_F(HookTest, DISABLED_VerifySlaveLaunchExecutorHook) { master::Flags masterFlags = CreateMasterFlags(); Try<PID<Master>> master = StartMaster(masterFlags); ASSERT_SOME(master); slave::Flags slaveFlags = CreateSlaveFlags(); MockExecutor exec(DEFAULT_EXECUTOR_ID); TestContainerizer containerizer(&exec); Try<PID<Slave>> slave = StartSlave(&containerizer); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); // Launch a task with the command executor. TaskInfo task; task.set_name(""); task.mutable_task_id()->set_value("1"); task.mutable_slave_id()->CopyFrom(offers.get()[0].slave_id()); task.mutable_resources()->CopyFrom(offers.get()[0].resources()); task.mutable_executor()->CopyFrom(DEFAULT_EXECUTOR_INFO); vector<TaskInfo> tasks; tasks.push_back(task); EXPECT_CALL(exec, launchTask(_, _)); Future<ExecutorInfo> executorInfo; EXPECT_CALL(exec, registered(_, _, _, _)) .WillOnce(FutureArg<1>(&executorInfo)); // On successful completion of the "slaveLaunchExecutorHook", the // test hook will send a HookExecuted message to itself. We wait // until that message is intercepted by the testing infrastructure. Future<HookExecuted> hookFuture = FUTURE_PROTOBUF(HookExecuted(), _, _); driver.launchTasks(offers.get()[0].id(), tasks); AWAIT_READY(executorInfo); driver.stop(); driver.join(); Shutdown(); // Must shutdown before 'containerizer' gets deallocated. // Now wait for the hook to finish execution. AWAIT_READY(hookFuture); }
/*! \internal */ void QSqlResult::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy) { if (driver()->hasFeature(QSqlDriver::LowPrecisionNumbers)) virtual_hook(SetNumericalPrecision, &policy); }
int ClassifySeqsCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } string outputMethodTag = method; if(method == "wang"){ classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters, rand(), flip, writeShortcuts); } else if(method == "knn"){ classify = new Knn(taxonomyFileName, templateFileName, search, kmerSize, gapOpen, gapExtend, match, misMatch, numWanted, rand()); } else if(method == "zap"){ outputMethodTag = search + "_" + outputMethodTag; if (search == "kmer") { classify = new KmerTree(templateFileName, taxonomyFileName, kmerSize, cutoff); } else { classify = new AlignTree(templateFileName, taxonomyFileName, cutoff); } } else { m->mothurOut(search + " is not a valid method option. I will run the command using wang."); m->mothurOutEndLine(); classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters, rand(), flip, writeShortcuts); } if (m->control_pressed) { delete classify; return 0; } for (int s = 0; s < fastaFileNames.size(); s++) { m->mothurOut("Classifying sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine(); string baseTName = m->getSimpleName(taxonomyFileName); //set rippedTaxName to string RippedTaxName = ""; bool foundDot = false; for (int i = baseTName.length()-1; i >= 0; i--) { if (foundDot && (baseTName[i] != '.')) { RippedTaxName = baseTName[i] + RippedTaxName; } else if (foundDot && (baseTName[i] == '.')) { break; } else if (!foundDot && (baseTName[i] == '.')) { foundDot = true; } } //if (RippedTaxName != "") { RippedTaxName += "."; } if (outputDir == "") { outputDir += m->hasPath(fastaFileNames[s]); } map<string, string> variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])); variables["[tag]"] = RippedTaxName; variables["[tag2]"] = outputMethodTag; string newTaxonomyFile = getOutputFileName("taxonomy", variables); string newaccnosFile = getOutputFileName("accnos", variables); string tempTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "taxonomy.temp"; string taxSummary = getOutputFileName("taxsummary", variables); if ((method == "knn") && (search == "distance")) { string DistName = getOutputFileName("matchdist", variables); classify->setDistName(DistName); outputNames.push_back(DistName); outputTypes["matchdist"].push_back(DistName); } outputNames.push_back(newTaxonomyFile); outputTypes["taxonomy"].push_back(newTaxonomyFile); outputNames.push_back(taxSummary); outputTypes["taxsummary"].push_back(taxSummary); int start = time(NULL); int numFastaSeqs = 0; for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); vector<unsigned long long> positions; #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) positions = m->divideFile(fastaFileNames[s], processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); } #else if (processors == 1) { lines.push_back(new linePair(0, 1000)); }else { positions = m->setFilePosFasta(fastaFileNames[s], numFastaSeqs); if (numFastaSeqs < processors) { processors = numFastaSeqs; } //figure out how many sequences you have to process int numSeqsPerProcessor = numFastaSeqs / processors; for (int i = 0; i < processors; i++) { int startIndex = i * numSeqsPerProcessor; if(i == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor; } lines.push_back(new linePair(positions[startIndex], numSeqsPerProcessor)); } } #endif if(processors == 1){ numFastaSeqs = driver(lines[0], newTaxonomyFile, tempTaxonomyFile, newaccnosFile, fastaFileNames[s]); }else{ numFastaSeqs = createProcesses(newTaxonomyFile, tempTaxonomyFile, newaccnosFile, fastaFileNames[s]); } if (!m->isBlank(newaccnosFile)) { m->mothurOutEndLine(); m->mothurOut("[WARNING]: mothur reversed some your sequences for a better classification. If you would like to take a closer look, please check " + newaccnosFile + " for the list of the sequences."); m->mothurOutEndLine(); outputNames.push_back(newaccnosFile); outputTypes["accnos"].push_back(newaccnosFile); }else { m->mothurRemove(newaccnosFile); } m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to classify " + toString(numFastaSeqs) + " sequences."); m->mothurOutEndLine(); m->mothurOutEndLine(); start = time(NULL); //read namefile if(namefile != "") { m->mothurOut("Reading " + namefileNames[s] + "..."); cout.flush(); nameMap.clear(); //remove old names m->readNames(namefileNames[s], nameMap); m->mothurOut(" Done."); m->mothurOutEndLine(); } //output taxonomy with the unclassified bins added ifstream inTax; m->openInputFile(newTaxonomyFile, inTax); ofstream outTax; string unclass = newTaxonomyFile + ".unclass.temp"; m->openOutputFile(unclass, outTax); //get maxLevel from phylotree so you know how many 'unclassified's to add int maxLevel = classify->getMaxLevel(); //read taxfile - this reading and rewriting is done to preserve the confidence scores. string name, taxon; string group = ""; GroupMap* groupMap = NULL; CountTable* ct = NULL; PhyloSummary* taxaSum; if (hasCount) { ct = new CountTable(); ct->readTable(countfileNames[s], true, false); taxaSum = new PhyloSummary(ct, relabund, printlevel); }else { if (groupfile != "") { group = groupfileNames[s]; groupMap = new GroupMap(group); groupMap->readMap(); } taxaSum = new PhyloSummary(groupMap, relabund, printlevel); } while (!inTax.eof()) { if (m->control_pressed) { outputTypes.clear(); if (ct != NULL) { delete ct; } if (groupMap != NULL) { delete groupMap; } delete taxaSum; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete classify; return 0; } inTax >> name >> taxon; m->gobble(inTax); string newTax = m->addUnclassifieds(taxon, maxLevel, probs); outTax << name << '\t' << newTax << endl; if (namefile != "") { itNames = nameMap.find(name); if (itNames == nameMap.end()) { m->mothurOut(name + " is not in your name file please correct."); m->mothurOutEndLine(); exit(1); }else{ for (int i = 0; i < itNames->second.size(); i++) { taxaSum->addSeqToTree(itNames->second[i], newTax); //add it as many times as there are identical seqs } itNames->second.clear(); nameMap.erase(itNames->first); } }else { taxaSum->addSeqToTree(name, newTax); } } inTax.close(); outTax.close(); m->mothurRemove(newTaxonomyFile); rename(unclass.c_str(), newTaxonomyFile.c_str()); if (m->control_pressed) { outputTypes.clear(); if (ct != NULL) { delete ct; } if (groupMap != NULL) { delete groupMap; } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } delete classify; return 0; } //print summary file ofstream outTaxTree; m->openOutputFile(taxSummary, outTaxTree); taxaSum->print(outTaxTree, output); outTaxTree.close(); if (ct != NULL) { delete ct; } if (groupMap != NULL) { delete groupMap; } delete taxaSum; m->mothurRemove(tempTaxonomyFile); m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to create the summary file for " + toString(numFastaSeqs) + " sequences."); m->mothurOutEndLine(); m->mothurOutEndLine(); } delete classify; m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine(); //set taxonomy file as new current taxonomyfile string current = ""; itTypes = outputTypes.find("taxonomy"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setTaxonomyFile(current); } } current = ""; itTypes = outputTypes.find("accnos"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); } } return 0; } catch(exception& e) { m->errorOut(e, "ClassifySeqsCommand", "execute"); exit(1); } }
// Tests that the default container logger writes files into the sandbox. TEST_F(ContainerLoggerTest, DefaultToSandbox) { // Create a master, agent, and framework. Try<PID<Master>> master = StartMaster(); ASSERT_SOME(master); Future<SlaveRegisteredMessage> slaveRegisteredMessage = FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _); // We'll need access to these flags later. slave::Flags flags = CreateSlaveFlags(); Fetcher fetcher; // We use an actual containerizer + executor since we want something to run. Try<MesosContainerizer*> containerizer = MesosContainerizer::create(flags, false, &fetcher); CHECK_SOME(containerizer); Try<PID<Slave>> slave = StartSlave(containerizer.get(), flags); ASSERT_SOME(slave); AWAIT_READY(slaveRegisteredMessage); SlaveID slaveId = slaveRegisteredMessage.get().slave_id(); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); Future<FrameworkID> frameworkId; EXPECT_CALL(sched, registered(&driver, _, _)) .WillOnce(FutureArg<1>(&frameworkId)); // Wait for an offer, and start a task. Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(frameworkId); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); // We'll start a task that outputs to stdout. TaskInfo task = createTask(offers.get()[0], "echo 'Hello World!'"); Future<TaskStatus> status; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&status)) .WillRepeatedly(Return()); // Ignore subsequent updates. driver.launchTasks(offers.get()[0].id(), {task}); AWAIT_READY(status); EXPECT_EQ(TASK_RUNNING, status.get().state()); // Check that the sandbox was written to. string sandboxDirectory = path::join( slave::paths::getExecutorPath( flags.work_dir, slaveId, frameworkId.get(), status->executor_id()), "runs", "latest"); ASSERT_TRUE(os::exists(sandboxDirectory)); string stdoutPath = path::join(sandboxDirectory, "stdout"); ASSERT_TRUE(os::exists(stdoutPath)); Result<string> stdout = os::read(stdoutPath); ASSERT_SOME(stdout); EXPECT_TRUE(strings::contains(stdout.get(), "Hello World!")); driver.stop(); driver.join(); Shutdown(); }
bool CompilerEngine::compileCode(const QString &pCode) { // Prepend all the external functions that may, or not, be needed by the // given code // Note: indeed, we cannot include header files since we don't (and don't // want in order to avoid complications) deploy them with OpenCOR. So, // instead, we must declare as external functions all the functions // that we would normally use through header files... QString code = "extern double fabs(double);\n" "\n" "extern double log(double);\n" "extern double exp(double);\n" "\n" "extern double floor(double);\n" "extern double ceil(double);\n" "\n" "extern double factorial(double);\n" "\n" "extern double sin(double);\n" "extern double sinh(double);\n" "extern double asin(double);\n" "extern double asinh(double);\n" "\n" "extern double cos(double);\n" "extern double cosh(double);\n" "extern double acos(double);\n" "extern double acosh(double);\n" "\n" "extern double tan(double);\n" "extern double tanh(double);\n" "extern double atan(double);\n" "extern double atanh(double);\n" "\n" "extern double sec(double);\n" "extern double sech(double);\n" "extern double asec(double);\n" "extern double asech(double);\n" "\n" "extern double csc(double);\n" "extern double csch(double);\n" "extern double acsc(double);\n" "extern double acsch(double);\n" "\n" "extern double cot(double);\n" "extern double coth(double);\n" "extern double acot(double);\n" "extern double acoth(double);\n" "\n" "extern double arbitrary_log(double, double);\n" "\n" "extern double pow(double, double);\n" "\n" "extern double multi_min(int, ...);\n" "extern double multi_max(int, ...);\n" "\n" "extern double gcd_multi(int, ...);\n" "extern double lcm_multi(int, ...);\n" "\n" +pCode; // Reset our compiler engine reset(); // Determine our target triple // Note: normally, we would call llvm::sys::getProcessTriple(), but this // returns the information about the system on which LLVM was built. // In most cases it is fine, but on OS X it may be a problem. Indeed, // with OS X 10.9, Apple decided to extend the C standard by adding // some functions (e.g. __exp10()). So, if the given code needs one of // those functions, then OpenCOR will crash if run on an 'old' version // of OS X. So, to avoid this issue, we set the target triple // ourselves, based on the system on which OpenCOR is to be used... std::string targetTriple; #if defined(Q_OS_WIN) targetTriple = "x86_64-pc-windows-msvc-elf"; // Note: MCJIT currently works only through the ELF object format, hence we // are appending "-elf"... #elif defined(Q_OS_LINUX) targetTriple = "x86_64-pc-linux-gnu"; #elif defined(Q_OS_MAC) targetTriple = "x86_64-apple-darwin"+std::to_string(QSysInfo::MacintoshVersion+2); #else #error Unsupported platform #endif // Get a driver to compile our code llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagnosticOptions = new clang::DiagnosticOptions(); clang::DiagnosticsEngine diagnosticsEngine(llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>(new clang::DiagnosticIDs()), &*diagnosticOptions); clang::driver::Driver driver("clang", targetTriple, diagnosticsEngine); driver.setCheckInputsExist(false); // Get a compilation object to which we pass some arguments llvm::StringRef dummyFileName("dummyFile.c"); llvm::SmallVector<const char *, 16> compilationArguments; compilationArguments.push_back("clang"); compilationArguments.push_back("-fsyntax-only"); compilationArguments.push_back("-O3"); compilationArguments.push_back("-ffast-math"); compilationArguments.push_back("-Werror"); compilationArguments.push_back(dummyFileName.data()); std::unique_ptr<clang::driver::Compilation> compilation(driver.BuildCompilation(compilationArguments)); if (!compilation) { mError = tr("the compilation object could not be created"); return false; } // The compilation object should have only one command, so if it doesn't // then something went wrong const clang::driver::JobList &jobList = compilation->getJobs(); if ( (jobList.size() != 1) || !llvm::isa<clang::driver::Command>(*jobList.begin())) { mError = tr("the compilation object must contain only one command"); return false; } // Retrieve the command job const clang::driver::Command &command = llvm::cast<clang::driver::Command>(*jobList.begin()); QString commandName = command.getCreator().getName(); if (commandName.compare("clang")) { mError = tr("a <strong>clang</strong> command was expected, but a <strong>%1</strong> command was found instead").arg(commandName); return false; } // Create a compiler invocation using our command's arguments const clang::driver::ArgStringList &commandArguments = command.getArguments(); std::unique_ptr<clang::CompilerInvocation> compilerInvocation(new clang::CompilerInvocation()); clang::CompilerInvocation::CreateFromArgs(*compilerInvocation, commandArguments.data(), commandArguments.data()+commandArguments.size(), diagnosticsEngine); // Map our dummy file to a memory buffer QByteArray codeByteArray = code.toUtf8(); compilerInvocation->getPreprocessorOpts().addRemappedFile(dummyFileName, llvm::MemoryBuffer::getMemBuffer(codeByteArray.constData()).release()); // Create a compiler instance to handle the actual work clang::CompilerInstance compilerInstance; compilerInstance.setInvocation(compilerInvocation.release()); // Create the compiler instance's diagnostics engine compilerInstance.createDiagnostics(); if (!compilerInstance.hasDiagnostics()) { mError = tr("the diagnostics engine could not be created"); return false; } // Create and execute the frontend to generate an LLVM bitcode module std::unique_ptr<clang::CodeGenAction> codeGenerationAction(new clang::EmitLLVMOnlyAction(&llvm::getGlobalContext())); if (!compilerInstance.ExecuteAction(*codeGenerationAction)) { mError = tr("the code could not be compiled"); reset(false); return false; } // Retrieve the LLVM bitcode module std::unique_ptr<llvm::Module> module = codeGenerationAction->takeModule(); // Initialise the native target (and its ASM printer), so not only can we // then create an execution engine, but more importantly its data layout // will match that of our target platform llvm::InitializeNativeTarget(); llvm::InitializeNativeTargetAsmPrinter(); // Create and keep track of an execution engine mExecutionEngine = std::unique_ptr<llvm::ExecutionEngine>(llvm::EngineBuilder(std::move(module)).setEngineKind(llvm::EngineKind::JIT).create()); if (!mExecutionEngine) { mError = tr("the execution engine could not be created"); delete module.release(); return false; } // Map all the external functions that may, or not, be needed by the given // code #if defined(Q_OS_WIN) || defined(Q_OS_LINUX) #define FUNCTION_NAME(x) (x) #elif defined(Q_OS_MAC) #define FUNCTION_NAME(x) (std::string(std::string("_")+(x)).c_str()) #else #error Unsupported platform #endif mExecutionEngine->addGlobalMapping(FUNCTION_NAME("fabs"), (uint64_t) compiler_fabs); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("log"), (uint64_t) compiler_log); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("exp"), (uint64_t) compiler_exp); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("floor"), (uint64_t) compiler_floor); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("ceil"), (uint64_t) compiler_ceil); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("factorial"), (uint64_t) compiler_factorial); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("sin"), (uint64_t) compiler_sin); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("sinh"), (uint64_t) compiler_sinh); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("asin"), (uint64_t) compiler_asin); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("asinh"), (uint64_t) compiler_asinh); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("cos"), (uint64_t) compiler_cos); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("cosh"), (uint64_t) compiler_cosh); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("acos"), (uint64_t) compiler_acos); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("acosh"), (uint64_t) compiler_acosh); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("tan"), (uint64_t) compiler_tan); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("tanh"), (uint64_t) compiler_tanh); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("atan"), (uint64_t) compiler_atan); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("atanh"), (uint64_t) compiler_atanh); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("sec"), (uint64_t) compiler_sec); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("sech"), (uint64_t) compiler_sech); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("asec"), (uint64_t) compiler_asec); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("asech"), (uint64_t) compiler_asech); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("csc"), (uint64_t) compiler_csc); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("csch"), (uint64_t) compiler_csch); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("acsc"), (uint64_t) compiler_acsc); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("acsch"), (uint64_t) compiler_acsch); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("cot"), (uint64_t) compiler_cot); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("coth"), (uint64_t) compiler_coth); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("acot"), (uint64_t) compiler_acot); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("acoth"), (uint64_t) compiler_acoth); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("arbitrary_log"), (uint64_t) compiler_arbitrary_log); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("pow"), (uint64_t) compiler_pow); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("multi_min"), (uint64_t) compiler_multi_min); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("multi_max"), (uint64_t) compiler_multi_max); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("gcd_multi"), (uint64_t) compiler_gcd_multi); mExecutionEngine->addGlobalMapping(FUNCTION_NAME("lcm_multi"), (uint64_t) compiler_lcm_multi); return true; }
int main(int argc, char** argv) { std::string working_directory = ""; std::string decomp_method = ""; std::string mesh = ""; std::string type = "exodusii"; int id_integer_size = 4; bool create_faces = false; bool create_edges = false; bool create_skin = false; //---------------------------------- // Process the broadcast command line arguments stk::ParallelMachine comm = stk::parallel_machine_init(&argc, &argv); stk::BroadcastArg b_arg(comm, argc, argv); bopt::options_description desc("options"); desc.add_options() ("help,h", "produce help message") ("directory,d", bopt::value<std::string>(&working_directory), "working directory with trailing '/'" ) ("decomposition,D", bopt::value<std::string>(&decomp_method), "decomposition method. One of: linear, rcb, rib, hsfc, block, cyclic, random, kway, geom_kway, metis_sfc" ) ("faces", "create all faces" ) ("edges", "create all edges" ) ("skin", "create all boundary faces (skin of the model)" ) ("id_integer_size", bopt::value<int>(&id_integer_size), "use 4 or 8-byte integers for ids" ) ("mesh", bopt::value<std::string>(&mesh), "mesh file. Use name of form 'gen:NxMxL' to internally generate a hex mesh of size N by M by L intervals. See GeneratedMesh documentation for more options. Can also specify a filename." ); stk::get_options_description().add(desc); bopt::variables_map &vm = stk::get_variables_map(); try { bopt::store(bopt::parse_command_line(b_arg.m_argc, b_arg.m_argv, desc), vm); bopt::notify(vm); } catch (std::exception & /* x */) { std::exit(1); } if (mesh.empty()) { std::cerr << "\nERROR: The --mesh option is required\n"; std::cerr << "\nApplication " << desc << "\n"; std::exit(EXIT_FAILURE); } if (vm.count("help")) { std::cout << "Usage: " << argv[0] << " " << desc << "\n"; std::exit(EXIT_SUCCESS); } if (vm.count("faces")) {create_faces = true;} if (vm.count("edges")) {create_edges = true;} if (vm.count("skin")) {create_skin = true;} type = "exodusii"; if (strncasecmp("gen:", mesh.c_str(), 4) == 0) { mesh = mesh.substr(4, mesh.size()); type = "generated"; } if (strncasecmp("dof:", mesh.c_str(), 4) == 0) { mesh = mesh.substr(4, mesh.size()); type = "dof"; } driver(comm, working_directory, mesh, type, decomp_method, create_edges, create_faces, create_skin, id_integer_size); stk::parallel_machine_finalize(); return 0; }
int correctDist::createProcess(string distanceFileName){ try { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) int process = 1; vector<int> processIDs; bool recalc = false; while(process != processors){ pid_t pid = fork(); if(pid > 0){ processIDs.push_back(pid); process++; } else if(pid == 0){ driver(start[process], end[process], distanceFileName + m->mothurGetpid(process) + ".temp"); exit(0); } else{ m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; for (int i = 0; i < processIDs.size(); i++) { kill (processIDs[i], SIGINT); } //wait to die for (int i=0;i<processIDs.size();i++) { int temp = processIDs[i]; wait(&temp); } m->control_pressed = false; recalc = true; break; } } if (recalc) { start.clear(); end.clear(); for(int i=0;i<processors;i++){ start.push_back(int (sqrt(float(i)/float(processors)) * numSeqs)); end.push_back(int (sqrt(float(i+1)/float(processors)) * numSeqs)); } processIDs.resize(0); process = 1; while(process != processors){ pid_t pid = fork(); if(pid > 0){ processIDs.push_back(pid); process++; } else if(pid == 0){ driver(start[process], end[process], distanceFileName + m->mothurGetpid(process) + ".temp"); exit(0); } else{ m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); for (int i=0;i<processIDs.size();i++) { int temp = processIDs[i]; kill(temp, SIGINT); } exit(0); } } } driver(start[0], end[0], distanceFileName); for (int i=0;i<processIDs.size();i++) { int temp = processIDs[i]; wait(&temp); } for(int i=0;i<processIDs.size();i++){ m->appendFiles((distanceFileName + toString(processIDs[i]) + ".temp"), distanceFileName); remove((distanceFileName + toString(processIDs[i]) + ".temp").c_str()); } #endif return 0; } catch(exception& e) { m->errorOut(e, "correctDist", "createProcess"); exit(1); } }
int AlignCommand::createProcesses(string alignFileName, string reportFileName, string accnosFName, string filename) { try { int num = 0; processIDS.resize(0); bool recalc = false; #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) int process = 1; //loop through and create all the processes you want while (process != processors) { pid_t pid = fork(); if (pid > 0) { processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ num = driver(lines[process], alignFileName + toString(m->mothurGetpid(process)) + ".temp", reportFileName + toString(m->mothurGetpid(process)) + ".temp", accnosFName + m->mothurGetpid(process) + ".temp", filename); //pass numSeqs to parent ofstream out; string tempFile = alignFileName + toString(m->mothurGetpid(process)) + ".num.temp"; m->openOutputFile(tempFile, out); out << num << endl; out.close(); exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } //wait to die for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; wait(&temp); } m->control_pressed = false; recalc = true; break; } } if (recalc) { //test line, also set recalc to true. //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; wait(&temp); } m->control_pressed = false; processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); vector<unsigned long long> positions; positions = m->divideFile(filename, processors); for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(new linePair(positions[i], positions[(i+1)])); } num = 0; processIDS.resize(0); process = 1; while (process != processors) { pid_t pid = fork(); if (pid > 0) { processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ num = driver(lines[process], alignFileName + toString(m->mothurGetpid(process)) + ".temp", reportFileName + toString(m->mothurGetpid(process)) + ".temp", accnosFName + m->mothurGetpid(process) + ".temp", filename); //pass numSeqs to parent ofstream out; string tempFile = alignFileName + toString(m->mothurGetpid(process)) + ".num.temp"; m->openOutputFile(tempFile, out); out << num << endl; out.close(); exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } exit(0); } } } //do my part num = driver(lines[0], alignFileName, reportFileName, accnosFName, filename); //force parent to wait until all the processes are done for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; wait(&temp); } vector<string> nonBlankAccnosFiles; if (!(m->isBlank(accnosFName))) { nonBlankAccnosFiles.push_back(accnosFName); } else { m->mothurRemove(accnosFName); } //remove so other files can be renamed to it for (int i = 0; i < processIDS.size(); i++) { ifstream in; string tempFile = alignFileName + toString(processIDS[i]) + ".num.temp"; m->openInputFile(tempFile, in); if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; } in.close(); m->mothurRemove(tempFile); m->appendFiles((alignFileName + toString(processIDS[i]) + ".temp"), alignFileName); m->mothurRemove((alignFileName + toString(processIDS[i]) + ".temp")); appendReportFiles((reportFileName + toString(processIDS[i]) + ".temp"), reportFileName); m->mothurRemove((reportFileName + toString(processIDS[i]) + ".temp")); if (!(m->isBlank(accnosFName + toString(processIDS[i]) + ".temp"))) { nonBlankAccnosFiles.push_back(accnosFName + toString(processIDS[i]) + ".temp"); }else { m->mothurRemove((accnosFName + toString(processIDS[i]) + ".temp")); } } //append accnos files if (nonBlankAccnosFiles.size() != 0) { rename(nonBlankAccnosFiles[0].c_str(), accnosFName.c_str()); for (int h=1; h < nonBlankAccnosFiles.size(); h++) { m->appendFiles(nonBlankAccnosFiles[h], accnosFName); m->mothurRemove(nonBlankAccnosFiles[h]); } }else { //recreate the accnosfile if needed ofstream out; m->openOutputFile(accnosFName, out); out.close(); } #else ////////////////////////////////////////////////////////////////////////////////////////////////////// //Windows version shared memory, so be careful when passing variables through the alignData struct. //Above fork() will clone, so memory is separate, but that's not the case with windows, ////////////////////////////////////////////////////////////////////////////////////////////////////// vector<alignData*> pDataArray; DWORD dwThreadIdArray[processors-1]; HANDLE hThreadArray[processors-1]; //Create processor worker threads. for( int i=0; i<processors-1; i++ ){ //copy templateDb //AlignmentDB* tempDB = new AlignmentDB(*templateDB); // Allocate memory for thread data. string extension = ""; if (i != 0) { extension = toString(i) + ".temp"; } alignData* tempalign = new alignData(templateFileName, (alignFileName + extension), (reportFileName + extension), (accnosFName + extension), filename, align, search, kmerSize, m, lines[i]->start, lines[i]->end, flip, match, misMatch, gapOpen, gapExtend, threshold, i); pDataArray.push_back(tempalign); processIDS.push_back(i); //MySeqSumThreadFunction is in header. It must be global or static to work with the threads. //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier hThreadArray[i] = CreateThread(NULL, 0, MyAlignThreadFunction, pDataArray[i], 0, &dwThreadIdArray[i]); } //need to check for line ending error ifstream inFASTA; m->openInputFile(filename, inFASTA); inFASTA.seekg(lines[processors-1]->start-1); char c = inFASTA.peek(); if (c != '>') { //we need to move back lines[processors-1]->start--; } //using the main process as a worker saves time and memory //do my part - do last piece because windows is looking for eof num = driver(lines[processors-1], (alignFileName + toString(processors-1) + ".temp"), (reportFileName + toString(processors-1) + ".temp"), (accnosFName + toString(processors-1) + ".temp"), filename); //Wait until all threads have terminated. WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE); //Close all thread handles and free memory allocations. for(int i=0; i < pDataArray.size(); i++){ if (pDataArray[i]->count != pDataArray[i]->end) { m->mothurOut("[ERROR]: process " + toString(i) + " only processed " + toString(pDataArray[i]->count) + " of " + toString(pDataArray[i]->end) + " sequences assigned to it, quitting. \n"); m->control_pressed = true; } num += pDataArray[i]->count; CloseHandle(hThreadArray[i]); delete pDataArray[i]; } vector<string> nonBlankAccnosFiles; if (!(m->isBlank(accnosFName))) { nonBlankAccnosFiles.push_back(accnosFName); } else { m->mothurRemove(accnosFName); } //remove so other files can be renamed to it for (int i = 1; i < processors; i++) { m->appendFiles((alignFileName + toString(i) + ".temp"), alignFileName); m->mothurRemove((alignFileName + toString(i) + ".temp")); appendReportFiles((reportFileName + toString(i) + ".temp"), reportFileName); m->mothurRemove((reportFileName + toString(i) + ".temp")); if (!(m->isBlank(accnosFName + toString(i) + ".temp"))) { nonBlankAccnosFiles.push_back(accnosFName + toString(i) + ".temp"); }else { m->mothurRemove((accnosFName + toString(i) + ".temp")); } } //append accnos files if (nonBlankAccnosFiles.size() != 0) { rename(nonBlankAccnosFiles[0].c_str(), accnosFName.c_str()); for (int h=1; h < nonBlankAccnosFiles.size(); h++) { m->appendFiles(nonBlankAccnosFiles[h], accnosFName); m->mothurRemove(nonBlankAccnosFiles[h]); } }else { //recreate the accnosfile if needed ofstream out; m->openOutputFile(accnosFName, out); out.close(); } #endif return num; }
EstOutput Unweighted::createProcesses(Tree* t, vector< vector<string> > namesOfGroupCombos, CountTable* ct) { try { int process = 1; vector<int> processIDS; bool recalc = false; EstOutput results; #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) //loop through and create all the processes you want while (process != processors) { pid_t pid = fork(); if (pid > 0) { processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ EstOutput myresults; myresults = driver(t, namesOfGroupCombos, lines[process].start, lines[process].num, ct); if (m->control_pressed) { exit(0); } //pass numSeqs to parent ofstream out; string tempFile = outputDir + m->mothurGetpid(process) + ".unweighted.results.temp"; m->openOutputFile(tempFile, out); out << myresults.size() << endl; for (int i = 0; i < myresults.size(); i++) { out << myresults[i] << '\t'; } out << endl; out.close(); exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process; for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } //wait to die for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; wait(&temp); } m->control_pressed = false; for (int i=0;i<processIDS.size();i++) { m->mothurRemove(outputDir + (toString(processIDS[i]) + ".unweighted.results.temp")); } recalc = true; break; } } if (recalc) { //test line, also set recalc to true. //for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } for (int i=0;i<processIDS.size();i++) { int temp = processIDS[i]; wait(&temp); } m->control_pressed = false; for (int i=0;i<processIDS.size();i++) {m->mothurRemove(outputDir + (toString(processIDS[i]) + ".unweighted.results.temp"));}processors=3; m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(processors) + "\n"); //if the users enters no groups then give them the score of all groups int numGroups = m->getNumGroups(); //calculate number of comparsions int numComp = 0; vector< vector<string> > namesOfGroupCombos; for (int r=0; r<numGroups; r++) { for (int l = 0; l < r; l++) { numComp++; vector<string> groups; groups.push_back((m->getGroups())[r]); groups.push_back((m->getGroups())[l]); namesOfGroupCombos.push_back(groups); } } if (numComp != 1) { vector<string> groups; if (numGroups == 0) { //get score for all users groups for (int i = 0; i < (ct->getNamesOfGroups()).size(); i++) { if ((ct->getNamesOfGroups())[i] != "xxx") { groups.push_back((ct->getNamesOfGroups())[i]); } } namesOfGroupCombos.push_back(groups); }else { for (int i = 0; i < m->getNumGroups(); i++) { groups.push_back((m->getGroups())[i]); } namesOfGroupCombos.push_back(groups); } } lines.clear(); int remainingPairs = namesOfGroupCombos.size(); int startIndex = 0; for (int remainingProcessors = processors; remainingProcessors > 0; remainingProcessors--) { int numPairs = remainingPairs; //case for last processor if (remainingProcessors != 1) { numPairs = ceil(remainingPairs / remainingProcessors); } lines.push_back(linePair(startIndex, numPairs)); //startIndex, numPairs startIndex = startIndex + numPairs; remainingPairs = remainingPairs - numPairs; } results.clear(); processIDS.resize(0); process = 1; //loop through and create all the processes you want while (process != processors) { pid_t pid = fork(); if (pid > 0) { processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later process++; }else if (pid == 0){ EstOutput myresults; myresults = driver(t, namesOfGroupCombos, lines[process].start, lines[process].num, ct); if (m->control_pressed) { exit(0); } //pass numSeqs to parent ofstream out; string tempFile = outputDir + m->mothurGetpid(process) + ".unweighted.results.temp"; m->openOutputFile(tempFile, out); out << myresults.size() << endl; for (int i = 0; i < myresults.size(); i++) { out << myresults[i] << '\t'; } out << endl; out.close(); exit(0); }else { m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); } exit(0); } } } results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num, ct); //force parent to wait until all the processes are done for (int i=0;i<(processors-1);i++) { int temp = processIDS[i]; wait(&temp); } if (m->control_pressed) { return results; } //get data created by processes for (int i=0;i<(processors-1);i++) { ifstream in; string s = outputDir + toString(processIDS[i]) + ".unweighted.results.temp"; m->openInputFile(s, in); //get quantiles if (!in.eof()) { int num; in >> num; m->gobble(in); if (m->control_pressed) { break; } double w; for (int j = 0; j < num; j++) { in >> w; results.push_back(w); } m->gobble(in); } in.close(); m->mothurRemove(s); } #else //fill in functions vector<unweightedData*> pDataArray; DWORD dwThreadIdArray[processors-1]; HANDLE hThreadArray[processors-1]; vector<CountTable*> cts; vector<Tree*> trees; //Create processor worker threads. for( int i=1; i<processors; i++ ){ CountTable* copyCount = new CountTable(); copyCount->copy(ct); Tree* copyTree = new Tree(copyCount); copyTree->getCopy(t); cts.push_back(copyCount); trees.push_back(copyTree); unweightedData* tempweighted = new unweightedData(m, lines[i].start, lines[i].num, namesOfGroupCombos, copyTree, copyCount, includeRoot); pDataArray.push_back(tempweighted); processIDS.push_back(i); hThreadArray[i-1] = CreateThread(NULL, 0, MyUnWeightedThreadFunction, pDataArray[i-1], 0, &dwThreadIdArray[i-1]); } results = driver(t, namesOfGroupCombos, lines[0].start, lines[0].num, ct); //Wait until all threads have terminated. WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE); //Close all thread handles and free memory allocations. for(int i=0; i < pDataArray.size(); i++){ for (int j = 0; j < pDataArray[i]->results.size(); j++) { results.push_back(pDataArray[i]->results[j]); } delete cts[i]; delete trees[i]; CloseHandle(hThreadArray[i]); delete pDataArray[i]; } #endif return results; }
// Test that memory pressure listening is restarted after recovery. TEST_F(MemoryPressureMesosTest, ROOT_CGROUPS_SlaveRecovery) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); slave::Flags flags = CreateSlaveFlags(); // We only care about memory cgroup for this test. flags.isolation = "cgroups/mem"; Fetcher fetcher(flags); Try<MesosContainerizer*> _containerizer = MesosContainerizer::create(flags, true, &fetcher); ASSERT_SOME(_containerizer); Owned<MesosContainerizer> containerizer(_containerizer.get()); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), containerizer.get(), flags); ASSERT_SOME(slave); MockScheduler sched; // Enable checkpointing for the framework. FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO; frameworkInfo.set_checkpoint(true); MesosSchedulerDriver driver( &sched, frameworkInfo, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(_, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(_, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); ASSERT_FALSE(offers->empty()); Offer offer = offers.get()[0]; // Run a task that triggers memory pressure event. We request 1G // disk because we are going to write a 512 MB file repeatedly. TaskInfo task = createTask( offer.slave_id(), Resources::parse("cpus:1;mem:256;disk:1024").get(), "while true; do dd count=512 bs=1M if=/dev/zero of=./temp; done"); Future<TaskStatus> starting; Future<TaskStatus> running; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&starting)) .WillOnce(FutureArg<1>(&running)) .WillRepeatedly(Return()); // Ignore subsequent updates. Future<Nothing> runningAck = FUTURE_DISPATCH(_, &Slave::_statusUpdateAcknowledgement); Future<Nothing> startingAck = FUTURE_DISPATCH(_, &Slave::_statusUpdateAcknowledgement); driver.launchTasks(offers.get()[0].id(), {task}); AWAIT_READY(starting); EXPECT_EQ(task.task_id(), starting->task_id()); EXPECT_EQ(TASK_STARTING, starting->state()); AWAIT_READY_FOR(startingAck, Seconds(120)); AWAIT_READY(running); EXPECT_EQ(task.task_id(), running->task_id()); EXPECT_EQ(TASK_RUNNING, running->state()); // Wait for the ACK to be checkpointed. AWAIT_READY_FOR(runningAck, Seconds(120)); // We restart the slave to let it recover. slave.get()->terminate(); // Set up so we can wait until the new slave updates the container's // resources (this occurs after the executor has reregistered). Future<Nothing> update = FUTURE_DISPATCH(_, &MesosContainerizerProcess::update); // Use the same flags. _containerizer = MesosContainerizer::create(flags, true, &fetcher); ASSERT_SOME(_containerizer); containerizer.reset(_containerizer.get()); Future<SlaveReregisteredMessage> reregistered = FUTURE_PROTOBUF(SlaveReregisteredMessage(), master.get()->pid, _); slave = StartSlave(detector.get(), containerizer.get(), flags); ASSERT_SOME(slave); AWAIT_READY(reregistered); // Wait until the containerizer is updated. AWAIT_READY(update); Future<hashset<ContainerID>> containers = containerizer->containers(); AWAIT_READY(containers); ASSERT_EQ(1u, containers->size()); ContainerID containerId = *(containers->begin()); // Wait a while for some memory pressure events to occur. Duration waited = Duration::zero(); do { Future<ResourceStatistics> usage = containerizer->usage(containerId); AWAIT_READY(usage); if (usage->mem_low_pressure_counter() > 0) { // We will check the correctness of the memory pressure counters // later, because the memory-hammering task is still active // and potentially incrementing these counters. break; } os::sleep(Milliseconds(100)); waited += Milliseconds(100); } while (waited < Seconds(5)); EXPECT_LE(waited, Seconds(5)); // Pause the clock to ensure that the reaper doesn't reap the exited // command executor and inform the containerizer/slave. Clock::pause(); Clock::settle(); Future<TaskStatus> killed; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&killed)); // Stop the memory-hammering task. driver.killTask(task.task_id()); AWAIT_READY_FOR(killed, Seconds(120)); EXPECT_EQ(task.task_id(), killed->task_id()); EXPECT_EQ(TASK_KILLED, killed->state()); // Now check the correctness of the memory pressure counters. Future<ResourceStatistics> usage = containerizer->usage(containerId); AWAIT_READY(usage); EXPECT_GE(usage->mem_low_pressure_counter(), usage->mem_medium_pressure_counter()); EXPECT_GE(usage->mem_medium_pressure_counter(), usage->mem_critical_pressure_counter()); Clock::resume(); driver.stop(); driver.join(); }
int PBGameInfo::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = gameId(); break; case 1: *reinterpret_cast< QString*>(_v) = tableId(); break; case 2: *reinterpret_cast< QString*>(_v) = tourneyTableId(); break; case 3: *reinterpret_cast< QString*>(_v) = siteId(); break; case 4: *reinterpret_cast< int*>(_v) = canJoin(); break; case 5: *reinterpret_cast< QString*>(_v) = gameFamily(); break; case 6: *reinterpret_cast< double*>(_v) = smallBlind(); break; case 7: *reinterpret_cast< double*>(_v) = bigBlind(); break; case 8: *reinterpret_cast< int*>(_v) = maxSeats(); break; case 9: *reinterpret_cast< QString*>(_v) = driver(); break; case 10: *reinterpret_cast< int*>(_v) = canOpen(); break; case 11: *reinterpret_cast< int*>(_v) = openedTablesCount(); break; case 12: *reinterpret_cast< int*>(_v) = tablesMax(); break; case 13: *reinterpret_cast< int*>(_v) = tableOpened(); break; case 14: *reinterpret_cast< int*>(_v) = tourneyOpened(); break; case 15: *reinterpret_cast< int*>(_v) = gameComplete(); break; } _id -= 16; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setGameId(*reinterpret_cast< QString*>(_v)); break; case 1: setTableId(*reinterpret_cast< QString*>(_v)); break; case 2: setTourneyTableId(*reinterpret_cast< QString*>(_v)); break; case 3: setSiteId(*reinterpret_cast< QString*>(_v)); break; case 4: setCanJoin(*reinterpret_cast< int*>(_v)); break; case 5: setGameFamily(*reinterpret_cast< QString*>(_v)); break; case 6: setSmallBlind(*reinterpret_cast< double*>(_v)); break; case 7: setBigBlind(*reinterpret_cast< double*>(_v)); break; case 8: setMaxSeats(*reinterpret_cast< int*>(_v)); break; case 9: setDriver(*reinterpret_cast< QString*>(_v)); break; case 10: setCanOpen(*reinterpret_cast< int*>(_v)); break; case 11: setOpenedTablesCount(*reinterpret_cast< int*>(_v)); break; case 12: setTablesMax(*reinterpret_cast< int*>(_v)); break; case 13: setTableOpened(*reinterpret_cast< int*>(_v)); break; case 14: setTourneyOpened(*reinterpret_cast< int*>(_v)); break; case 15: setGameComplete(*reinterpret_cast< int*>(_v)); break; } _id -= 16; } else if (_c == QMetaObject::ResetProperty) { _id -= 16; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 16; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 16; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 16; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 16; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 16; } #endif // QT_NO_PROPERTIES return _id; }