Example #1
0
TEST(ArrayRefTests, arrayView) {
  uint8_t data[4] = {2, 3, 5, 7};
  const ArrayRef<> ref(data);
  ArrayView<> view = ref;
  ASSERT_EQ(ref.getData(), view.getData());
  ASSERT_EQ(ref.getSize(), view.getSize());
}
Example #2
0
  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 DefaultProductMultiVector<Scalar>::initializeImpl(
    const RCP<const DefaultProductVectorSpace<Scalar> > &productSpace_in,
    const ArrayView<const RCP<MultiVectorType> > &multiVecs
)
{
    // This function provides the "strong" guarantee (i.e. if an exception is
    // thrown, then *this will be left in the original state as before the
    // function was called)!
#ifdef TEUCHOS_DEBUG
    TEUCHOS_ASSERT(nonnull(productSpace_in));
    TEUCHOS_ASSERT_EQUALITY(multiVecs.size(), productSpace_in->numBlocks());
#endif // TEUCHOS_DEBUG
    const RCP<const VectorSpaceBase<Scalar> >
    theDomain = multiVecs[0]->domain();
    const int numBlocks = productSpace_in->numBlocks();
#ifdef TEUCHOS_DEBUG
    for ( int k = 0; k < numBlocks; ++k ) {
        THYRA_ASSERT_VEC_SPACES(
            Teuchos::TypeNameTraits<DefaultProductMultiVector<Scalar> >::name(),
            *theDomain, *multiVecs[k]->domain()
        );
    }
#endif
    productSpace_ = productSpace_in;
    numBlocks_ = numBlocks;
    multiVecs_.assign(multiVecs.begin(),multiVecs.end());
}
void MpiComm<Ordinal>::waitAll(
    const ArrayView<RCP<CommRequest> > &requests
) const
{
    TEUCHOS_COMM_TIME_MONITOR(
        "Teuchos::MpiComm<"<<OrdinalTraits<Ordinal>::name()<<">::waitAll(...)"
    );
    const int count = requests.size();
#ifdef TEUCHOS_DEBUG
    TEST_FOR_EXCEPT( requests.size() == 0 );
#endif

    Array<MPI_Request> rawMpiRequests(count, MPI_REQUEST_NULL);
    for (int i = 0; i < count; ++i) {
        RCP<CommRequest> &request = requests[i];
        if (!is_null(request)) {
            const RCP<MpiCommRequest> mpiCommRequest =
                rcp_dynamic_cast<MpiCommRequest>(request);
            rawMpiRequests[i] = mpiCommRequest->releaseRawMpiRequest();
        }
        // else already null
        request = null;
    }

    Array<MPI_Status> rawMpiStatuses(count);
    MPI_Waitall( count, rawMpiRequests.getRawPtr(), rawMpiStatuses.getRawPtr() );
    // ToDo: We really should check the status?

}
void Thyra::apply_op_validate_input(
  const std::string &func_name,
  const VectorSpaceBase<Scalar> &domain,
  const VectorSpaceBase<Scalar> &range,
  const RTOpPack::RTOpT<Scalar> &primary_op,
  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
  const Ordinal primary_global_offset_in
  )
{
  using Teuchos::as;
  // Validate primary range arguments
  TEST_FOR_EXCEPTION(
    primary_global_offset_in < 0, std::logic_error
    ,func_name << " : Error! primary_global_offset_in = "
    <<primary_global_offset_in<<" is not valid" );
  // Validate secondary domain arguments
  // Validate spaces
  for (int k = 0; k < multi_vecs.size(); ++k) {
    THYRA_ASSERT_VEC_SPACES(func_name,domain,*multi_vecs[k]->domain());
    THYRA_ASSERT_VEC_SPACES(func_name,range,*multi_vecs[k]->range());
  }
  for (int k = 0; k < targ_multi_vecs.size(); ++k) {
    THYRA_ASSERT_VEC_SPACES(func_name,domain,*targ_multi_vecs[k]->domain());
    THYRA_ASSERT_VEC_SPACES(func_name,range,*targ_multi_vecs[k]->range());
  }
}
Example #6
0
ble_error_t nRF5xGap::update_identities_list(bool resolution_enabled)
{
    uint32_t err;

    if (resolution_enabled) {
        ArrayView<ble_gap_id_key_t> entries = get_sm().get_resolving_list();
        size_t limit = std::min(
            entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE
        );
        ble_gap_id_key_t* id_keys_pp[YOTTA_CFG_IRK_TABLE_MAX_SIZE];

        for (size_t i = 0; i < limit; ++i) {
            id_keys_pp[i] = &entries[i];
        }

        err = sd_ble_gap_device_identities_set(
            limit ? id_keys_pp : NULL,
            /* use the local IRK for all devices */ NULL,
            limit
        );
    } else {
        err = sd_ble_gap_device_identities_set(
            NULL,
            /* use the local IRK for all devices */ NULL,
            0
        );
    }

    return err ? BLE_ERROR_INVALID_STATE : BLE_ERROR_NONE;
}
void MpiComm<Ordinal>::readySend(
    const ArrayView<const char> &sendBuffer,
    const int destRank
) const
{
    TEUCHOS_COMM_TIME_MONITOR(
        "Teuchos::MpiComm<"<<OrdinalTraits<Ordinal>::name()<<">::readySend(...)"
    );
#ifdef TEUCHOS_DEBUG
    TEST_FOR_EXCEPTION(
        ! ( 0 <= destRank && destRank < size_ ), std::logic_error
        ,"Error, destRank = " << destRank << " is not < 0 or is not"
        " in the range [0,"<<size_-1<<"]!"
    );
#endif // TEUCHOS_DEBUG
#ifdef TEUCHOS_MPI_COMM_DUMP
    if(show_dump) {
        dumpBuffer<Ordinal,char>(
            "Teuchos::MpiComm<Ordinal>::readySend(...)"
            ,"sendBuffer", bytes, sendBuffer
        );
    }
#endif // TEUCHOS_MPI_COMM_DUMP
    MPI_Rsend(
        const_cast<char*>(sendBuffer.getRawPtr()),sendBuffer.size(),MPI_CHAR,destRank,tag_,*rawMpiComm_
    );
    // ToDo: What about error handling???
}
Example #8
0
  void LeftoverAggregationAlgorithm<LocalOrdinal, GlobalOrdinal, Node, LocalMatOps>::RootCandidates(my_size_t nVertices,
  ArrayView<const LO> & vertex2AggId, GraphBase const &graph,
                      ArrayRCP<LO> &candidates, my_size_t &nCandidates, global_size_t &nCandidatesGlobal) const
  {
    nCandidates = 0;

    for (my_size_t i = 0; i < nVertices; i++ ) {
      if (vertex2AggId[i] == MUELU_UNAGGREGATED) {
        bool noAggdNeighbors = true;

        // neighOfINode is the neighbor node list of node 'iNode'.
        ArrayView<const LO> neighOfINode = graph.getNeighborVertices(i);

        for (typename ArrayView<const LO>::const_iterator it = neighOfINode.begin(); it != neighOfINode.end(); ++it) {
          int adjacent    = *it;
          if (vertex2AggId[adjacent] != MUELU_UNAGGREGATED)
            noAggdNeighbors = false;
        }
        if (noAggdNeighbors == true) candidates[nCandidates++] = i;
      }
    }

    sumAll(graph.GetComm(), (GO)nCandidates, nCandidatesGlobal);

  } //RootCandidates
  void
  AbstractConcreteMatrixAdapter<
    Epetra_RowMatrix,
    DerivedMat>::getGlobalRowCopy_impl(global_ordinal_t row,
                                       const ArrayView<global_ordinal_t>& indices,
                                       const ArrayView<scalar_t>& vals,
                                       size_t& nnz) const
  {
    using Teuchos::as;

    local_ordinal_t local_row = this->row_map_->getLocalElement(row);
    int nnz_ret = 0;
    int rowmatrix_return_val
      = this->mat_->ExtractMyRowCopy(as<int>(local_row),
                                     as<int>(std::min(indices.size(), vals.size())),
                                     nnz_ret,
                                     vals.getRawPtr(),
                                     indices.getRawPtr());
    TEUCHOS_TEST_FOR_EXCEPTION( rowmatrix_return_val != 0,
                        std::runtime_error,
                        "Epetra_RowMatrix object returned error code "
                        << rowmatrix_return_val << " from ExtractMyRowCopy." );
    nnz = as<size_t>(nnz_ret);

    // Epetra_CrsMatrix::ExtractMyRowCopy returns local column
    // indices, so transform these into global indices
    for( size_t i = 0; i < nnz; ++i ){
      indices[i] = this->col_map_->getGlobalElement(indices[i]);
    }
  }
Example #10
0
    std::pair<CudaEvent, view_type>
    copy(const ArrayView<
                value_type,
                HostCoordinator<
                    value_type,
                    PinnedAllocator<
                        value_type,
                        alignment>>> &from,
         view_type &to) {
        assert(from.size()==to.size());

        #ifdef VERBOSE
        using oType = ArrayView< value_type, HostCoordinator< value_type, PinnedAllocator< value_type, alignment>>>;
        std::cout << util::pretty_printer<DeviceCoordinator>::print(*this)
                  << "::" << util::blue("copy") << "(asynchronous, " << from.size() << ")"
                  << "\n  " << util::type_printer<oType>::print() << " @ " << from.data()
                  << util::yellow(" -> ")
                  << util::type_printer<view_type>::print() << " @ " << to.data() << std::endl;
        #endif

        auto status = cudaMemcpy(
                reinterpret_cast<void*>(to.begin()),
                reinterpret_cast<const void*>(from.begin()),
                from.size()*sizeof(value_type),
                cudaMemcpyHostToDevice
        );
        if(status != cudaSuccess) {
            std::cerr << util::red("error") << " bad CUDA memcopy, unable to copy " << sizeof(T)*from.size() << " bytes from host to device";
            exit(-1);
        }

        CudaEvent event;
        return std::make_pair(event, to);
    }
Example #11
0
//-----------------------------------------------------------------------------
void Function::restrict(double* w, const FiniteElement& element,
                        const Cell& dolfin_cell,
                        const double* coordinate_dofs,
                        const ufc::cell& ufc_cell) const
{
  dolfin_assert(w);
  dolfin_assert(_function_space);
  dolfin_assert(_function_space->dofmap());

  // Check if we are restricting to an element of this function space
  if (_function_space->has_element(element)
      && _function_space->has_cell(dolfin_cell))
  {
    // Get dofmap for cell
    const GenericDofMap& dofmap = *_function_space->dofmap();
    const ArrayView<const dolfin::la_index> dofs
      = dofmap.cell_dofs(dolfin_cell.index());

    // Note: We should have dofmap.max_element_dofs() == dofs.size() here.
    // Pick values from vector(s)
    _vector->get_local(w, dofs.size(), dofs.data());
  }
  else
  {
    // Restrict as UFC function (by calling eval)
    restrict_as_ufc_function(w, element, dolfin_cell, coordinate_dofs,
                             ufc_cell);
  }
}
RCP<Epetra_CrsMatrix> UserInputForTests::getEpetraCrsMatrix()
{
  if (M_.is_null())
    throw std::runtime_error("could not read mtx file");
  RCP<Epetra_CrsGraph> egraph = getEpetraCrsGraph();
  eM_ = rcp(new Epetra_CrsMatrix(Copy, *egraph));

  size_t maxRow = M_->getNodeMaxNumRowEntries();
  int nrows = egraph->NumMyRows();
  int base = egraph->IndexBase();
  const Epetra_BlockMap &rowMap = egraph->RowMap();
  const Epetra_BlockMap &colMap = egraph->ColMap();
  Array<int> colGid(maxRow);

  for (int i=0; i < nrows; i++){
    ArrayView<const int> colLid;
    ArrayView<const scalar_t> nz;
    M_->getLocalRowView(i+base, colLid, nz);
    size_t rowSize = colLid.size();
    int rowGid = rowMap.GID(i+base);
    for (size_t j=0; j < rowSize; j++){
      colGid[j] = colMap.GID(colLid[j]);
    }
    eM_->InsertGlobalValues(
      rowGid, rowSize, nz.getRawPtr(), colGid.getRawPtr());
  }
  eM_->FillComplete();
  return eM_;
}
  void EpetraCrsMatrixT<EpetraGlobalOrdinal>::getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
    XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");

    int numEntries = -1;
    XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
    NumEntries = numEntries;
  }
 void compute_weight(Function& DG)
 { // Compute weights for averaging with neighboring cells
     
   // Get the mesh, element and dofmap
   std::shared_ptr<const FunctionSpace> V = DG.function_space(); 
   std::shared_ptr<const Mesh> mesh = V->mesh();
   std::shared_ptr<const FiniteElement> element = V->element();
   std::shared_ptr<const GenericDofMap> dofmap_u = V->dofmap();
   
   // Allocate storage for weights on one cell
   std::vector<double> ws(element->space_dimension()); 
       
   // Compute weights
   GenericVector& dg_vector = *DG.vector();  
   dg_vector.zero();
   for (CellIterator cell(*mesh, "all"); !cell.end(); ++cell)
   {
     const ArrayView<const dolfin::la_index> dofs
       = dofmap_u->cell_dofs(cell->index());
       
     std::fill(ws.begin(), ws.end(), 1./cell->volume());
     dg_vector.add_local(ws.data(), dofs.size(), dofs.data());    
   }  
   dg_vector.apply("insert"); 
 }
Example #15
0
  // Create and return a simple example CrsMatrix, with row
  // distribution over the given Map.
  Teuchos::RCP<const TpetraMatrixType>
  create (const Teuchos::RCP<const map_type>& map) const
  {
    using Teuchos::arcp;
    using Teuchos::ArrayRCP;
    using Teuchos::ArrayView;
    using Teuchos::RCP;
    using Teuchos::rcp;
    using Teuchos::Time;
    using Teuchos::TimeMonitor;
    using Teuchos::tuple;
    typedef Tpetra::global_size_t GST;

    // Create a timer for sparse matrix creation.
    RCP<Time> timer = TimeMonitor::getNewCounter ("Sparse matrix creation");

    // Time the whole scope of this routine, not counting timer lookup.
    TimeMonitor monitor (*timer);

    // Create a Tpetra::Matrix using the Map, with dynamic allocation.
    RCP<TpetraMatrixType> A = rcp (new TpetraMatrixType (map, 3));

    // Add rows one at a time.  Off diagonal values will always be -1.
    const scalar_type two    = static_cast<scalar_type>( 2.0);
    const scalar_type negOne = static_cast<scalar_type>(-1.0);

    const GST numGlobalElements = map->getGlobalNumElements ();
    //    const size_t numMyElements = map->getNodeNumElements ();

    // The list of global elements owned by this MPI process.
    ArrayView<const global_ordinal_type> myGlobalElements =
      map->getNodeElementList ();

    typedef typename ArrayView<const global_ordinal_type>::const_iterator iter_type;
    for (iter_type it = myGlobalElements.begin(); it != myGlobalElements.end(); ++it) {
      const local_ordinal_type i_local = *it;
      const global_ordinal_type i_global = map->getGlobalElement (i_local);

      // Can't insert local indices without a column map, so we insert
      // global indices here.
      if (i_global == 0) {
        A->insertGlobalValues (i_global,
                              tuple (i_global, i_global+1),
                              tuple (two, negOne));
      } else if (static_cast<GST> (i_global) == numGlobalElements - 1) {
        A->insertGlobalValues (i_global,
                              tuple (i_global-1, i_global),
                              tuple (negOne, two));
      } else {
        A->insertGlobalValues (i_global,
                              tuple (i_global-1, i_global, i_global+1),
                              tuple (negOne, two, negOne));
      }
    }

    // Finish up the matrix.
    A->fillComplete ();
    return A;
  }
Example #16
0
REFCOUNTPTR_INLINE
Teuchos::ArrayView<T2>
Teuchos::av_const_cast(const ArrayView<T1>& p1)
{
  T2 *ptr2 = const_cast<T2*>(p1.getRawPtr());
  return ArrayView<T2>(ptr2, p1.size());
  // Note: Above is just fine even if p1.get()==NULL!
}
TestLagrPolyMeritFunc1D<Scalar>::TestLagrPolyMeritFunc1D(
  const ArrayView<const Scalar> &alpha,
  const ArrayView<const Scalar> &phi
  )
  : alpha_(alpha), phi_(phi)
{
  TEUCHOS_ASSERT_EQUALITY(alpha.size(), phi.size());
}
Example #18
0
template<class T> inline
void ArrayRCP<T>::deepCopy(const ArrayView<const T>& av)
{
  if (av.size() == 0) {
    *this = null;
    return;
  }
  assign(av.begin(), av.end());
}
void MultiVectorDefaultBase<Scalar>::mvMultiReductApplyOpImpl(
  const RTOpPack::RTOpT<Scalar> &prim_op,
  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
  const Ordinal prim_global_offset_in
  ) const
{

  using Teuchos::Workspace;
  using Teuchos::as;
  Teuchos::WorkspaceStore* wss = Teuchos::get_default_workspace_store().get();

  const int num_multi_vecs = multi_vecs.size();
  const int num_targ_multi_vecs = targ_multi_vecs.size();

  // ToDo: Validate the input!

  const VectorSpaceBase<Scalar> &l_domain = *this->domain();

  // Get the primary and secondary dimensions.

  const Ordinal sec_dim = l_domain.dim();

  //
  // Apply the reduction/transformation operator and transform the
  // target vectors and reduce each of the reduction objects.
  //

  Workspace<RCP<const VectorBase<Scalar> > > vecs_s(wss, num_multi_vecs);
  Workspace<Ptr<const VectorBase<Scalar> > > vecs(wss, num_multi_vecs);
  Workspace<RCP<VectorBase<Scalar> > > targ_vecs_s(wss, num_targ_multi_vecs);
  Workspace<Ptr<VectorBase<Scalar> > > targ_vecs(wss, num_targ_multi_vecs);

  for(Ordinal j = 0; j < sec_dim; ++j) {
    // Fill the arrays of vector arguments
    {for(Ordinal k = 0; k < as<Ordinal>(num_multi_vecs); ++k) {
        vecs_s[k] = multi_vecs[k]->col(j);
        vecs[k] = vecs_s[k].ptr();
      }}
    {for(Ordinal k = 0; k < as<Ordinal>(num_targ_multi_vecs); ++k) {
        targ_vecs_s[k] = targ_multi_vecs[k]->col(j);
        targ_vecs[k] = targ_vecs_s[k].ptr();
      }}
    // Apply the reduction/transformation operator
    Thyra::applyOp(
      prim_op,
      vecs().getConst(),
      targ_vecs().getConst(),
      reduct_objs.size() ? reduct_objs[j] : Ptr<RTOpPack::ReductTarget>(),
      prim_global_offset_in);
  }
  // At this point all of the designated targ vectors in the target multi-vectors have
  // been transformed and all the reduction objects in reduct_obj[] have accumulated
  // the reductions.
}
TEUCHOS_UNIT_TEST( Rythmos_StackedStepper, addgetStepper ) {
    RCP<StackedStepper<double> > sStepper = stackedStepper<double>();
    {
        ArrayView<const RCP<StepperBase<double> > > stepperArray;
        stepperArray = sStepper->getNonconstSteppers();
        TEST_ASSERT( stepperArray.size() == 0 );
    }
    {
        RCP<StepperBase<double> > stepper;
        const RCP<StepperBuilder<double> > builder = stepperBuilder<double>();
        RCP<ParameterList> pl = Teuchos::parameterList();
        pl->set("Stepper Type","Explicit RK");
        builder->setParameterList(pl);
        stepper = builder->create();
        sStepper->addStepper(stepper);
        pl->set("Stepper Type","Implicit RK");
        sStepper->addStepper(builder->create());
        pl->set("Stepper Type","Implicit BDF");
        sStepper->addStepper(builder->create());
    }
    ArrayView<const RCP<StepperBase<double> > > stepperArray;
    stepperArray = sStepper->getNonconstSteppers();
    TEST_ASSERT(stepperArray.size() == 3);

    RCP<const StepperBase<double> > stepper;
    stepper = stepperArray[0];
    TEST_ASSERT( !is_null(stepper) );
    {
        RCP<const ExplicitRKStepper<double> > erkStepper =
            Teuchos::rcp_dynamic_cast<const ExplicitRKStepper<double> >(
                stepper,
                false
            );
        TEST_ASSERT( !is_null(erkStepper) );
    }
    stepper = stepperArray[1];
    TEST_ASSERT( !is_null(stepper) );
    {
        RCP<const ImplicitRKStepper<double> > irkStepper =
            Teuchos::rcp_dynamic_cast<const ImplicitRKStepper<double> >(
                stepper,
                false
            );
        TEST_ASSERT( !is_null(irkStepper) );
    }
    stepper = stepperArray[2];
    TEST_ASSERT( !is_null(stepper) );
    {
        RCP<const ImplicitBDFStepper<double> > ibdfStepper =
            Teuchos::rcp_dynamic_cast<const ImplicitBDFStepper<double> >(
                stepper,
                false
            );
        TEST_ASSERT( !is_null(ibdfStepper) );
    }
}
Example #21
0
void TextureAtlas::set_regions(const ArrayView<int>& rects)
{
    R_ASSERT(rects.size() % 4 == 0,
             "Rectangle data size must be a multiple of 4");

    regions_.clear();
    regions_.reserve(rects.size() / 4);
    for (size_t i = 0; i < rects.size(); i += 4)
        add_region(rects[i], rects[i + 1], rects[i + 2], rects[i + 3]);
}
Example #22
0
inline void verify_empty(const ArrayView<T> &v)
{
  // NOTE: implicitly tests data(), size(), begin(), cbegin(), and
  //       operator bool()
  REQUIRE(!v);
  REQUIRE(v.data() == nullptr);
  REQUIRE(v.size() == 0);
  REQUIRE(v.begin() == nullptr);
  REQUIRE(v.cbegin() == nullptr);
}
void GlobalMPISession::allGather(int localVal, const ArrayView<int> &allVals)
{
  justInTimeInitialize();
  TEUCHOS_ASSERT_EQUALITY(allVals.size(), getNProc());
#ifdef HAVE_MPI
  MPI_Allgather( &localVal, 1, MPI_INT, allVals.getRawPtr(), 1, MPI_INT,
    MPI_COMM_WORLD);
#else
  allVals[0] = localVal;
#endif
}
Example #24
0
void ArrayView<T>::assign(const ArrayView<const T>& array) const
{
  debug_assert_valid_ptr();
  debug_assert_not_null();
  if (this->getRawPtr()==array.getRawPtr() && this->size()==array.size())
    return; // Assignment to self
  debug_assert_in_range(0,array.size());
  std::copy( array.begin(), array.end(), this->begin() );
  // Note: Above, in debug mode, the iterators are range checked!  In
  // optimized mode, these are raw pointers which should run very fast!
}
Example #25
0
Array<Sacado::Fad::DFad<ScalarT> > convertToPassiveFadArray(
  const ArrayView<const ScalarT> &av
  )
{
  using Sacado::Fad::DFad;
  Array<DFad<ScalarT> > a_fad(av.size());
  for (int i = 0; i < av.size(); ++i) {
    a_fad[i] = DFad<double>(av[i]);
  }
  return a_fad;
}
Example #26
0
Array<Sacado::Fad::DFad<ScalarT> > convertToIndepVarFadArray(
  const ArrayView<const ScalarT> &av, const int num_derivs,
  const Ptr<int> &deriv_idx)
{
  using Sacado::Fad::DFad;
  Array<DFad<ScalarT> > a_fad(av.size());
  for (int i = 0; i < av.size(); ++i) {
    a_fad[i] = DFad<double>(num_derivs, (*deriv_idx)++, av[i]);
  }
  return a_fad;
}
Example #27
0
 void getStridedStats(const ArrayView<scalar_t> &v, int stride, 
   int offset, scalar_t &min, scalar_t &max, scalar_t &sum)
{
  if (v.size() < 1) return;
  min = max = sum = v[offset];

  for (int i=offset+stride; i < v.size(); i += stride){
    if (v[i] < min) min = v[i];
    else if (v[i] > max) max = v[i];
    sum += v[i];
  }
}
Example #28
0
  inline void CUDANodeMemoryModel::readyBuffers(ArrayView<ArrayRCP<const char> > buffers, ArrayView<ArrayRCP<char> > ncBuffers) {
#ifdef HAVE_KOKKOSCLASSIC_DEBUG
    for (size_t i=0; i < (size_t)buffers.size(); ++i) {
      CHECK_COMPUTE_BUFFER(buffers[i]);
    }
    for (size_t i=0; i < (size_t)ncBuffers.size(); ++i) {
      CHECK_COMPUTE_BUFFER(ncBuffers[i]);
    }
#endif
    (void)buffers;
    (void)ncBuffers;
  }
Example #29
0
//-----------------------------------------------------------------------------
void DofMap::set(GenericVector& x, double value) const
{
  dolfin_assert(_dofmap.size() % _cell_dimension == 0);
  const std::size_t num_cells = _dofmap.size() / _cell_dimension;

  std::vector<double> _value(_cell_dimension, value);
  for (std::size_t i = 0; i < num_cells; ++i)
  {
    const ArrayView<const la_index> dofs = cell_dofs(i);
    x.set_local(_value.data(), dofs.size(), dofs.data());
  }
  x.apply("insert");
}
    bool CheckConsistency() const {
      const RCP<const Map> fullMap = getFullMap();

      for (size_t i = 0; i < NumMaps(); i++) {
        const RCP<const Map> map = getMap(i);

        ArrayView<const GlobalOrdinal> mapGids = map->getNodeElementList();
        for (typename ArrayView< const GlobalOrdinal >::const_iterator it = mapGids.begin(); it != mapGids.end(); it++)
          if (fullMap->isNodeGlobalElement(*it) == false)
            return false; // Global ID (*it) not found locally on this proc in fullMap -> error
      }
      return true;
    }