https://mooseframework.inl.gov
Loading...
Searching...
No Matches
KokkosVector.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://www.mooseframework.org
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "KokkosArray.h"
13
14#include "libmesh/petsc_vector.h"
15#include "libmesh/dof_map.h"
16
17namespace Moose::Kokkos
18{
19
20class System;
21
25class Vector
26{
27public:
31 Vector() = default;
39 void destroy();
40
41#ifdef MOOSE_KOKKOS_SCOPE
46 bool isAlloc() const { return _is_alloc; }
53 void create(libMesh::NumericVector<PetscScalar> & vector, const System & system, bool assemble);
61 void copyToHost();
65 void restore();
69 void close();
70
76 KOKKOS_FUNCTION PetscScalar & operator()(dof_id_type i) const
77 {
78 return i < _local.size() ? _local[i] : _ghost(i);
79 }
85 KOKKOS_FUNCTION PetscScalar & operator[](dof_id_type i) const
86 {
87 return i < _local.size() ? _local[i] : _ghost(i);
88 }
93 auto & operator=(PetscScalar scalar)
94 {
95 _local = scalar;
96 _ghost = scalar;
97
98 return *this;
99 }
100
106 {
107 };
109 {
110 };
111
112 KOKKOS_FUNCTION void operator()(PackBuffer, const PetscCount tid) const;
113 KOKKOS_FUNCTION void operator()(UnpackBuffer, const PetscCount tid) const;
115#endif
116
117private:
149
152
153 unsigned int _current_proc;
155
160 Vec _global_vector = PETSC_NULLPTR;
161 Vec _local_vector = PETSC_NULLPTR;
163
166 PetscScalar * _array = PETSC_NULLPTR;
182
185 bool _assemble = false;
189 bool _is_ghosted = false;
193 bool _is_host = false;
197 bool _is_alloc = false;
198};
199
200} // namespace Moose::Kokkos
KOKKOS_FUNCTION index_type size() const
Get the total array size.
The Kokkos array class.
The Kokkos base system class.
The Kokkos wrapper class for PETSc vector.
void destroy()
Free all data and reset.
void copyToDevice()
Copy from the host libMesh PetscVector.
KOKKOS_FUNCTION PetscScalar & operator()(dof_id_type i) const
Get an entry with a given index.
Array< PetscScalar > _local
Data vectors on device.
void copyToHost()
Copy to the host libMesh PetscVector.
bool _is_ghosted
Flag whether the PETSc vector is ghosted.
KOKKOS_FUNCTION void operator()(PackBuffer, const PetscCount tid) const
void close()
Assemble the underlying PETSc vector.
KOKKOS_FUNCTION PetscScalar & operator[](dof_id_type i) const
Get an entry with a given index.
unsigned int _current_proc
Vec _global_vector
PETSc vectors.
bool isAlloc() const
Get whether the vector was allocated.
KOKKOS_FUNCTION void operator()(UnpackBuffer, const PetscCount tid) const
PetscScalar * _array
Raw data of local PETSc vector.
bool _is_host
Flag whether the PETSc vector is a host vector.
bool _is_alloc
Flag whether the vector was allocated.
void create(libMesh::NumericVector< PetscScalar > &vector, const System &system, bool assemble)
Create the vector from a libMesh PetscVector.
auto & operator=(PetscScalar scalar)
Assign a scalar value uniformly.
Array< PetscScalar > _ghost
const libMesh::Parallel::Communicator * _comm
Pointer to the libMesh communicator.
void restore()
Restore the underlying PETSc vector.
bool _assemble
Flag whether the vector will be assembled.
DeviceAssembly _send
Vector()=default
Default constructor.
DeviceAssembly _recv
const System * _system
Pointer to the Kokkos system.
Data for direct assembly on device.
Array< PetscScalar > buffer
Communication buffer.
Array< int > count
Number of DOFs to send/receive for each process.
void create(const Array< Array< libMesh::dof_id_type > > &list)
Allocate data.
Array< int > offset
Starting offset of each process into the communication buffer.
Array< Array< libMesh::dof_id_type > > list
List of DOFs to send/receive for each process.
Kokkos functions for direct assembly on device.