packages/Alea/mc_solvers/MC_Data.cc
//---------------------------------------------------------------------------//
// Convert matrices to Kokkos View storage
//---------------------------------------------------------------------------//
Convert matrices to Kokkos View storage
Convert matrices to Kokkos View storage
MC_Data_View MC_Data::createKokkosViews()
{
    REQUIRE( d_H->isLocallyIndexed() );
    REQUIRE( d_P->isLocallyIndexed() );
    REQUIRE( d_W->isLocallyIndexed() );
    REQUIRE( d_H->supportsRowViews() );
    REQUIRE( d_P->supportsRowViews() );
    REQUIRE( d_W->supportsRowViews() );
    LO numRows     = d_H->getNodeNumRows();
    GO numNonZeros = d_H->getNodeNumEntries();
    scalar_view H("H",numNonZeros);
    scalar_view P("H",numNonZeros);
    scalar_view W("H",numNonZeros);
    ord_view    inds("inds",numNonZeros);
    ord_view    offsets("offsets",numRows+1);
    scalar_host_mirror H_host       = Kokkos::create_mirror_view(H);
    scalar_host_mirror P_host       = Kokkos::create_mirror_view(P);
    scalar_host_mirror W_host       = Kokkos::create_mirror_view(W);
    ord_host_mirror    inds_host    = Kokkos::create_mirror_view(inds);
    ord_host_mirror    offsets_host = Kokkos::create_mirror_view(offsets);
    Teuchos::ArrayView<const double> H_row, P_row, W_row;
    Teuchos::ArrayView<const int> ind_row;
    LO count = 0;
    for( LO irow=0; irow<numRows; ++irow )
    {
        d_H->getLocalRowView(irow,ind_row,H_row);
        d_P->getLocalRowView(irow,ind_row,P_row);
        d_W->getLocalRowView(irow,ind_row,W_row);
        std::copy( H_row.begin(), H_row.end(), &H_host(count) );
        std::copy( P_row.begin(), P_row.end(), &P_host(count) );
        std::copy( W_row.begin(), W_row.end(), &W_host(count) );
        std::copy( ind_row.begin(), ind_row.end(), &inds_host(count) );
        count += ind_row.size();
        offsets_host(irow+1) = count;
    }
    d_H       = Teuchos::null;
    d_P       = Teuchos::null;
    d_W       = Teuchos::null;
    Kokkos::deep_copy(H,H_host);
    Kokkos::deep_copy(P,P_host);
    Kokkos::deep_copy(W,W_host);
    Kokkos::deep_copy(inds,inds_host);
    Kokkos::deep_copy(offsets,offsets_host);
    return MC_Data_View(H,P,W,inds,offsets);
}
MC_Data_View MC_Data :: createKokkosViews ( ) { REQUIRE ( d_H -> isLocallyIndexed ( ) ) ; REQUIRE ( d_P -> isLocallyIndexed ( ) ) ; REQUIRE ( d_W -> isLocallyIndexed ( ) ) ; REQUIRE ( d_H -> supportsRowViews ( ) ) ; REQUIRE ( d_P -> supportsRowViews ( ) ) ; REQUIRE ( d_W -> supportsRowViews ( ) ) ; LO numRows = d_H -> getNodeNumRows ( ) ; GO numNonZeros = d_H -> getNodeNumEntries ( ) ; scalar_view H ( " " , numNonZeros ) ; scalar_view P ( " " , numNonZeros ) ; scalar_view W ( " " , numNonZeros ) ; ord_view inds ( " " , numNonZeros ) ; ord_view offsets ( " " , numRows + 1 ) ; scalar_host_mirror H_host = Kokkos :: create_mirror_view ( H ) ; scalar_host_mirror P_host = Kokkos :: create_mirror_view ( P ) ; scalar_host_mirror W_host = Kokkos :: create_mirror_view ( W ) ; ord_host_mirror inds_host = Kokkos :: create_mirror_view ( inds ) ; ord_host_mirror offsets_host = Kokkos :: create_mirror_view ( offsets ) ; Teuchos :: ArrayView < const double > H_row , P_row , W_row ; Teuchos :: ArrayView < const int > ind_row ; LO count = 0 ; for ( LO irow = 0 ; irow < numRows ; ++ irow ) { d_H -> getLocalRowView ( irow , ind_row , H_row ) ; d_P -> getLocalRowView ( irow , ind_row , P_row ) ; d_W -> getLocalRowView ( irow , ind_row , W_row ) ; std :: copy ( H_row . begin ( ) , H_row . end ( ) , & H_host ( count ) ) ; std :: copy ( P_row . begin ( ) , P_row . end ( ) , & P_host ( count ) ) ; std :: copy ( W_row . begin ( ) , W_row . end ( ) , & W_host ( count ) ) ; std :: copy ( ind_row . begin ( ) , ind_row . end ( ) , & inds_host ( count ) ) ; count += ind_row . size ( ) ; offsets_host ( irow + 1 ) = count ; } d_H = Teuchos :: null ; d_P = Teuchos :: null ; d_W = Teuchos :: null ; Kokkos :: deep_copy ( H , H_host ) ; Kokkos :: deep_copy ( P , P_host ) ; Kokkos :: deep_copy ( W , W_host ) ; Kokkos :: deep_copy ( inds , inds_host ) ; Kokkos :: deep_copy ( offsets , offsets_host ) ; return MC_Data_View ( H , P , W , inds , offsets ) ; }
Convert matrices to Kokkos View storage
Convert matrices to Kokkos View storage
// Allocate views // Mirror views on host // Copy data from CrsMatrix into Kokkos host mirrors // Get row views // Copy into host mirror // Release pointers to Tpetra matrices // Copy to device // Create data view object