-
Notifications
You must be signed in to change notification settings - Fork 89
Code patterns in Kokkos enabled Albany
Dan Ibanez edited this page Jan 23, 2017
·
1 revision
- Replace PHX::TypeString::value with PHX::typeAsString();
Example:
this->setName("Gather Solution"+PHX::TypeString<EvalT>::value);
should be replaced with
this->setName("Gather Solution"+PHX::typeAsString<EvalT>());
-
MDField no longer has operator[].
for (std::size_t i=0; i < Residual.size(); ++i) Residual[i]=0.0
should be replaced with
Residual.deep_copy(0.0);
or
for (int i=0; i<Residual.dimension(0); i++)
for (int j=0; j<Residual.dimension(1); j++)
Residual(i,j)=0.0;
or
for (PHAL::MDFieldIterator<ScalarT> gr(Residual); ! gr.done(); ++gr)
*gr = 0.0;
- We can't use pointers with Kokkos data types, so we need to replace pointer usage with direct access
Example 1:
MeshScalarT* X = &coordVec(cell,qp,0);
f[0] = 40.0*muqp*(2.0*X[1]*X[1] - 3.0*X[1]+1.0)*X[1]*(6.0*X[0]*X[0] -6.0*X[0] + 1.0)
+ 120*muqp*(X[0]-1.0)*(X[0]-1.0)*X[0]*X[0]*(2.0*X[1]-1.0)
could be replaced with
typename PHAL::Ref<MeshScalarT>::type X0 = coordVec(cell,qp,0);
typename PHAL::Ref<MeshScalarT>::type X1 = coordVec(cell,qp,1);
force(cell,qp,0) = 40.0*muqp*(2.0*X1*X1 - 3.0*X1+1.0)*X1*(6.0*X0*X0 -6.0*X0 + 1.0)
+ 120*muqp*(X0-1.0)*(X0-1.0)*X0*X0*(2.0*X1-1.0)
Example 2:
if (this->tensorRank == 2) valptr = this->valTensor[0](cell,node,eq/numDim,eq%numDim);
else if (this->tensorRank == 1) valptr = this->valVec[0](cell,node,eq);
else valptr = this->val[eq](cell,node);
could be replaced with
typename PHAL::Ref<ScalarT>::type valptr =
(this->tensorRank == 2) ? this->valTensor[0](cell,node,eq/numDim,eq%numDim) :
(this->tensorRank == 1) ? this->valVec[0](cell,node,eq) :
this->val[eq](cell,node);
In these examples, the syntax typename PHAL::Ref<ScalarT>::type evaluates to a type that is semantically like a reference. If ScalarT is a POD, then it is a reference; if it is a FadType, for example, then it is a Kokkos::View.
-
MiniTensor changes:
Tensor B(*A(i,j,0,0)); B.fill (*C(i,j,0,0));
should be replaced with:
Tensor B(*A,i,j,0,0); B.fill (*C,i,j,0,0);
-
Teuchos::reduceAll calls on MDFields should be changed. For example, this code:
Teuchos::RCP< Teuchos::ValueTypeSerializer<int,ScalarT> > serializer =
workset.serializerManager.template getValue<EvalT>();
Teuchos::reduceAll(
*workset.comm, *serializer, Teuchos::REDUCE_SUM,
this->global_response.size(), &this->global_response[0],
&this->global_response[0]);
becomes
PHAL::reduceAll<ScalarT>(*workset.comm, Teuchos::REDUCE_SUM,
this->global_response);