void smp_flush_tlb_all(void) { xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all)); local_flush_tlb_all(); }
void smp_flush_cache_all(void) { xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all)); }
void smp_show_backtrace_all_cpus(void) { xc0((smpfunc_t) show_backtrace); show_backtrace(); }
/** * Main function. * * Usage: VtkToFld session.xml input.vtk output.fld [options] */ int main(int argc, char* argv[]) { // Set up available options po::options_description desc("Available options"); desc.add_options() ("help,h", "Produce this help message.") ("name,n", po::value<string>()->default_value("Intensity"), "Name of field in VTK file to use for intensity.") ("outname,m", po::value<string>()->default_value("intensity"), "Name of field in output FLD file.") ("precision,p", po::value<double>()->default_value(1), "Precision of vertex matching."); po::options_description hidden("Hidden options"); hidden.add_options() ("file", po::value<vector<string> >(), "Input filename"); po::options_description cmdline_options; cmdline_options.add(desc).add(hidden); po::positional_options_description p; p.add("file", -1); po::variables_map vm; // Parse command-line options try { po::store(po::command_line_parser(argc, argv). options(cmdline_options).positional(p).run(), vm); po::notify(vm); } catch (const std::exception& e) { cerr << e.what() << endl; cerr << desc; return 1; } if ( vm.count("help") || vm.count("file") == 0 || vm["file"].as<vector<string> >().size() != 3) { cerr << "Usage: VtkToFld session.xml intensity.vtk output.fld [options]" << endl; cerr << desc; return 1; } // Extract command-line argument values std::vector<std::string> vFiles = vm["file"].as<vector<string> >(); const string infile = vFiles[1]; const string outfile = vFiles[2]; const double factor = vm["precision"].as<double>(); const string name = vm["name"].as<string>(); const string outname = vm["outname"].as<string>(); std::vector<std::string> vFilenames; LibUtilities::SessionReaderSharedPtr vSession; SpatialDomains::MeshGraphSharedPtr graph2D; MultiRegions::ExpList2DSharedPtr Exp; vFilenames.push_back(vFiles[0]); vSession = LibUtilities::SessionReader::CreateInstance(2, argv, vFilenames); try { //---------------------------------------------- // Read in mesh from input file graph2D = MemoryManager<SpatialDomains::MeshGraph2D>:: AllocateSharedPtr(vSession); //---------------------------------------------- //---------------------------------------------- // Define Expansion Exp = MemoryManager<MultiRegions::ExpList2D>:: AllocateSharedPtr(vSession,graph2D); //---------------------------------------------- //---------------------------------------------- // Set up coordinates of mesh int coordim = Exp->GetCoordim(0); int nq = Exp->GetNpoints(); Array<OneD, NekDouble> xc0(nq,0.0); Array<OneD, NekDouble> xc1(nq,0.0); Array<OneD, NekDouble> xc2(nq,0.0); switch(coordim) { case 2: Exp->GetCoords(xc0,xc1); break; case 3: Exp->GetCoords(xc0,xc1,xc2); break; default: ASSERTL0(false,"Coordim not valid"); break; } //---------------------------------------------- vtkPolyDataReader *vtkMeshReader = vtkPolyDataReader::New(); vtkMeshReader->SetFileName(infile.c_str()); vtkMeshReader->Update(); vtkPolyData *vtkMesh = vtkMeshReader->GetOutput(); vtkCellDataToPointData* c2p = vtkCellDataToPointData::New(); #if VTK_MAJOR_VERSION <= 5 c2p->SetInput(vtkMesh); #else c2p->SetInputData(vtkMesh); #endif c2p->PassCellDataOn(); c2p->Update(); vtkPolyData *vtkDataAtPoints = c2p->GetPolyDataOutput(); vtkPoints *vtkPoints = vtkMesh->GetPoints(); ASSERTL0(vtkPoints, "ERROR: cannot get points from mesh."); vtkCellArray *vtkPolys = vtkMesh->GetPolys(); ASSERTL0(vtkPolys, "ERROR: cannot get polygons from mesh."); vtkPointData *vtkPData = vtkDataAtPoints->GetPointData(); ASSERTL0(vtkPolys, "ERROR: cannot get point data from file."); VertexSet points; VertexSet::iterator vIter; double p[3]; double val; double x, y, z; int coeff_idx; int i,j,n; if (!vtkDataAtPoints->GetPointData()->HasArray(name.c_str())) { n = vtkDataAtPoints->GetPointData()->GetNumberOfArrays(); cerr << "Input file '" << infile << "' does not have a field named '" << name << "'" << endl; cerr << "There are " << n << " arrays in this file." << endl; for (int i = 0; i < n; ++i) { cerr << " " << vtkDataAtPoints->GetPointData()->GetArray(i)->GetName() << endl; } return 1; } // Build up an unordered set of vertices from the VTK file. For each // vertex a hashed value of the coordinates is generated to within a // given tolerance. n = vtkPoints->GetNumberOfPoints(); for (i = 0; i < n; ++i) { vtkPoints->GetPoint(i,p); val = vtkPData->GetScalars(name.c_str())->GetTuple1(i); boost::shared_ptr<Vertex> v(new Vertex(p[0],p[1],p[2],val,factor)); points.insert(v); } // Now process each vertex of each element in the mesh SpatialDomains::PointGeomSharedPtr vert; for (i = 0; i < Exp->GetNumElmts(); ++i) { StdRegions::StdExpansionSharedPtr e = Exp->GetExp(i); for (j = 0; j < e->GetNverts(); ++j) { // Get the index of the coefficient corresponding to this vertex coeff_idx = Exp->GetCoeff_Offset(i) + e->GetVertexMap(j); // Get the coordinates of the vertex vert = e->as<LocalRegions::Expansion2D>()->GetGeom2D() ->GetVertex(j); vert->GetCoords(x,y,z); // Look up the vertex in the VertexSet boost::shared_ptr<Vertex> v(new Vertex(x,y,z,0.0,factor)); vIter = points.find(v); // If not found, maybe the tolerance should be reduced? // If found, record the scalar value from the VTK file in the // corresponding coefficient. if (vIter == points.end()) { cerr << "Vertex " << i << " not found. Looking for (" << x << ", " << y << ", " << z << ")" << endl; } else { Exp->UpdateCoeffs()[coeff_idx] = (*vIter)->scalar; } } } Exp->SetPhysState(false); //----------------------------------------------- // Write solution to file std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef = Exp->GetFieldDefinitions(); std::vector<std::vector<NekDouble> > FieldData(FieldDef.size()); for(i = 0; i < FieldDef.size(); ++i) { FieldDef[i]->m_fields.push_back(outname); Exp->AppendFieldData(FieldDef[i], FieldData[i]); } LibUtilities::FieldIO vFld(vSession->GetComm()); vFld.Write(outfile, FieldDef, FieldData); //----------------------------------------------- } catch (...) { cout << "An error occurred." << endl; } }
void TestIt(long m, long p, long r, long d, long L, long bnd, long B) { cout << "*** TestIt" << (isDryRun()? "(dry run):" : ":") << " m=" << m << ", p=" << p << ", r=" << r << ", d=" << d << ", L=" << L << ", bnd=" << bnd << ", B=" << B << endl; setTimersOn(); FHEcontext context(m, p, r); buildModChain(context, L, /*c=*/2); context.zMStar.printout(); cout << endl; FHESecKey secretKey(context); const FHEPubKey& publicKey = secretKey; secretKey.GenSecKey(/*w=*/64); // A Hamming-weight-w secret key ZZX G; if (d == 0) G = context.alMod.getFactorsOverZZ()[0]; else G = makeIrredPoly(p, d); cout << "G = " << G << "\n"; cout << "generating key-switching matrices... "; addSome1DMatrices(secretKey); // compute key-switching matrices that we need cout << "done\n"; cout << "computing masks and tables for rotation..."; EncryptedArray ea(context, G); cout << "done\n"; PlaintextArray xp0(ea), xp1(ea); xp0.random(); xp1.random(); Ctxt xc0(publicKey); ea.encrypt(xc0, publicKey, xp0); ZZX poly_xp1; ea.encode(poly_xp1, xp1); cout << "** Testing replicate():\n"; bool error = false; Ctxt xc1 = xc0; CheckCtxt(xc1, "before replicate"); replicate(ea, xc1, ea.size()/2); if (!check_replicate(xc1, xc0, ea.size()/2, secretKey, ea)) error = true; CheckCtxt(xc1, "after replicate"); // Get some timing results for (long i=0; i<20 && i<ea.size(); i++) { xc1 = xc0; FHE_NTIMER_START(replicate); replicate(ea, xc1, i); if (!check_replicate(xc1, xc0, i, secretKey, ea)) error = true; FHE_NTIMER_STOP(replicate); } cout << " Replicate test " << (error? "failed :(\n" : "succeeded :)") << endl<< endl; printAllTimers(); cout << "\n** Testing replicateAll()... " << std::flush; #ifdef DEBUG_PRINTOUT replicateVerboseFlag = true; #else replicateVerboseFlag = false; #endif error = false; ReplicateTester *handler = new ReplicateTester(secretKey, ea, xp0, B); try { FHE_NTIMER_START(replicateAll); replicateAll(ea, xc0, handler, bnd); } catch (StopReplicate) { } cout << (handler->error? "failed :(\n" : "succeeded :)") << ", total time=" << handler->t_total << " (" << ((B>0)? B : ea.size()) << " vectors)\n"; delete handler; }
//--------------------------------------------------------- void EulerShock2D::precalc_limiter_data() //--------------------------------------------------------- { //--------------------------------------------- // pre-calculate element geometry and constant // factors for use in this->EulerLimiter2D() //--------------------------------------------- Lim_AVE = 0.5 * MassMatrix.col_sums(); DMat dropAVE = eye(Np) - outer(ones(Np),Lim_AVE); Lim_dx = dropAVE*x; Lim_dy = dropAVE*y; // Extract coordinates of vertices of elements IVec v1=EToV(All,1); Lim_xv1=VX(v1); Lim_yv1=VY(v1); IVec v2=EToV(All,2); Lim_xv2=VX(v2); Lim_yv2=VY(v2); IVec v3=EToV(All,3); Lim_xv3=VX(v3); Lim_yv3=VY(v3); const DVec &xv1=Lim_xv1,&xv2=Lim_xv2,&xv3=Lim_xv3; const DVec &yv1=Lim_yv1,&yv2=Lim_yv2,&yv3=Lim_yv3; DMat &fnx=Lim_fnx, &fny=Lim_fny, &fL=Lim_fL; // Compute face unit normals and lengths fnx.resize(3,K); fny.resize(3,K); // fnx = (3,K) = [yv2-yv1; yv3-yv2; yv1-yv3]; fnx.set_row(1, yv2-yv1); fnx.set_row(2, yv3-yv2); fnx.set_row(3, yv1-yv3); // fny = (3,K) = -[xv2-xv1;xv3-xv2;xv1-xv3]; //fny.set_row(1, xv2-xv1); fny.set_row(2, xv3-xv2); fny.set_row(3, xv1-xv3); fny.set_row(1, xv1-xv2); fny.set_row(2, xv2-xv3); fny.set_row(3, xv3-xv1); fL = sqrt(sqr(fnx)+sqr(fny)); fnx.div_element(fL); fny.div_element(fL); //------------------------------------------------------- // Compute coords of element centers and face weights //------------------------------------------------------- // Find neighbors in patch Lim_E1=EToE(All,1); Lim_E2=EToE(All,2); Lim_E3=EToE(All,3); // Compute coordinates of element centers xc0=Lim_AVE*x; xc1=xc0(Lim_E1); xc2=xc0(Lim_E2); xc3=xc0(Lim_E3); yc0=Lim_AVE*y; yc1=yc0(Lim_E1); yc2=yc0(Lim_E2); yc3=yc0(Lim_E3); // Compute weights for face gradients A0=Lim_AVE*J*TWOTHIRD; A1=A0+A0(Lim_E1); A2=A0+A0(Lim_E2); A3=A0+A0(Lim_E3); A1_A2_A3 = A1+A2+A3; // Find boundary faces for each face Lim_id1=find(BCType.get_col(1),'!',0); Lim_id2=find(BCType.get_col(2),'!',0); Lim_id3=find(BCType.get_col(3),'!',0); // Compute location of centers of reflected ghost elements at boundary faces if (1) { DMat FL1=fL(1,Lim_id1), Fnx1=fnx(1,Lim_id1), Fny1=fny(1,Lim_id1); DVec fL1=FL1, fnx1=Fnx1, fny1=Fny1; DVec H1 = 2.0*(dd(A0(Lim_id1),fL1)); xc1(Lim_id1) += 2.0*fnx1.dm(H1); yc1(Lim_id1) += 2.0*fny1.dm(H1); DMat FL2=fL(2,Lim_id2), Fnx2=fnx(2,Lim_id2), Fny2=fny(2,Lim_id2); DVec fL2=FL2, fnx2=Fnx2, fny2=Fny2; DVec H2 = 2.0*(dd(A0(Lim_id2),fL2)); xc2(Lim_id2) += 2.0*fnx2.dm(H2); yc2(Lim_id2) += 2.0*fny2.dm(H2); DMat FL3=fL(3,Lim_id3), Fnx3=fnx(3,Lim_id3), Fny3=fny(3,Lim_id3); DVec fL3=FL3, fnx3=Fnx3, fny3=Fny3; DVec H3 = 2.0*(dd(A0(Lim_id3),fL3)); xc3(Lim_id3) += 2.0*fnx3.dm(H3); yc3(Lim_id3) += 2.0*fny3.dm(H3); } // Find boundary faces IVec bct = trans(BCType); Lim_idI = find(bct, '=', (int)BC_In); Lim_idO = find(bct, '=', (int)BC_Out); Lim_idW = find(bct, '=', (int)BC_Wall); Lim_idC = find(bct, '=', (int)BC_Cyl); Lim_ctx.resize(3,K); Lim_cty.resize(3,K); Lim_ctx.set_row(1,xc1); Lim_ctx.set_row(2,xc2); Lim_ctx.set_row(3,xc3); Lim_cty.set_row(1,yc1); Lim_cty.set_row(2,yc2); Lim_cty.set_row(3,yc3); // load the set of ids Lim_ids.resize(6); Lim_ids(1)=1; Lim_ids(2)=Nfp; Lim_ids(3)=Nfp+1; Lim_ids(4)=2*Nfp; Lim_ids(5)=3*Nfp; Lim_ids(6)=2*Nfp+1; limQ = Q; }