template <class T> inline void CUDANodeMemoryModel::copyFromBuffer(size_t size, const ArrayRCP<const T> &buffSrc, const ArrayView<T> &hostDest) { CHECK_COMPUTE_BUFFER(buffSrc); TEUCHOS_TEST_FOR_EXCEPTION( (size_t)buffSrc.size() < size, std::runtime_error, "CUDANodeMemoryModel::copyFromBuffer<" << Teuchos::TypeNameTraits<T>::name () << ">: invalid copy. Device source buffer has size " << buffSrc.size () << ", which is less than the requested copy size " << size << "."); TEUCHOS_TEST_FOR_EXCEPTION( (size_t)hostDest.size() < size, std::runtime_error, "CUDANodeMemoryModel::copyFromBuffer<" << Teuchos::TypeNameTraits<T>::name () << ">: invalid copy. Host destination buffer has size " << hostDest.size () << ", which is less than the requested copy size " << size << "."); #ifdef HAVE_KOKKOSCLASSIC_CUDA_NODE_MEMORY_PROFILING ++numCopiesD2H_; bytesCopiedD2H_ += size*sizeof(T); #endif #ifdef HAVE_KOKKOSCLASSIC_CUDA_NODE_MEMORY_TRACE std::cerr << "copyFromBuffer<" << Teuchos::TypeNameTraits<T>::name() << "> of size " << sizeof(T) * size << std::endl; #endif cudaError_t err = cudaMemcpy( hostDest.getRawPtr(), buffSrc.getRawPtr(), size*sizeof(T), cudaMemcpyDeviceToHost); TEUCHOS_TEST_FOR_EXCEPTION( cudaSuccess != err, std::runtime_error, "Kokkos::CUDANodeMemoryModel::copyFromBuffer<" << Teuchos::TypeNameTraits<T>::name () << ">(): cudaMemcpy() returned error: " << cudaGetErrorString (err) ); }
void EpetraCrsMatrixT<EpetraGlobalOrdinal>::setAllValues(const ArrayRCP<size_t>& rowptr, const ArrayRCP<LocalOrdinal>& colind, const ArrayRCP<Scalar>& values) { XPETRA_MONITOR("EpetraCrsMatrixT::setAllValues"); // Check sizes TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(rowptr.size()) != getNodeNumRows()+1, Xpetra::Exceptions::RuntimeError, "An exception is thrown to let you know that the size of your rowptr array is incorrect."); TEUCHOS_TEST_FOR_EXCEPTION(values.size() != colind.size(), Xpetra::Exceptions::RuntimeError, "An exception is thrown to let you know that you mismatched your pointers."); // Check pointers if (values.size() > 0) { TEUCHOS_TEST_FOR_EXCEPTION(colind.getRawPtr() != mtx_->ExpertExtractIndices().Values(), Xpetra::Exceptions::RuntimeError, "An exception is thrown to let you know that you mismatched your pointers."); TEUCHOS_TEST_FOR_EXCEPTION(values.getRawPtr() != mtx_->ExpertExtractValues(), Xpetra::Exceptions::RuntimeError, "An exception is thrown to let you know that you mismatched your pointers."); } // We have to make a copy here, it is unavoidable // See comments in allocateAllValues const size_t N = getNodeNumRows(); Epetra_IntSerialDenseVector& myRowptr = mtx_->ExpertExtractIndexOffset(); myRowptr.Resize(N+1); for (size_t i = 0; i < N+1; i++) myRowptr[i] = Teuchos::as<int>(rowptr[i]); }
/*! \brief Return the max cut for the requested weight. * \param cut on return is the requested value. * \param idx is the weight index reqested, ranging from zero * to one less than the number of weights provided in the input. * If there were no weights, this is the cut count. */ void getMaxWeightedEdgeCut(scalar_t &cut, int idx=0) const{ if (idx >= graphMetrics_.size()) // idx too high cut = graphMetrics_[graphMetrics_.size() - 1].getGlobalMax(); else if (idx < 0) // idx too low cut = graphMetrics_[0].getGlobalMax(); else // cut = graphMetrics_[idx].getGlobalMax(); }
/*! \brief Return the max cut for the requested weight. * \param cut on return is the requested value. * \param idx is the weight index reqested, ranging from zero * to one less than the number of weights provided in the input. * If there were no weights, this is the cut count. */ void getWeightCut(scalar_t &cut, int idx=0) const{ if (graphMetrics_.size() < idx) // idx too high cut = graphMetrics_[graphMetrics_.size()-1].getGlobalMax(); else if (idx < 0) // idx too low cut = graphMetrics_[0].getGlobalMax(); else // idx weight cut = graphMetrics_[idx].getGlobalMax(); }
ArrayRCP<RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> > > MergedSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::SmootherListDeepCopy(const ArrayRCP<const RCP<SmootherPrototype> >& srcSmootherList) { ArrayRCP<RCP<SmootherPrototype> > newSmootherList(srcSmootherList.size()); for (typename ArrayRCP<RCP<SmootherPrototype> >::size_type i = 0; i < srcSmootherList.size(); i++) newSmootherList[i] = srcSmootherList[i]->Copy(); return newSmootherList; }
/*! \brief Return the imbalance for the requested weight. * \param imbalance on return is the requested value. * \param idx is the weight index requested, ranging from zero * to one less than the number of weights provided in the input. * If there were no weights, this is the object count imbalance. */ void getWeightImbalance(scalar_t &imbalance, int idx=0) const{ imbalance = 0; if (metrics_.size() > 2) // idx of multiple weights imbalance = metrics_[idx+2].getMaxImbalance(); else if (metrics_.size() == 2) // only one weight imbalance = metrics_[1].getMaxImbalance(); else // no weights, return object count imbalance imbalance = metrics_[0].getMaxImbalance(); }
ArrayRCP<Scalar> MultiVectorTransferFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::expandCoordinates(ArrayRCP<SC> coordinates, LocalOrdinal blksize) { if (blksize == 1) return coordinates; ArrayRCP<SC> expandCoord(coordinates.size()*blksize); //TODO: how to avoid automatic initialization of the vector? using arcp()? for(int i=0; i<coordinates.size(); i++) { for(int j=0; j< blksize; j++) { expandCoord[i*blksize + j] = coordinates[i]; } } return expandCoord; } // expandCoordinates
void setMap_RankForPart(ArrayRCP<part_t> &parts, ArrayRCP<int> &ranks) { nParts = parts.size(); int maxRank = 0; // Need data stored in unordered_map; create it rankForPart = rcp(new rankmap_t(parts.size())); for (size_t i = 0; i < nParts; i++) { (*rankForPart)[parts[i]] = ranks[i]; if (parts[i] > maxPart) maxPart = parts[i]; if (ranks[i] > maxRank) maxRank = ranks[i]; } nRanks = maxRank+1; }
void UncoupledAggregationAlgorithm<LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::RandomReorder(ArrayRCP<LO> list) const { //TODO: replace int int n = list.size(); for(int i = 0; i < n-1; i++) { std::swap(list[i], list[RandomOrdinal(i,n-1)]); } }
static bool analyzePartitionMetrics( const ParameterList &metricsPlist, const RCP<const Zoltan2::EvaluatePartition <basic_id_t> > &metricObject, const RCP<const Comm<int>> &comm, std::ostringstream &msg_stream) { ArrayRCP<const metric_t> metrics = metricObject->getMetrics(); bool all_tests_pass = true; zscalar_t metric_value = 0.0; for (int i = 0; i < metrics.size(); i++) { // print their names... if (metricsPlist.isSublist(metrics[i].getName())) { auto metric_plist = metricsPlist.sublist(metrics[i].getName()); // loop on tests auto p= metric_plist.begin(); // iterator while (p != metric_plist.end()) { auto test_name = metric_plist.name(p); if( metrics[i].hasMetricValue(test_name)) { if(!MetricAnalyzer::MetricBoundsTest( metrics[i].getMetricValue(test_name), test_name, metric_plist.sublist(test_name), comm, msg_stream)) { all_tests_pass = false; } } else msg_stream << "UNKNOWN TEST: " + test_name << std::endl; ++p; } } else { msg_stream << "UNKNOWN METRIC: " + metrics[i].getName() << std::endl; } } return all_tests_pass; }
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(ParameterListInterpreter, SetParameterList, Scalar, LocalOrdinal, GlobalOrdinal, Node) { # include <MueLu_UseShortNames.hpp> MUELU_TESTING_SET_OSTREAM; MUELU_TESTING_LIMIT_SCOPE(Scalar,GlobalOrdinal,Node); #if defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK) && defined(HAVE_MUELU_IFPACK2) && defined(HAVE_MUELU_AMESOS) && defined(HAVE_MUELU_AMESOS2) RCP<Matrix> A = TestHelpers::TestFactory<SC, LO, GO, NO>::Build1DPoisson(99); RCP<const Teuchos::Comm<int> > comm = TestHelpers::Parameters::getDefaultComm(); ArrayRCP<std::string> fileList = TestHelpers::GetFileList(std::string("ParameterList/ParameterListInterpreter/"), std::string(".xml")); for(int i=0; i< fileList.size(); i++) { out << "Processing file: " << fileList[i] << std::endl; ParameterListInterpreter mueluFactory("ParameterList/ParameterListInterpreter/" + fileList[i],*comm); RCP<Hierarchy> H = mueluFactory.CreateHierarchy(); H->GetLevel(0)->Set("A", A); mueluFactory.SetupHierarchy(*H); //TODO: check no unused parameters //TODO: check results of Iterate() } # else out << "Skipping test because some required packages are not enabled (Tpetra, Epetra, EpetraExt, Ifpack, Ifpack2, Amesos, Amesos2)." << std::endl; # endif }
void BraessSarazinSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Setup(Level& currentLevel) { FactoryMonitor m(*this, "Setup Smoother", currentLevel); if (SmootherPrototype::IsSetup() == true) this->GetOStream(Warnings0) << "MueLu::BreaessSarazinSmoother::Setup(): Setup() has already been called"; // Extract blocked operator A from current level A_ = Factory::Get<RCP<Matrix> > (currentLevel, "A"); RCP<BlockedCrsMatrix> bA = rcp_dynamic_cast<BlockedCrsMatrix>(A_); TEUCHOS_TEST_FOR_EXCEPTION(bA.is_null(), Exceptions::BadCast, "MueLu::BraessSarazinSmoother::Setup: input matrix A is not of type BlockedCrsMatrix! error."); // Store map extractors rangeMapExtractor_ = bA->getRangeMapExtractor(); domainMapExtractor_ = bA->getDomainMapExtractor(); // Store the blocks in local member variables A00_ = MueLu::Utilities<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Crs2Op(bA->getMatrix(0,0)); A01_ = MueLu::Utilities<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Crs2Op(bA->getMatrix(0,1)); A10_ = MueLu::Utilities<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Crs2Op(bA->getMatrix(1,0)); A11_ = MueLu::Utilities<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Crs2Op(bA->getMatrix(1,1)); // TODO move this to BlockedCrsMatrix->getMatrix routine... A00_->CreateView("stridedMaps", bA->getRangeMap(0), bA->getDomainMap(0)); A01_->CreateView("stridedMaps", bA->getRangeMap(0), bA->getDomainMap(1)); A10_->CreateView("stridedMaps", bA->getRangeMap(1), bA->getDomainMap(0)); if (!A11_.is_null()) A11_->CreateView("stridedMaps", bA->getRangeMap(1), bA->getDomainMap(1)); const ParameterList& pL = Factory::GetParameterList(); SC omega = pL.get<SC>("Damping factor"); // Create the inverse of the diagonal of F D_ = VectorFactory::Build(A00_->getRowMap()); ArrayRCP<SC> diag; if (pL.get<bool>("lumping") == false) diag = Utilities::GetMatrixDiagonal (*A00_); else diag = Utilities::GetLumpedMatrixDiagonal(*A00_); SC one = Teuchos::ScalarTraits<SC>::one(); ArrayRCP<SC> Ddata = D_->getDataNonConst(0); for (GO row = 0; row < Ddata.size(); row++) Ddata[row] = one / (diag[row]*omega); // Set the Smoother // carefully switch to the SubFactoryManagers (defined by the users) { SetFactoryManager currentSFM(rcpFromRef(currentLevel), FactManager_); smoo_ = currentLevel.Get<RCP<SmootherBase> >("PreSmoother", FactManager_->GetFactory("Smoother").get()); S_ = currentLevel.Get<RCP<Matrix> > ("A", FactManager_->GetFactory("A").get()); } SmootherPrototype::IsSetup(true); }
void setMap_PartsForRank(ArrayRCP<int> &idx, ArrayRCP<part_t> &parts) { nRanks = idx.size() - 1; nParts = parts.size(); // Need data stored in unordered_map; create it rankForPart = rcp(new rankmap_t(idx[nRanks])); maxPart = 0; for (int i = 0; i < nRanks; i++) { for (part_t j = idx[i]; j < idx[i+1]; j++) { (*rankForPart)[parts[j]] = i; if (parts[j] > maxPart) maxPart = parts[j]; } } // Parts for this rank are already contiguous in parts arcp. // Keep a view of them. partsForRank = parts.persistingView(idx[myRank],idx[myRank+1]-idx[myRank]); }
int dft_linprobmgr_getrhs(void * linprobmgr, double** x) { BLPM * linprobmgr_ = (BLPM *) linprobmgr; ArrayRCP<ArrayRCP<SCALAR> > data = linprobmgr_->getRhs(); for(int j = 0; j < data.size(); j++){ for(int k = 0; k < data[j].size(); k++){ x[j][k] = Teuchos::as<double>(data[j][k]); } } return( 0 ); }
/** \brief . */ void initialize( Teuchos_Ordinal globalOffset_in, Teuchos_Ordinal subDim_in, Teuchos_Ordinal subNz_in, const ArrayRCP<const Scalar> &values_in, ptrdiff_t valuesStride_in, const ArrayRCP<const Teuchos_Ordinal> &indices_in, ptrdiff_t indicesStride_in, ptrdiff_t localOffset_in, bool isSorted_in ) { using Teuchos::as; #ifdef TEUCHOS_DEBUG TEUCHOS_ASSERT(globalOffset_in >= 0); TEUCHOS_ASSERT(subDim_in > 0); TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(subNz_in, 0, subDim_in+1); TEUCHOS_ASSERT_EQUALITY(values_in.lowerOffset(), 0); TEUCHOS_ASSERT(valuesStride_in != 0); TEUCHOS_ASSERT_EQUALITY(values_in.size(), subNz_in*as<Teuchos_Ordinal>(std::abs(as<int>(valuesStride_in)))); if (!is_null(indices_in)) { TEUCHOS_ASSERT(indicesStride_in != 0); TEUCHOS_ASSERT_EQUALITY(indices_in.size(), subNz_in*as<Teuchos_Ordinal>(std::abs(as<int>(indicesStride_in)))); // Note: localOffset can be +, -, or 0 so there is nothing to assert! if (isSorted_in) { for (int k = 0; k < subNz_in-1; ++k) { const Teuchos_Ordinal idx_k = indices_in[k*indicesStride_in]; const Teuchos_Ordinal idx_kp1 = indices_in[(k+1)*indicesStride_in]; TEUCHOS_TEST_FOR_EXCEPTION( !(idx_k < idx_kp1), std::out_of_range, "Error indices["<<k<<"]="<<idx_k<<" >= indices["<<k+1<<"]="<<idx_kp1 <<"!" ); } } } #endif globalOffset_ = globalOffset_in; subDim_ = subDim_in; subNz_ = subNz_in; values_ = values_in; valuesStride_ = valuesStride_in; indices_ = indices_in; indicesStride_ = indicesStride_in; localOffset_ = localOffset_in; isSorted_ = isSorted_in; }
size_t getImportList( const PartitioningSolution<SolutionAdapter> &solution, const DataAdapter * const data, ArrayRCP<typename DataAdapter::zgid_t> &imports // output ) { typedef typename PartitioningSolution<SolutionAdapter>::part_t part_t; typedef typename PartitioningSolution<SolutionAdapter>::gno_t gno_t; typedef typename DataAdapter::zgid_t zgid_t; size_t numParts = solution.getActualGlobalNumberOfParts(); int numProcs = solution.getCommunicator()->getSize(); if (numParts > size_t(numProcs)) { char msg[256]; sprintf(msg, "Number of parts %lu exceeds number of ranks %d; " "%s requires a MappingSolution for this case\n", numParts, numProcs, __func__); throw std::logic_error(msg); } size_t localNumIds = data->getLocalNumIDs(); const zgid_t *gids = NULL; data->getIDsView(gids); const part_t *parts = solution.getPartListView(); // How many ids to each process? Array<int> counts(numProcs, 0); for (size_t i=0; i < localNumIds; i++) counts[parts[i]]++; Array<gno_t> offsets(numProcs+1, 0); for (int i=1; i <= numProcs; i++){ offsets[i] = offsets[i-1] + counts[i-1]; } Array<typename DataAdapter::zgid_t> gidList(localNumIds); for (size_t i=0; i < localNumIds; i++) { gno_t idx = offsets[parts[i]]; gidList[idx] = gids[i]; offsets[parts[i]] = idx + 1; } Array<int> recvCounts(numProcs, 0); try { AlltoAllv<zgid_t>(*(solution.getCommunicator()), *(solution.getEnvironment()), gidList(), counts(), imports, recvCounts()); } Z2_FORWARD_EXCEPTIONS; return imports.size(); }
int LeftoverAggregationAlgorithm<LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::RemoveSmallAggs(Aggregates& aggregates, int min_size, RCP<Xpetra::Vector<double,LO,GO,NO> > & distWeights, const MueLu::CoupledAggregationCommHelper<LO,GO,NO,LMO> & myWidget) const { int myPid = aggregates.GetMap()->getComm()->getRank(); LO nAggregates = aggregates.GetNumAggregates(); ArrayRCP<LO> procWinner = aggregates.GetProcWinner()->getDataNonConst(0); ArrayRCP<LO> vertex2AggId = aggregates.GetVertex2AggId()->getDataNonConst(0); LO size = procWinner.size(); //ArrayRCP<int> AggInfo = Teuchos::arcp<int>(nAggregates+1); //aggregates.ComputeAggSizes(AggInfo); ArrayRCP<LO> AggInfo = aggregates.ComputeAggregateSizes(); ArrayRCP<double> weights = distWeights->getDataNonConst(0); // Make a list of all aggregates indicating New AggId // Use AggInfo array for this. LO NewNAggs = 0; for (LO i = 0; i < nAggregates; i++) { if ( AggInfo[i] < min_size) { AggInfo[i] = MUELU_UNAGGREGATED; } else AggInfo[i] = NewNAggs++; } for (LO k = 0; k < size; k++ ) { if (procWinner[k] == myPid) { if (vertex2AggId[k] != MUELU_UNAGGREGATED) { vertex2AggId[k] = AggInfo[vertex2AggId[k]]; weights[k] = 1.; } if (vertex2AggId[k] == MUELU_UNAGGREGATED) aggregates.SetIsRoot(k,false); } } nAggregates = NewNAggs; //TODO JJH We want to skip this call myWidget.ArbitrateAndCommunicate(*distWeights, aggregates, true); // All tentatively assigned vertices are now definitive // procWinner is not set correctly for aggregates which have // been eliminated for (LO i = 0; i < size; i++) { if (vertex2AggId[i] == MUELU_UNAGGREGATED) procWinner[i] = MUELU_UNASSIGNED; } aggregates.SetNumAggregates(nAggregates); return 0; //TODO } //RemoveSmallAggs
static void jacobianPostRegistration( RCP<Application>& app, ArrayRCP<RCP<FieldManager<AlbanyTraits> > >& fm) { for (int ps=0; ps < fm.size(); ++ps) { std::vector<PHX::index_size_type> dd; dd.push_back(PHAL::getDerivativeDimensions<J>(app.get(), ps)); fm[ps]->setKokkosExtendedDataTypeDimensions<J>(dd); fm[ps]->postRegistrationSetupForType<J>("Jacobian"); } }
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdVector, getMultiVectorLocalData, Scalar ) { out << "Test that we can grab MV data from Vector ...\n"; typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag; RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim); const int procRank = Teuchos::DefaultComm<Ordinal>::getComm()->getRank(); RCP<VectorBase<Scalar> > v = createMember(*vs); const ScalarMag tol = 100.0*ScalarTraits<Scalar>::eps(); const Ordinal globalOffset = procRank * g_localDim; out << "Get non-const MV local data and set it ...\n"; { ArrayRCP<Scalar> localValues; Ordinal leadingDim = -1; rcp_dynamic_cast<SpmdMultiVectorBase<Scalar> >(v,true)->getNonconstLocalData( outArg(localValues), outArg(leadingDim)); TEST_EQUALITY(localValues.size(), g_localDim); TEST_EQUALITY(leadingDim, g_localDim); for (int i = 0; i < localValues.size(); ++i) { localValues[i] = globalOffset + i + 1; } } const Ordinal n = vs->dim(); TEST_FLOATING_EQUALITY(sum<Scalar>(*v), as<Scalar>((n*(n+1))/2.0), tol); out << "Get const MV local data and check it ...\n"; { ArrayRCP<const Scalar> localValues; Ordinal leadingDim = -1; rcp_dynamic_cast<const SpmdMultiVectorBase<Scalar> >(v,true)->getLocalData( outArg(localValues), outArg(leadingDim)); TEST_EQUALITY(localValues.size(), g_localDim); TEST_EQUALITY(leadingDim, g_localDim); for (int i = 0; i < localValues.size(); ++i) { TEST_EQUALITY(localValues[i], as<Scalar>(globalOffset + i + 1)); } } }
GidLookupHelper<T, lno_t>::GidLookupHelper( const RCP<const Environment> &env, const ArrayRCP<const T> &gidList): env_(env), gidList_(gidList), useHashTable_(false), indexMap_(), indexHash_() { lno_t len = gidList_.size(); if (len < 1) return; if (IdentifierTraits<T>::hasUniqueKey()) useHashTable_ = true; const T *ids = gidList_.getRawPtr(); if (!useHashTable_){ try{ for (lno_t i=0; i < gidList.size(); i++){ typename map<T, lno_t>::iterator rec = indexMap_.find(*ids); if (rec == indexMap_.end()) indexMap_[*ids] = i; ids++; } } catch (const std::exception &e){ env_->localMemoryAssertion(__FILE__, __LINE__, len, false); } } else{ typedef typename Teuchos::Hashtable<double, lno_t> id2index_hash_t; id2index_hash_t *p = NULL; try{ p = new id2index_hash_t(len); } catch (const std::exception &e){ env_->localMemoryAssertion(__FILE__, __LINE__, len, false); } for (lno_t i=0; i < len; i++){ double key = IdentifierTraits<T>::key(*ids++); try{ if (!p->containsKey(key)) p->put(key, i); } Z2_THROW_OUTSIDE_ERROR(*env_); } indexHash_ = rcp<id2index_hash_t>(p); } }
std::map<const string, const metric_t> ComparisonHelper::metricArrayToMap(const ArrayRCP<const metric_t> &metrics) { typedef std::pair<const string,const metric_t> pair_t; std::map<const string, const metric_t> metric_map; ArrayRCP<const metric_t>::size_type idx; for(idx = 0; idx < metrics.size(); idx++) { metric_map.insert(pair_t(metrics[idx].getName(),metrics[idx])); } return metric_map; }
RCP<typename BrickAggregationFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::container> BrickAggregationFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>:: Construct1DMap (const RCP<const Teuchos::Comm<int> >& comm, const ArrayRCP<const double>& x) const { int n = x.size(); // Step 1: Create a local vector with unique coordinate points RCP<container> gMap = rcp(new container); for (int i = 0; i < n; i++) (*gMap)[x[i]] = 0; #ifdef HAVE_MPI // Step 2: exchange coordinates // NOTE: we assume the coordinates are double, or double compatible // That means that for complex case, we assume that all imaginary parts are zeros int numProcs = comm->getSize(); if (numProcs > 1) { RCP<const Teuchos::MpiComm<int> > dupMpiComm = rcp_dynamic_cast<const Teuchos::MpiComm<int> >(comm->duplicate()); MPI_Comm rawComm = (*dupMpiComm->getRawMpiComm())(); int sendCnt = gMap->size(), cnt = 0, recvSize; Array<int> recvCnt(numProcs), Displs(numProcs); Array<double> sendBuf, recvBuf; sendBuf.resize(sendCnt); for (typename container::const_iterator cit = gMap->begin(); cit != gMap->end(); cit++) sendBuf[cnt++] = Teuchos::as<double>(STS::real(cit->first)); MPI_Allgather(&sendCnt, 1, MPI_INT, recvCnt.getRawPtr(), 1, MPI_INT, rawComm); Displs[0] = 0; for (int i = 0; i < numProcs-1; i++) Displs[i+1] = Displs[i] + recvCnt[i]; recvSize = Displs[numProcs-1] + recvCnt[numProcs-1]; recvBuf.resize(recvSize); MPI_Allgatherv(sendBuf.getRawPtr(), sendCnt, MPI_DOUBLE, recvBuf.getRawPtr(), recvCnt.getRawPtr(), Displs.getRawPtr(), MPI_DOUBLE, rawComm); for (int i = 0; i < recvSize; i++) (*gMap)[as<SC>(recvBuf[i])] = 0; } #endif GO cnt = 0; for (typename container::iterator it = gMap->begin(); it != gMap->end(); it++) it->second = cnt++; return gMap; }
inline void convert(const DMV& X, RMV& Y) { // Convert X from DomainScalar precision to RangeScalar precision for (size_t j=0; j<X.getNumVectors(); ++j) { ArrayRCP<const DomainScalar> xvecVals = X.getVector( j )->get1dView(); if( xvecVals.size() ) { std::transform( xvecVals.begin(), xvecVals.end(), Y.getVectorNonConst( j )->get1dViewNonConst().begin(), Teuchos::asFunc<RangeScalar>() ); } } return; }
TEUCHOS_UNIT_TEST(MLParameterListInterpreter, SetParameterList) { //TODO: this test can be done at compilation time #if !defined(HAVE_MUELU_EPETRA) or !defined(HAVE_MUELU_IFPACK) or !defined(HAVE_MUELU_AMESOS) if (TestHelpers::Parameters::getLib() == Xpetra::UseEpetra) { out << "Test skipped (dependencies not available)" << std::endl; return; } #endif #if !defined(HAVE_MUELU_TPETRA) or !defined(HAVE_MUELU_IFPACK2) or !defined(HAVE_MUELU_AMESOS2) if (TestHelpers::Parameters::getLib() == Xpetra::UseTpetra) { out << "Test skipped (dependencies not available)" << std::endl; return; } #endif RCP<Matrix> A = TestHelpers::TestFactory<SC, LO, GO, NO>::Build1DPoisson(99); Teuchos::ParameterList galeriParameters; galeriParameters.set("nx",99); RCP<MultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map,MultiVector>("1D", A->getRowMap(), galeriParameters); ArrayRCP<std::string> fileList = TestHelpers::GetFileList(std::string("ParameterList/MLParameterListInterpreter/"), std::string(".xml")); for(int i=0; i< fileList.size(); i++) { out << "Processing file: " << fileList[i] << std::endl; Teuchos::ParameterList myList; myList.set("xml parameter file","ParameterList/MLParameterListInterpreter/" + fileList[i]); Teuchos::ArrayRCP<MultiVector::scalar_type> xcoord=coordinates->getDataNonConst(0); myList.set("x-coordinates",xcoord.get()); MLParameterListInterpreter mueluFactory(myList,A->getRowMap()->getComm()); RCP<Hierarchy> H = mueluFactory.CreateHierarchy(); H->GetLevel(0)->Set<RCP<Matrix> >("A", A); mueluFactory.SetupHierarchy(*H); //TODO: check no unused parameters //TODO: check results of Iterate() } }
TEUCHOS_UNIT_TEST(ML_CreateSublists, SetParameterList) { std::string dir("ParameterList/CreateSublists/"); ArrayRCP<std::string> fileList = TestHelpers::GetFileList(dir, std::string(".xml")); for(int i=0; i< fileList.size(); i++) { out << "Processing file: " << fileList[i] << std::endl; Teuchos::RCP<const Teuchos::ParameterList> inputList = Teuchos::getParametersFromXmlFile(dir + fileList[i]); Teuchos::ParameterList outputList; ML_CreateSublists(*inputList, outputList); // Test against reference output (replace '.xml' by '.output' to get the filename) Teuchos::RCP<Teuchos::ParameterList> refOutputList = Teuchos::getParametersFromXmlFile(dir + fileList[i].substr(0, fileList[i].find_last_of(".")) + ".output"); TEST_EQUALITY(outputList, *refOutputList); } }
void Albany::ProjectionProblem::buildProblem( ArrayRCP<RCP<Albany::MeshSpecsStruct> > mesh_specs, Albany::StateManager & state_manager) { // Construct all Phalanx evaluators TEUCHOS_TEST_FOR_EXCEPTION( mesh_specs.size() != 1, std::logic_error, "Problem supports one Material Block"); fm.resize(1); fm[0] = rcp(new PHX::FieldManager<AlbanyTraits>); buildEvaluators( *fm[0], *mesh_specs[0], state_manager, BUILD_RESID_FM, Teuchos::null); constructDirichletEvaluators(*mesh_specs[0]); }
/*! \brief Print all the metrics */ void printGraphMetrics(std::ostream &os) const { Zoltan2::printMetrics<scalar_t, part_t>(os, targetGlobalParts_, numGlobalParts_, graphMetrics_.view(0, graphMetrics_.size())); }
void AggregationPhase1Algorithm_kokkos<LocalOrdinal, GlobalOrdinal, Node>::RandomReorder(ArrayRCP<LO> list) const { //TODO: replace int int n = list.size(); for(int i = 0; i < n-1; i++) std::swap(list[i], list[RandomOrdinal(i,n-1)]); }
/*! \brief Return the object normed weight imbalance. * \param imbalance on return is the object normed weight imbalance. * If there were no weights, this is the object count imbalance. * If there was one weight, it is the imbalance with respect to that weight. */ void getNormedImbalance(scalar_t &imbalance) const{ if (metrics_.size() > 1) imbalance = metrics_[1].getMaxImbalance(); else imbalance = metrics_[0].getMaxImbalance(); }
TEUCHOS_UNIT_TEST(Aggregates, UncoupledPhase3) { out << "version: " << MueLu::Version() << std::endl; RCP<Matrix> A = TestHelpers::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36); RCP<const Map> rowmap = A->getRowMap(); RCP<AmalgamationInfo> amalgInfo; RCP<Aggregates> aggregates = gimmeUncoupledAggregates(A, amalgInfo,false,false,false,true); GO numAggs = aggregates->GetNumAggregates(); RCP<const Teuchos::Comm<int> > comm = TestHelpers::Parameters::getDefaultComm(); TEST_EQUALITY(aggregates->AggregatesCrossProcessors(),false); ArrayRCP<LO> aggSizes = Teuchos::ArrayRCP<LO>(numAggs); ArrayRCP<LO> aggStart; ArrayRCP<GO> aggToRowMap; amalgInfo->UnamalgamateAggregates(*aggregates, aggStart, aggToRowMap); for (LO i = 0; i < numAggs; ++i) aggSizes[i] = aggStart[i+1] - aggStart[i]; bool foundAggNotSize2=false; for (int i=0; i<aggSizes.size(); ++i) if (aggSizes[i] != 2) { foundAggNotSize2=true; break; } switch (comm->getSize()) { case 1 : TEST_EQUALITY(numAggs, 18); TEST_EQUALITY(foundAggNotSize2, false); break; case 2: TEST_EQUALITY(numAggs, 9); TEST_EQUALITY(foundAggNotSize2, false); break; case 3: TEST_EQUALITY(numAggs, 6); TEST_EQUALITY(foundAggNotSize2, false); break; case 4: TEST_EQUALITY(numAggs, 4); TEST_EQUALITY(foundAggNotSize2, true); break; default: std::string msg = "Only 1-4 MPI processes are supported."; //throw(MueLu::Exceptions::NotImplemented(msg)); out << msg << std::endl; break; } //ArrayRCP< ArrayRCP<GO> > aggToRowMap(numAggs); int root = out.getOutputToRootOnly(); out.setOutputToRootOnly(-1); for (int j=0; j<comm->getSize(); ++j) { if (comm->getRank() == j) { out << "++ pid " << j << " ++" << std::endl; out << " num local DOFs = " << rowmap->getNodeNumElements() << std::endl; for (int i=0; i< numAggs; ++i) { out << " aggregate " << i << ": "; for (int k=aggStart[i]; k< aggStart[i+1]; ++k) out << aggToRowMap[k] << " "; out << std::endl; } } comm->barrier(); } out.setOutputToRootOnly(root); } //UncoupledPhase3