/** * In case BOOST_COMPUTE_USE_OFFLINE_CACHE macro is defined, * the compiled binary is stored for reuse in the offline cache located in * $HOME/.boost_compute on UNIX-like systems and in %APPDATA%/boost_compute * on Windows. */ static program build_with_source( const std::string &source, const context &context, const std::string &options = std::string() ) { #ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE // Get hash string for the kernel. std::string hash; { device d(context.get_device()); platform p(d.get_info<cl_platform_id>(CL_DEVICE_PLATFORM)); std::ostringstream src; src << "// " << p.name() << " v" << p.version() << "\n" << "// " << context.get_device().name() << "\n" << "// " << options << "\n\n" << source; hash = detail::sha1(src.str()); } // Try to get cached program binaries: try { boost::optional<program> prog = load_program_binary(hash, context); if (prog) { prog->build(options); return *prog; } } catch (...) { // Something bad happened. Fallback to normal compilation. } // Cache is apparently not available. Just compile the sources. #endif const char *source_string = source.c_str(); cl_int error = 0; cl_program program_ = clCreateProgramWithSource(context, uint_(1), &source_string, 0, &error); if(!program_){ BOOST_THROW_EXCEPTION(runtime_exception(error)); } program prog(program_, false); prog.build(options); #ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE // Save program binaries for future reuse. save_program_binary(hash, prog); #endif return prog; }
/** * Executes the algorithm * */ void ConvertToConstantL2::exec() { initWorkspaces(); // Calculate the number of spectra in this workspace const size_t numberOfSpectra = m_inputWS->getNumberHistograms(); API::Progress prog(this, 0.0, 1.0, numberOfSpectra); int64_t numberOfSpectra_i = static_cast<int64_t>(numberOfSpectra); // cast to make openmp happy const auto &inputSpecInfo = m_inputWS->spectrumInfo(); auto &outputDetInfo = m_outputWS->mutableDetectorInfo(); // Loop over the histograms (detector spectra) PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWS, *m_outputWS)) for (int64_t i = 0; i < numberOfSpectra_i; ++i) { PARALLEL_START_INTERUPT_REGION m_outputWS->setHistogram(i, m_inputWS->histogram(i)); // Should not move the monitors if (inputSpecInfo.isMonitor(i)) continue; // Throw if detector doesn't exist or is a group if (!inputSpecInfo.hasUniqueDetector(i)) { const auto errorMsg = boost::format("The detector for spectrum number %d was either not " "found, or is a group.") % i; throw std::runtime_error(errorMsg.str()); } // subract the diference in l2 double thisDetL2 = inputSpecInfo.l2(i); double deltaL2 = std::abs(thisDetL2 - m_l2); double deltaTOF = calculateTOF(deltaL2); deltaTOF *= 1e6; // micro sec // position - set all detector distance to constant l2 double r, theta, phi; V3D oldPos = inputSpecInfo.position(i); oldPos.getSpherical(r, theta, phi); V3D newPos; newPos.spherical(m_l2, theta, phi); const auto detIndex = inputSpecInfo.spectrumDefinition(i)[0]; outputDetInfo.setPosition(detIndex, newPos); m_outputWS->mutableX(i) -= deltaTOF; prog.report("Aligning elastic line..."); PARALLEL_END_INTERUPT_REGION } // end for i PARALLEL_CHECK_INTERUPT_REGION this->setProperty("OutputWorkspace", this->m_outputWS); }
void TLDDetector::ocl_batchSrSc(const Mat_<uchar>& patches, double *resultSr, double *resultSc, int numOfPatches) { UMat devPatches = patches.getUMat(ACCESS_READ, USAGE_ALLOCATE_DEVICE_MEMORY); UMat devPositiveSamples = posExp->getUMat(ACCESS_READ, USAGE_ALLOCATE_DEVICE_MEMORY); UMat devNegativeSamples = negExp->getUMat(ACCESS_READ, USAGE_ALLOCATE_DEVICE_MEMORY); UMat devPosNCC(MAX_EXAMPLES_IN_MODEL, numOfPatches, CV_32FC1, ACCESS_RW, USAGE_ALLOCATE_DEVICE_MEMORY); UMat devNegNCC(MAX_EXAMPLES_IN_MODEL, numOfPatches, CV_32FC1, ACCESS_RW, USAGE_ALLOCATE_DEVICE_MEMORY); ocl::Kernel k; ocl::ProgramSource src = ocl::tracking::tldDetector_oclsrc; String error; ocl::Program prog(src, String(), error); k.create("batchNCC", prog); if (k.empty()) printf("Kernel create failed!!!\n"); k.args( ocl::KernelArg::PtrReadOnly(devPatches), ocl::KernelArg::PtrReadOnly(devPositiveSamples), ocl::KernelArg::PtrReadOnly(devNegativeSamples), ocl::KernelArg::PtrWriteOnly(devPosNCC), ocl::KernelArg::PtrWriteOnly(devNegNCC), *posNum, *negNum, numOfPatches); size_t globSize = 2 * numOfPatches*MAX_EXAMPLES_IN_MODEL; if (!k.run(1, &globSize, NULL, true)) printf("Kernel Run Error!!!"); Mat posNCC = devPosNCC.getMat(ACCESS_READ); Mat negNCC = devNegNCC.getMat(ACCESS_READ); //Calculate Srs for (int id = 0; id < numOfPatches; id++) { double spr = 0.0, smr = 0.0, spc = 0.0, smc = 0; int med = getMedian((*timeStampsPositive)); for (int i = 0; i < *posNum; i++) { spr = std::max(spr, 0.5 * (posNCC.at<float>(id * 500 + i) + 1.0)); if ((int)(*timeStampsPositive)[i] <= med) spc = std::max(spr, 0.5 * (posNCC.at<float>(id * 500 + i) + 1.0)); } for (int i = 0; i < *negNum; i++) smc = smr = std::max(smr, 0.5 * (negNCC.at<float>(id * 500 + i) + 1.0)); if (spr + smr == 0.0) resultSr[id] = 0.0; else resultSr[id] = spr / (smr + spr); if (spc + smc == 0.0) resultSc[id] = 0.0; else resultSc[id] = spc / (smc + spc); } }
static Program make(void) { Program prog(ObjectDesc("Flare")); prog.AttachShader(FlareVertShader()); prog.AttachShader(FlareGeomShader()); prog.AttachShader(FlareFragShader()); prog.Link().Use(); return prog; }
void CreateProgPage::setPercent(uint32 per) { gcWString prog(L"{0} %", per); m_labPercent->SetLabel(prog); m_pbProgress->setProgress(per); m_butPause->Enable(true); Refresh(false); }
//base function void start(){ current_line = 1; var_count = 0; pro_count = 0; advance(); prog(); write_var(); write_pro(); }
// (when 'any . prg) -> any any doWhen(any x) { any a; x = cdr(x); if (isNil(a = EVAL(car(x)))) return Nil; val(At) = a; return prog(cdr(x)); }
void SurfacePointsRenderer::Render(const Scene &scene) { // Declare shared variables for Poisson point generation BBox octBounds = scene.WorldBound(); octBounds.Expand(.001f * powf(octBounds.Volume(), 1.f/3.f)); Octree<SurfacePoint> pointOctree(octBounds); // Create scene bounding sphere to catch rays that leave the scene Point sceneCenter; float sceneRadius; scene.WorldBound().BoundingSphere(&sceneCenter, &sceneRadius); Transform ObjectToWorld(Translate(sceneCenter - Point(0,0,0))); Transform WorldToObject(Inverse(ObjectToWorld)); Reference<Shape> sph = new Sphere(&ObjectToWorld, &WorldToObject, true, sceneRadius, -sceneRadius, sceneRadius, 360.f); //Reference<Material> nullMaterial = Reference<Material>(NULL); Material nullMaterial; GeometricPrimitive sphere(sph, nullMaterial, NULL); int maxFails = 2000, repeatedFails = 0, maxRepeatedFails = 0; if (PbrtOptions.quickRender) maxFails = max(10, maxFails / 10); int totalPathsTraced = 0, totalRaysTraced = 0, numPointsAdded = 0; ProgressReporter prog(maxFails, "Depositing samples"); // Launch tasks to trace rays to find Poisson points PBRT_SUBSURFACE_STARTED_RAYS_FOR_POINTS(); vector<Task *> tasks; RWMutex *mutex = RWMutex::Create(); int nTasks = NumSystemCores(); for (int i = 0; i < nTasks; ++i) tasks.push_back(new SurfacePointTask(scene, pCamera, time, i, minDist, maxFails, *mutex, repeatedFails, maxRepeatedFails, totalPathsTraced, totalRaysTraced, numPointsAdded, sphere, pointOctree, points, prog)); EnqueueTasks(tasks); WaitForAllTasks(); for (uint32_t i = 0; i < tasks.size(); ++i) delete tasks[i]; RWMutex::Destroy(mutex); prog.Done(); PBRT_SUBSURFACE_FINISHED_RAYS_FOR_POINTS(totalRaysTraced, numPointsAdded); if (filename != "") { // Write surface points to file FILE *f = fopen(filename.c_str(), "w"); if (!f) { Error("Unable to open output file \"%s\" (%s)", filename.c_str(), strerror(errno)); return; } fprintf(f, "# points generated by SurfacePointsRenderer\n"); fprintf(f, "# position (x,y,z), normal (x,y,z), area, rayEpsilon\n"); for (u_int i = 0; i < points.size(); ++i) { const SurfacePoint &sp = points[i]; fprintf(f, "%g %g %g %g %g %g %g %g\n", sp.p.x, sp.p.y, sp.p.z, sp.n.x, sp.n.y, sp.n.z, sp.area, sp.rayEpsilon); } fclose(f); } }
ShapeProgram(void) : Program(make()) , projection_matrix(prog(), "ProjectionMatrix") , camera_matrix(prog(), "CameraMatrix") , model_matrix(prog(), "ModelMatrix") , camera_position(prog(), "CameraPosition") , light_position(prog(), "LightPosition") , color_1(prog(), "Color1") , color_2(prog(), "Color2") , metal_tex(prog(), "MetalTex") { }
TransformProgram(void) : Program(make()) , camera_matrix(prog(), "CameraMatrix") , model_matrix(prog(), "ModelMatrix") , light_proj_matrix(prog(), "LightProjMatrix") , texture_matrix(prog(), "TextureMatrix") , camera_position(prog(), "CameraPosition") , light_position(prog(), "LightPosition") , clip_plane(prog(), "ClipPlane") , clip_direction(prog(), "ClipDirection") { }
/** * In case BOOST_COMPUTE_USE_OFFLINE_CACHE macro is defined, * the compiled binary is stored for reuse in the offline cache located in * $HOME/.boost_compute on UNIX-like systems and in %APPDATA%/boost_compute * on Windows. */ static program build_with_source( const std::string &source, const context &context, const std::string &options = std::string() ) { #ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE // Get hash string for the kernel. device d = context.get_device(); platform p = d.platform(); detail::sha1 hash; hash.process( p.name() ) .process( p.version() ) .process( d.name() ) .process( options ) .process( source ) ; std::string hash_string = hash; // Try to get cached program binaries: try { boost::optional<program> prog = load_program_binary(hash_string, context); if (prog) { prog->build(options); return *prog; } } catch (...) { // Something bad happened. Fallback to normal compilation. } // Cache is apparently not available. Just compile the sources. #endif const char *source_string = source.c_str(); cl_int error = 0; cl_program program_ = clCreateProgramWithSource(context, uint_(1), &source_string, 0, &error); if(!program_){ BOOST_THROW_EXCEPTION(opencl_error(error)); } program prog(program_, false); prog.build(options); #ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE // Save program binaries for future reuse. save_program_binary(hash_string, prog); #endif return prog; }
/** * Make a map of the conversion factors between tof and D-spacing * for all pixel IDs in a workspace. * * @param DFileName name of dspacemap file * @param offsetsWS :: OffsetsWorkspace with instrument and offsets */ void SaveDspacemap::CalculateDspaceFromCal(Mantid::DataObjects::OffsetsWorkspace_sptr offsetsWS, std::string DFileName) { const char * filename = DFileName.c_str(); // Get a pointer to the instrument contained in the workspace Instrument_const_sptr instrument = offsetsWS->getInstrument(); double l1; Kernel::V3D beamline,samplePos; double beamline_norm; instrument->getInstrumentParameters(l1,beamline,beamline_norm, samplePos); //To get all the detector ID's detid2det_map allDetectors; instrument->getDetectors(allDetectors); detid2det_map::const_iterator it; detid_t maxdetID = 0; for (it = allDetectors.begin(); it != allDetectors.end(); it++) { detid_t detectorID = it->first; if(detectorID > maxdetID) maxdetID = detectorID; } detid_t paddetID = detid_t(getProperty("PadDetID")); if (maxdetID < paddetID)maxdetID = paddetID; // Now write the POWGEN-style Dspace mapping file std::ofstream fout(filename, std::ios_base::out|std::ios_base::binary); Progress prog(this,0.0,1.0,maxdetID); for (detid_t i = 0; i != maxdetID; i++) { //Compute the factor double factor; Geometry::IDetector_const_sptr det; // Find the detector with that detector id it = allDetectors.find(i); if (it != allDetectors.end()) { det = it->second; factor = Instrument::calcConversion(l1, beamline, beamline_norm, samplePos, det, offsetsWS->getValue(i, 0.0)); //Factor of 10 between ISAW and Mantid factor *= 0.1 ; if(factor<0)factor = 0.0; fout.write( reinterpret_cast<char*>( &factor ), sizeof(double) ); } else { factor = 0; fout.write( reinterpret_cast<char*>( &factor ), sizeof(double) ); } //Report progress prog.report(); } fout.close(); }
// (if 'any1 'any2 . prg) -> any any doIf(any x) { any a; x = cdr(x); if (isNil(a = EVAL(car(x)))) return prog(cddr(x)); val(At) = a; x = cdr(x); return EVAL(car(x)); }
// (nond ('any1 . prg1) ('any2 . prg2) ..) -> any any doNond(any x) { any a; while (isCell(x = cdr(x))) { if (isNil(a = EVAL(caar(x)))) return prog(cdar(x)); val(At) = a; } return Nil; }
// (unless 'any . prg) -> any any doUnless(any x) { any a; x = cdr(x); if (!isNil(a = EVAL(car(x)))) { val(At) = a; return Nil; } return prog(cdr(x)); }
void Parser::parse() { lookahead_ = scanner_.nextToken(attribute_, lineno_); try { prog(); } catch(const std::exception& error) { std::stringstream ss; ss << lineno_ << ": " << error.what(); throw std::runtime_error(ss.str()); } }
string RenderDevice::ReadSources(const string &fileName) { fstream file; file.exceptions(ifstream::eofbit | ifstream::failbit | ifstream::badbit); file.open(fileName.c_str(), fstream::in | fstream::binary); string prog(istreambuf_iterator<char>(file), (istreambuf_iterator<char>())); cerr << "[Device::" << deviceName << "] Kernel file size " << prog.length() << "bytes" << endl; return prog; }
int main(int argc, char *argv[]) { QApplication prog(argc, argv); MainWindow w; w.show(); return prog.exec(); }
/* * * name: main * * Receives information from the user of the input and output files, and then * makes appropriate calls. * * @param argc the number of arguments passed (including the program) * @param argv the argument array of the program call * @return error code */ int main(int argc, char** argv){ line current; sourceContainer source; source.current = ¤t; char input[MAX_FILE_LEN]; int i; token tokenList[MAX_TOKENS]; // The user can pass a parameter to the program for the file name. // If no parameter is given, the program will ask explicitly. if(argc == 2){ strcpy(input, argv[1]); } else{ printf("\n Name of your input file (%d characters max): ", MAX_FILE_LEN); scanf("%s", input); } source.infile = fopen(input, "r"); if(source.infile == NULL){ printf("Could not open input file!\n"); exit(1); } // prepare and build the token table for(i=0;i<HASH_TABLE_SIZE;i++){ source.hashTable[i] = NULL; source.symbolTable[i] = NULL; } readTokens(tokenList, "tokens"); buildHashes(source.hashTable, tokenList); source.current->scanIndex = 0; source.current->lineNumber = 0; source.current->atEOF = 0; memset(source.current->line, '\0', MAX_LINE_LEN); // parse the source if(prog(&source)){ printf("\n\nParse successful!\n"); } else{ while(!source.current->atEOF){ getLine(source.current, source.infile); } printf("\n\nParse failure!\n"); } printf("\nSymbol table:\n"); printHash(source.symbolTable); return 0; }
int main(int argc, char * argv[]){ remove("tmp/test1.txt"); remove("tmp/test2.txt"); remove("./tmp/graph.dot"); if (argc < 2) { cout << "erreur : pas de fichier assembleur en entrée" << endl; } Program prog(argv[1]); Function* functmp; list <Basic_block*> myBB; cout<<"Le programme a "<<prog.size()<<" lignes\n"<<endl; cout<<"Contenu du programme:"<<endl; //prog.display(); prog.in_file("tmp/restit.txt"); cout<<"\n Calcul des fonctions des block de base et restitution\n"<<endl; prog.comput_function(); cout<<"nombre de fonction: "<<prog.nbr_func()<<endl; Cfg *graph; for (int i=0; i<prog.nbr_func(); i++){ functmp= prog.get_function(i); if(functmp==NULL){ cout<<"null"<<endl; break; } // functmp->restitution("tmp/test1.txt"); functmp->comput_basic_block(); functmp->comput_label(); for(int j=0; j<functmp->nbr_BB(); j++){ //functmp->get_BB(j)->display(); } functmp->comput_succ_pred_BB(); graph =new Cfg(functmp->get_BB(0), functmp->nbr_BB()); cout<<"------------Function "<< (i+1) <<"/"<<prog.nbr_func()<<" DISPLAY----------\n" <<endl; //functmp->test(); graph->display(NULL); } // graph->restitution(NULL,"./tmp/graph.dot"); }
void CompressEvents::exec() { // Get the input workspace EventWorkspace_sptr inputWS = getProperty("InputWorkspace"); EventWorkspace_sptr outputWS = getProperty("OutputWorkspace"); double tolerance = getProperty("Tolerance"); // Some starting things bool inplace = (inputWS == outputWS); const int noSpectra = static_cast<int>(inputWS->getNumberHistograms()); Progress prog(this,0.0,1.0, noSpectra*2); // Sort the input workspace in-place by TOF. This can be faster if there are few event lists. inputWS->sortAll(TOF_SORT, &prog); // Are we making a copy of the input workspace? if (!inplace) { //Make a brand new EventWorkspace outputWS = boost::dynamic_pointer_cast<EventWorkspace>( API::WorkspaceFactory::Instance().create("EventWorkspace", inputWS->getNumberHistograms(), 2, 1)); //Copy geometry over. API::WorkspaceFactory::Instance().initializeFromParent(inputWS, outputWS, false); // We DONT copy the data though // Do we want to parallelize over event lists, or in each event list bool parallel_in_each = noSpectra < PARALLEL_GET_MAX_THREADS; //parallel_in_each = false; // Loop over the histograms (detector spectra) // Don't parallelize the loop if we are going to parallelize each event list. // cppcheck-suppress syntaxError PRAGMA_OMP( parallel for schedule(dynamic) if (!parallel_in_each) ) for (int i = 0; i < noSpectra; ++i) { PARALLEL_START_INTERUPT_REGION //the loop variable i can't be signed because of OpenMp rules inforced in Linux. Using this signed type suppresses warnings below const size_t index = static_cast<size_t>(i); // The input event list EventList& input_el = inputWS->getEventList(index); // And on the output side EventList & output_el = outputWS->getOrAddEventList(index); // Copy other settings into output output_el.setX( input_el.ptrX() ); // The EventList method does the work. input_el.compressEvents(tolerance, &output_el, parallel_in_each); prog.report("Compressing"); PARALLEL_END_INTERUPT_REGION } PARALLEL_CHECK_INTERUPT_REGION }
// (cond ('any1 . prg1) ('any2 . prg2) ..) -> any any doCond(any x) { any a; while (isCell(x = cdr(x))) { if (!isNil(a = EVAL(caar(x)))) { val(At) = a; return prog(cdar(x)); } } return Nil; }
// (ifn 'any1 'any2 . prg) -> any any doIfn(any x) { any a; x = cdr(x); if (!isNil(a = EVAL(car(x)))) { val(At) = a; return prog(cddr(x)); } x = cdr(x); return EVAL(car(x)); }
// (catch 'any . prg) -> any any doCatch(any x) { any y; catchFrame f; x = cdr(x), f.tag = EVAL(car(x)), f.fin = Zero; f.link = CatchPtr, CatchPtr = &f; f.env = Env; y = setjmp(f.rst)? Thrown : prog(cdr(x)); CatchPtr = f.link; return y; }
static void _do_scatter(const VertexProg& prog_copy, Edge& e, Gather (VertexProg::*f)(const Edge&, Vertex&) const) { auto e_id = e.id; auto e_data = e.data; call<async>(e.ga, [=](Vertex& ve){ auto local_e_data = e_data; Edge e = { e_id, g->vs+e_id, local_e_data }; auto gather_delta = prog_copy.scatter(e, ve); prog(ve).post_delta(gather_delta); }); }
int main(){ Program prog("src/examples/recette.s"); Operand *Op1,*Op2, *Op3, *Op4, *Op5,*Op6; OPRegister registr("$5",5,Src); OPRegister registr0("$5",5,Dst); OPRegister registr1("$6",6,Dst); OPRegister registr2("$0",0,Src); OPRegister registr3("$6",6,Src); OPRegister registr4("$4",4,Dst); OPRegister registr5("$4",4,Src); OPImmediate imm("0xFFFF"); Directive dir("# Code avec des Nor"); Op1= ®istr; Op2= ®istr0; Op3= ®istr1; Op4= ®istr2; Op5= ®istr3; Op6= ®istr4; Line *ligne; prog.display(); prog.del_line(0); ligne = prog.find_line(0); Instruction *inst = dynamic_cast< Instruction * > (ligne); inst->set_opcode(lui); inst->set_op1(Op6); inst->set_op2(&imm); inst->set_op3(NULL); inst->set_number_oper(2); ligne=prog.find_line(1); Instruction *ins2 = dynamic_cast< Instruction * > (ligne); ins2->set_opcode(and_); Instruction ins3("ori $4,$4,0xFFFF",ori,R, ALU,Op6,®istr5,&imm,3); Instruction ins4("xor $5,$4,$0",xor_,R, ALU,Op1,®istr5,Op4,3); Instruction ins5("xor $4,$5,$6",xor_,R, ALU,Op3,®istr5,Op4,3); prog.add_line_at(&ins3,1); prog.add_line_at(&ins4,2); prog.add_line_at(&ins5,3); prog.display(); }
// (until 'any . prg) -> any any doUntil(any x) { any cond, a; cell c1; cond = car(x = cdr(x)), x = cdr(x); Push(c1, Nil); while (isNil(a = EVAL(cond))) data(c1) = prog(x); val(At) = a; return Pop(c1); }
void SumEventsByLogValue::createBinnedOutput( const Kernel::TimeSeriesProperty<T> *log) { // If only the number of bins was given, add the min & max values of the log if (m_binningParams.size() == 1) { m_binningParams.insert(m_binningParams.begin(), log->minValue()); m_binningParams.push_back( log->maxValue() * 1.000001); // Make it a tiny bit larger to cover full range } // XValues will be resized in createAxisFromRebinParams() std::vector<double> XValues; const int XLength = VectorHelper::createAxisFromRebinParams(m_binningParams, XValues); assert((int)XValues.size() == XLength); // Create the output workspace - the factory will give back a Workspace2D MatrixWorkspace_sptr outputWorkspace = WorkspaceFactory::Instance().create( "Workspace2D", 1, XLength, XLength - 1); // Copy the bin boundaries into the output workspace outputWorkspace->mutableX(0) = XValues; outputWorkspace->getAxis(0)->title() = m_logName; outputWorkspace->setYUnit("Counts"); auto &Y = outputWorkspace->mutableY(0); const int numSpec = static_cast<int>(m_inputWorkspace->getNumberHistograms()); Progress prog(this, 0.0, 1.0, numSpec); PARALLEL_FOR_IF(Kernel::threadSafe(*m_inputWorkspace)) for (int spec = 0; spec < numSpec; ++spec) { PARALLEL_START_INTERUPT_REGION const IEventList &eventList = m_inputWorkspace->getSpectrum(spec); const auto pulseTimes = eventList.getPulseTimes(); for (auto pulseTime : pulseTimes) { // Find the value of the log at the time of this event const double logValue = log->getSingleValue(pulseTime); if (logValue >= XValues.front() && logValue < XValues.back()) { PARALLEL_ATOMIC ++Y[VectorHelper::getBinIndex(XValues, logValue)]; } } prog.report(); PARALLEL_END_INTERUPT_REGION } PARALLEL_CHECK_INTERUPT_REGION // The errors are the sqrt of the counts so long as we don't deal with // weighted events. std::transform(Y.cbegin(), Y.cend(), outputWorkspace->mutableE(0).begin(), (double (*)(double))std::sqrt); setProperty("OutputWorkspace", outputWorkspace); }
string make_fake_program() { if (alphabet.size() > prog_length) { cerr<<"Error | make_fake_program | alphabet.size() > prog_length"<<endl; exit(EXIT_FAILURE); } string prog(prog_length, alphabet[0]); for (size_t i = 0 ; i < alphabet.size() ; i++) prog[i] = alphabet[i]; return prog; }
Instance ScriptAction::evaluate(const Instance *inst, const ConstMemberList &members, ScriptEngine *eng, bool *matched) const { // Parallel evaluation of threads // static QMutex lock(QMutex::Recursive); // QMutexLocker l(&lock); // Using the same QScriptProgram by multiple engines concurrently causes // a segmentation fault. // See https://bugreports.qt-project.org/browse/QTBUG-29246 QScriptProgram prog(_program->sourceCode(), _program->fileName(), _program->firstLineNumber()); if (matched) *matched = true; if (!_program || !inst) return Instance(); eng->initScriptEngine(); // Instance passed to the rule as 1. argument QScriptValue instVal = InstanceClass::instToScriptValue(eng->engine(), *inst); // List of accessed member indices passed to the rule as 2. argument QScriptValue indexlist = eng->engine()->newArray(members.size()); for (int i = 0; i < members.size(); ++i) indexlist.setProperty(i, eng->engine()->toScriptValue(members[i]->index())); QScriptValueList args; args << instVal << indexlist; QScriptValue ret(eng->evaluateFunction(funcToCall(), args, prog, _includePaths, inst->memDumpIndex())); if (eng->lastEvaluationFailed()) warnEvalError(eng, prog.fileName()); else if (ret.isBool() || ret.isNumber() || ret.isNull()) { if (matched) *matched = ret.toBool(); } else if (ret.isArray()) { InstanceList list; qScriptValueToSequence(ret, list); return Instance::fromList(list); } else { Instance instRet; InstanceClass::instFromScriptValue(ret, instRet); return instRet; } return Instance(); }