Teuchos::ArrayView<Integral> getList(Teuchos::Array<Integral> &irl) { Teuchos::ArrayView<Integral> av; // av.size() == 0 if (!Zoltan2::allValuesAreInRangeList(irl) && !Zoltan2::noValuesAreInRangeList(irl)) av = irl.view(0, irl.size()-1); // skip last value, it's a flag return av; }
void printIntegralRangeList(std::ostream &os, Teuchos::Array<Integral> &irl) { if (Zoltan2::allValuesAreInRangeList(irl)) os << "all"; else if (Zoltan2::noValuesAreInRangeList(irl)) os << "empty"; else{ Teuchos::ArrayView<const Integral> view = irl.view(0, irl.size()-1); // skip last value, it's a flag os << view; } }
// Just test whether Teuchos memory management objects and Kokkos // Array Views can coexist in the same program. This test does not // have the Teuchos and Kokkos objects interact with each other. TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, NoInteraction ) { typedef Teuchos::Array<double>::size_type size_type; const size_type numElts = 10; Teuchos::Array<double> x (numElts); for (size_type k = 0; k < numElts; ++k) { x[k] = 42.0 + static_cast<double> (k); } Teuchos::ArrayView<double> xView = x.view (3, 5); // view of [3, 4, 5, 6, 7] TEST_EQUALITY_CONST( xView.size(), 5 ); for (size_type k = 0; k < xView.size (); ++k) { TEST_EQUALITY( xView[k], x[k+3] ); } typedef Kokkos::View<double*, Kokkos::Threads> ka_view_type; ka_view_type y ("y", numElts); Kokkos::parallel_for (y.dimension_0 (), FillFunctor<Kokkos::Threads> (y)); }
int main(int argc, char *argv[]) { // Communicators Teuchos::GlobalMPISession mpiSession(&argc, &argv); const Albany_MPI_Comm nativeComm = Albany_MPI_COMM_WORLD; const RCP<const Teuchos::Comm<int> > teuchosComm = Albany::createTeuchosCommFromMpiComm(nativeComm); // Standard output const RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream(); // Parse command-line argument for input file const std::string firstArg = (argc > 1) ? argv[1] : ""; if (firstArg.empty() || firstArg == "--help") { *out << "AlbanyRBGen input-file-path\n"; return 0; } const std::string inputFileName = argv[1]; // Parse XML input file const RCP<Teuchos::ParameterList> topLevelParams = Teuchos::createParameterList("Albany Parameters"); Teuchos::updateParametersFromXmlFileAndBroadcast(inputFileName, topLevelParams.ptr(), *teuchosComm); const bool sublistMustExist = true; // Setup discretization factory const RCP<Teuchos::ParameterList> discParams = Teuchos::sublist(topLevelParams, "Discretization", sublistMustExist); TEUCHOS_TEST_FOR_EXCEPT(discParams->get<std::string>("Method") != "Ioss"); const std::string outputParamLabel = "Exodus Output File Name"; const std::string sampledOutputParamLabel = "Reference Exodus Output File Name"; const RCP<const Teuchos::ParameterEntry> reducedOutputParamEntry = getEntryCopy(*discParams, outputParamLabel); const RCP<const Teuchos::ParameterEntry> sampledOutputParamEntry = getEntryCopy(*discParams, sampledOutputParamLabel); discParams->remove(outputParamLabel, /*throwIfNotExists =*/ false); discParams->remove(sampledOutputParamLabel, /*throwIfNotExists =*/ false); const RCP<const Teuchos::ParameterList> discParamsCopy = Teuchos::rcp(new Teuchos::ParameterList(*discParams)); const RCP<Teuchos::ParameterList> problemParams = Teuchos::sublist(topLevelParams, "Problem", sublistMustExist); const RCP<const Teuchos::ParameterList> problemParamsCopy = Teuchos::rcp(new Teuchos::ParameterList(*problemParams)); // Create original (full) discretization const RCP<Albany::AbstractDiscretization> disc = Albany::discretizationNew(topLevelParams, teuchosComm); // Determine mesh sample const RCP<Teuchos::ParameterList> samplingParams = Teuchos::sublist(topLevelParams, "Mesh Sampling", sublistMustExist); const int firstVectorRank = samplingParams->get("First Vector Rank", 0); const Teuchos::Ptr<const int> basisSizeMax = Teuchos::ptr(samplingParams->getPtr<int>("Basis Size Max")); const int sampleSize = samplingParams->get("Sample Size", 0); *out << "Sampling " << sampleSize << " nodes"; if (Teuchos::nonnull(basisSizeMax)) { *out << " based on no more than " << *basisSizeMax << " basis vectors"; } if (firstVectorRank != 0) { *out << " starting from vector rank " << firstVectorRank; } *out << "\n"; const RCP<Albany::STKDiscretization> stkDisc = Teuchos::rcp_dynamic_cast<Albany::STKDiscretization>(disc, /*throw_on_fail =*/ true); const RCP<MOR::AtomicBasisSource> rawBasisSource = Teuchos::rcp(new Albany::StkNodalBasisSource(stkDisc)); const RCP<MOR::AtomicBasisSource> basisSource = Teuchos::rcp( Teuchos::nonnull(basisSizeMax) ? new MOR::WindowedAtomicBasisSource(rawBasisSource, firstVectorRank, *basisSizeMax) : new MOR::WindowedAtomicBasisSource(rawBasisSource, firstVectorRank) ); MOR::CollocationMetricCriterionFactory criterionFactory(samplingParams); const Teuchos::RCP<const MOR::CollocationMetricCriterion> criterion = criterionFactory.instanceNew(basisSource->entryCountMax()); const Teuchos::RCP<MOR::GreedyAtomicBasisSample> sampler(new MOR::GreedyAtomicBasisSample(*basisSource, criterion)); sampler->sampleSizeInc(sampleSize); Teuchos::Array<stk::mesh::EntityId> sampleNodeIds; const Teuchos::ArrayView<const int> sampleAtoms = sampler->sample(); sampleNodeIds.reserve(sampleAtoms.size()); for (Teuchos::ArrayView<const int>::const_iterator it = sampleAtoms.begin(), it_end = sampleAtoms.end(); it != it_end; ++it) { sampleNodeIds.push_back(*it + 1); } *out << "Sample = " << sampleNodeIds << "\n"; // Choose first sample node as sensor const Teuchos::ArrayView<const stk::mesh::EntityId> sensorNodeIds = sampleNodeIds.view(0, 1); const Teuchos::Array<std::string> additionalNodeSets = Teuchos::tuple(std::string("sample_nodes"), std::string("sensors")); // Create sampled discretization if (Teuchos::nonnull(sampledOutputParamEntry)) { const RCP<Teuchos::ParameterList> discParamsLocalCopy = Teuchos::rcp(new Teuchos::ParameterList(*discParamsCopy)); discParamsLocalCopy->setEntry("Exodus Output File Name", *sampledOutputParamEntry); discParamsLocalCopy->set("Additional Node Sets", additionalNodeSets); topLevelParams->set("Discretization", *discParamsLocalCopy); topLevelParams->set("Problem", *problemParamsCopy); const bool performReduction = false; const RCP<Albany::AbstractDiscretization> sampledDisc = sampledDiscretizationNew(topLevelParams, teuchosComm, sampleNodeIds, sensorNodeIds, performReduction); if (Teuchos::nonnull(basisSizeMax)) { transferSolutionHistory(*stkDisc, *sampledDisc, *basisSizeMax + firstVectorRank); } else { transferSolutionHistory(*stkDisc, *sampledDisc); } } // Create reduced discretization if (Teuchos::nonnull(reducedOutputParamEntry)) { const RCP<Teuchos::ParameterList> discParamsLocalCopy = Teuchos::rcp(new Teuchos::ParameterList(*discParamsCopy)); discParamsLocalCopy->setEntry("Exodus Output File Name", *reducedOutputParamEntry); discParamsLocalCopy->set("Additional Node Sets", additionalNodeSets); topLevelParams->set("Discretization", *discParamsLocalCopy); topLevelParams->set("Problem", *problemParamsCopy); const bool performReduction = true; const RCP<Albany::AbstractDiscretization> reducedDisc = sampledDiscretizationNew(topLevelParams, teuchosComm, sampleNodeIds, sensorNodeIds, performReduction); if (Teuchos::nonnull(basisSizeMax)) { transferSolutionHistory(*stkDisc, *reducedDisc, *basisSizeMax + firstVectorRank); } else { transferSolutionHistory(*stkDisc, *reducedDisc); } } }
void LinePartitioner<GraphType,Scalar>::local_automatic_line_search(int NumEqns, Teuchos::ArrayView <local_ordinal_type> blockIndices, local_ordinal_type last, local_ordinal_type next, local_ordinal_type LineID, MT tol, Teuchos::Array<local_ordinal_type> itemp, Teuchos::Array<MT> dtemp) const { typedef local_ordinal_type LO; const LO invalid = Teuchos::OrdinalTraits<LO>::invalid(); const Scalar zero = Teuchos::ScalarTraits<Scalar>::zero(); const MT mzero = Teuchos::ScalarTraits<MT>::zero(); Teuchos::ArrayRCP<const Scalar> xvalsRCP, yvalsRCP, zvalsRCP; Teuchos::ArrayView<const Scalar> xvals, yvals, zvals; xvalsRCP = coord_->getData(0); xvals = xvalsRCP(); if(coord_->getNumVectors() > 1) { yvalsRCP = coord_->getData(1); yvals = yvalsRCP(); } if(coord_->getNumVectors() > 2) { zvalsRCP = coord_->getData(2); zvals = zvalsRCP(); } size_t N = this->Graph_->getNodeNumRows(); size_t allocated_space = this->Graph_->getNodeMaxNumRowEntries(); Teuchos::ArrayView<LO> cols = itemp(); Teuchos::ArrayView<LO> indices = itemp.view(allocated_space,allocated_space); Teuchos::ArrayView<MT> dist= dtemp(); while (blockIndices[next] == invalid) { // Get the next row size_t nz=0; LO neighbors_in_line=0; this->Graph_->getLocalRowCopy(next,cols(),nz); Scalar x0 = (!xvals.is_null()) ? xvals[next/NumEqns_] : zero; Scalar y0 = (!yvals.is_null()) ? yvals[next/NumEqns_] : zero; Scalar z0 = (!zvals.is_null()) ? zvals[next/NumEqns_] : zero; // Calculate neighbor distances & sort LO neighbor_len=0; for(size_t i=0; i<nz; i+=NumEqns) { MT mydist = mzero; if(cols[i] >=(LO)N) continue; // Check for off-proc entries LO nn = cols[i] / NumEqns; if(blockIndices[nn]==LineID) neighbors_in_line++; if(!xvals.is_null()) mydist += square<Scalar>(x0 - xvals[nn]); if(!yvals.is_null()) mydist += square<Scalar>(y0 - yvals[nn]); if(!zvals.is_null()) mydist += square<Scalar>(z0 - zvals[nn]); dist[neighbor_len] = Teuchos::ScalarTraits<MT>::squareroot(mydist); indices[neighbor_len]=cols[i]; neighbor_len++; } // If more than one of my neighbors is already in this line. I // can't be because I'd create a cycle if(neighbors_in_line > 1) break; // Otherwise add me to the line for(LO k=0; k<NumEqns; k++) blockIndices[next + k] = LineID; // Try to find the next guy in the line (only check the closest two that aren't element 0 (diagonal)) Teuchos::ArrayView<MT> dist_view = dist(0,neighbor_len); Tpetra::sort2(dist_view.begin(),dist_view.end(),indices.begin()); if(neighbor_len > 2 && indices[1] != last && blockIndices[indices[1]] == -1 && dist[1]/dist[neighbor_len-1] < tol) { last=next; next=indices[1]; } else if(neighbor_len > 3 && indices[2] != last && blockIndices[indices[2]] == -1 && dist[2]/dist[neighbor_len-1] < tol) { last=next; next=indices[2]; } else { // I have no further neighbors in this line break; } } }