Intrepid
Intrepid_ArrayToolsDefScalar_Kokkos.hpp
1 #ifndef INTREPID_ARRAYTOOLSDEFSCALAR_KOKKOS_HPP
2 #define INTREPID_ARRAYTOOLSDEFSCALAR_KOKKOS_HPP
3 
4 #ifdef INTREPID_OLD_KOKKOS_CODE
5 
7 
8 namespace Intrepid{
9 
10 
11 //Functors for parallel_for rank 2_2
12 //Below you can find the switch staments and paralle fors that call
13 //The functors.
14 template<class ViewType, class ViewType1,class ViewType2>
15 struct PFor__Recip_Not_Const2_2 {
16  ViewType outputData;
17  typename ViewType1::const_type inputDataLeft;
18  typename ViewType2::const_type inputDataRight;
19  PFor__Recip_Not_Const2_2(ViewType outputData_, ViewType1 inputDataLeft_,
20  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
21 
22  KOKKOS_INLINE_FUNCTION
23  void operator() (int i) const {
24  for(int j = 0; j < outputData.dimension_1(); j++){
25  outputData(i,j) = inputDataRight(i,j)/inputDataLeft(i,j);
26  }
27  }
28 };
29 template<class ViewType, class ViewType1,class ViewType2>
30 struct PFor_Not_Recip_Not_Const2_2 {
31  ViewType outputData;
32  typename ViewType1::const_type inputDataLeft;
33  typename ViewType2::const_type inputDataRight;
34  PFor_Not_Recip_Not_Const2_2(ViewType outputData_, ViewType1 inputDataLeft_,
35  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
36 
37  KOKKOS_INLINE_FUNCTION
38  void operator() (int i) const {
39  for(int j = 0; j < outputData.dimension_1(); j++){
40  outputData(i,j) = inputDataRight(i,j)*inputDataLeft(i,j);
41  }
42  }
43 };
44 template<class ViewType, class ViewType1,class ViewType2>
45 struct PFor__Recip__Const2_2 {
46  ViewType outputData;
47  typename ViewType1::const_type inputDataLeft;
48  typename ViewType2::const_type inputDataRight;
49  PFor__Recip__Const2_2(ViewType outputData_, ViewType1 inputDataLeft_,
50  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
51 
52  KOKKOS_INLINE_FUNCTION
53  void operator() (int i) const {
54  for(int j = 0; j < outputData.dimension_1(); j++){
55  outputData(i,j) = inputDataRight(i,j)/inputDataLeft(i,0);
56  }
57  }
58 };
59 template<class ViewType, class ViewType1,class ViewType2>
60 struct PFor_Not_Recip__Const2_2 {
61  ViewType outputData;
62  typename ViewType1::const_type inputDataLeft;
63  typename ViewType2::const_type inputDataRight;
64  PFor_Not_Recip__Const2_2(ViewType outputData_, ViewType1 inputDataLeft_,
65  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
66 
67  KOKKOS_INLINE_FUNCTION
68  void operator() (int i) const {
69  for(int j = 0; j < outputData.dimension_1(); j++){
70  outputData(i,j) = inputDataRight(i,j)*inputDataLeft(i,0);
71  }
72  }
73 };
74 //End Functors for parallel_for rank 2_2
75 
76 //Partially specialized implementation of scalarMultiplyDataData with rank 2_2
77 
78  template<class ArrayOutData, class ArrayInDataLeft, class ArrayInDataRight, class Layout, class MemorySpace>
79 struct ArrayTools::scalarMultiplyDataData2Kokkos<ArrayOutData, ArrayInDataLeft, ArrayInDataRight, Layout, MemorySpace,2,2>{
80  scalarMultiplyDataData2Kokkos(ArrayOutData & outputData,
81  ArrayInDataLeft & inputDataLeft,
82  ArrayInDataRight & inputDataRight,
83  const bool reciprocal){
84 
85 #ifdef HAVE_INTREPID_DEBUG
86  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataLeft.rank() != 2), std::invalid_argument,
87  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Left input data container must have rank 2.");
88  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() != 2)), std::invalid_argument,
89  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 2.");
90  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()), std::invalid_argument,
91  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input and output data containers must have the same rank.");
92  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(0) != inputDataLeft.dimension(0) ), std::invalid_argument,
93  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions (number of integration domains) of the left and right data input containers must agree!");
94  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(1) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
95  ">>> ERROR (ArrayTools::scalarMultiplyDataData): First dimensions of the left and right data input containers (number of integration points) must agree or first dimension of the left data input container must be 1!");
96  for (int i=0; i<inputDataRight.rank(); i++) {
97  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimension ";
98  errmsg += (char)(48+i);
99  errmsg += " of the right input and output data containers must agree!";
100  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i)), std::invalid_argument, errmsg );
101  }
102 
103 
104 #endif
105 
106  // get sizes
107 
108  int numCells = outputData.dimension(0);
109  int numDataPoints = inputDataLeft.dimension(1);
110 
111  if (numDataPoints != 1) {
112  if (reciprocal) {
113  Kokkos::parallel_for(numCells,PFor__Recip_Not_Const2_2<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
114  inputDataRight));
115 
116  }
117  else {
118  Kokkos::parallel_for(numCells,PFor_Not_Recip_Not_Const2_2<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
119  inputDataRight));
120  }
121  }
122  else{
123  if (reciprocal) {
124  Kokkos::parallel_for(numCells,PFor__Recip__Const2_2<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
125  inputDataRight));
126  }
127  else {
128  Kokkos::parallel_for(numCells,PFor_Not_Recip__Const2_2<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
129  inputDataRight));
130  }
131  }
132 
133  }
134  };
135 
136 //This is a test that uses nested paralleism
137 //Functors for parallel_for rank 3_3
138 #define VECTOR_LENGTH 32
139 typedef Kokkos::TeamVectorPolicy<8> team_policy;
140 typedef team_policy::member_type team_member ;
141 
142 
143 template<class ViewType, class ViewType1,class ViewType2>
144 struct PFor__Recip_Not_Const3_3 {
145  ViewType outputData;
146  typename ViewType1::const_type inputDataLeft;
147  typename ViewType2::const_type inputDataRight;
148  PFor__Recip_Not_Const3_3(ViewType outputData_, ViewType1 inputDataLeft_,
149  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
150 
151  KOKKOS_INLINE_FUNCTION
152  void operator() (const team_member & thread) const {
153  int i = thread.league_rank();
154  thread.team_par_for(outputData.dimension_1(),[&] (const int& j){
155  thread.vector_par_for(outputData.dimension_2(),[&] (const int& k){
156  outputData(i,j,k) = inputDataRight(i,j,k)/inputDataLeft(i,j);
157  });
158  });
159  /* for(int j = 0; j < outputData.dimension_1(); j++){
160  for(int k = 0; k < outputData.dimension_2(); k++){
161  outputData(i,j,k) = inputDataRight(i,j,k)/inputDataLeft(i,j);
162  }
163  }*/
164  }
165 };
166 
167 /*
168 template<class ViewType, class ViewType1,class ViewType2>
169 struct PFor__Recip_Not_Const3_3 {
170  ViewType outputData;
171  typename ViewType1::const_type inputDataLeft;
172  typename ViewType2::const_type inputDataRight;
173  PFor__Recip_Not_Const3_3(ViewType outputData_, ViewType1 inputDataLeft_,
174  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
175 
176  KOKKOS_INLINE_FUNCTION
177  void operator() (int i) const {
178 
179  for(int j = 0; j < outputData.dimension_1(); j++){
180  for(int k = 0; k < outputData.dimension_2(); k++){
181  outputData(i,j,k) = inputDataRight(i,j,k)/inputDataLeft(i,j);
182  }
183  }
184  }
185 };
186 */
187 
188 template<class ViewType, class ViewType1,class ViewType2>
189 struct PFor_Not_Recip_Not_Const3_3 {
190  ViewType outputData;
191  typename ViewType1::const_type inputDataLeft;
192  typename ViewType2::const_type inputDataRight;
193  PFor_Not_Recip_Not_Const3_3(ViewType outputData_, ViewType1 inputDataLeft_,
194  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
195 
196  KOKKOS_INLINE_FUNCTION
197  void operator() (int i) const {
198  for(int j = 0; j < outputData.dimension_1(); j++){
199  for(int k = 0; k < outputData.dimension_2(); k++){
200  outputData(i,j,k) = inputDataRight(i,j,k)*inputDataLeft(i,j);
201  }
202  }
203  }
204 };
205 template<class ViewType, class ViewType1,class ViewType2>
206 struct PFor__Recip__Const3_3 {
207  ViewType outputData;
208  typename ViewType1::const_type inputDataLeft;
209  typename ViewType2::const_type inputDataRight;
210  PFor__Recip__Const3_3(ViewType outputData_, ViewType1 inputDataLeft_,
211  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
212 
213  KOKKOS_INLINE_FUNCTION
214  void operator() (int i) const {
215  for(int j = 0; j < outputData.dimension_1(); j++){
216  for(int k = 0; k < outputData.dimension_2(); k++){
217  outputData(i,j,k) = inputDataRight(i,j,k)/inputDataLeft(i,0);
218  }
219  }
220  }
221 };
222 
223 template<class ViewType, class ViewType1,class ViewType2>
224 struct PFor_Not_Recip__Const3_3 {
225  ViewType outputData;
226  typename ViewType1::const_type inputDataLeft;
227  typename ViewType2::const_type inputDataRight;
228  PFor_Not_Recip__Const3_3(ViewType outputData_, ViewType1 inputDataLeft_,
229  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
230 
231  KOKKOS_INLINE_FUNCTION
232  void operator() (int i) const {
233  for(int j = 0; j < outputData.dimension_1(); j++){
234  for(int k = 0; k < outputData.dimension_2(); k++){
235  outputData(i,j,k) = inputDataRight(i,j,k)*inputDataLeft(i,0);
236  }
237  }
238  }
239 };
240 //End Functors for parallel_for rank 3_3
241 
242 //Partially specialized implementation of scalarMultiplyDataData with rank 3_3
243 
244 template<class ArrayOutData, class ArrayInDataLeft, class ArrayInDataRight, class Layout, class MemorySpace>
245  struct ArrayTools::scalarMultiplyDataData2Kokkos<ArrayOutData, ArrayInDataLeft, ArrayInDataRight, Layout, MemorySpace,3,3>{
246  scalarMultiplyDataData2Kokkos(ArrayOutData & outputData,
247  ArrayInDataLeft & inputDataLeft,
248  ArrayInDataRight & inputDataRight,
249  const bool reciprocal){
250  #ifdef HAVE_INTREPID_DEBUG
251  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataLeft.rank() != 2), std::invalid_argument,
252  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Left input data container must have rank 2.");
253  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() != 3)), std::invalid_argument,
254  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 3.");
255  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()), std::invalid_argument,
256  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input and output data containers must have the same rank of 3.");
257  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(0) != inputDataLeft.dimension(0) ), std::invalid_argument,
258  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions (number of integration domains) of the left and right data input containers must agree!");
259  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(1) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
260  ">>> ERROR (ArrayTools::scalarMultiplyDataData): First dimensions of the left and right data input containers (number of integration points) must agree or first dimension of the left data input container must be 1!");
261  for (int i=0; i<inputDataRight.rank(); i++) {
262  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimension ";
263  errmsg += (char)(48+i);
264  errmsg += " of the right input and output data containers must agree!";
265  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i)), std::invalid_argument, errmsg );
266  }
267 
268 
269 #endif
270 
271  // get sizes
272 
273  int numCells = outputData.dimension(0);
274  int numDataPoints = inputDataLeft.dimension(1);
275 
276  if (numDataPoints != 1) {
277 
278  if (reciprocal) {
279  const team_policy policy( numCells , 2 );
280  Kokkos::parallel_for(policy,PFor__Recip_Not_Const3_3<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft, inputDataRight));
281  }
282  else {
283 
284  Kokkos::parallel_for(numCells,PFor_Not_Recip_Not_Const3_3<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
285  inputDataRight));
286  }
287  }
288  else{
289 
290  if (reciprocal) {
291 
292  Kokkos::parallel_for(numCells,PFor__Recip__Const3_3<ArrayOutData,ArrayInDataLeft,ArrayInDataRight >(outputData, inputDataLeft,
293  inputDataRight));
294  }
295  else {
296 
297  Kokkos::parallel_for(numCells,PFor_Not_Recip__Const3_3<ArrayOutData,ArrayInDataLeft,ArrayInDataRight >(outputData, inputDataLeft,
298  inputDataRight));
299  }
300  }
301  }
302  };
303 
304 
305 //Functors for parallel_for rank 4_4
306 template<class ViewType, class ViewType1,class ViewType2>
307 struct PFor__Recip_Not_Const4_4 {
308  ViewType outputData;
309  typename ViewType1::const_type inputDataLeft;
310  typename ViewType2::const_type inputDataRight;
311  PFor__Recip_Not_Const4_4(ViewType outputData_, ViewType1 inputDataLeft_,
312  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
313 
314  KOKKOS_INLINE_FUNCTION
315  void operator() (int i) const {
316  for(int j = 0; j < outputData.dimension_1(); j++){
317  for(int k = 0; k < outputData.dimension_2(); k++){
318  for(int l = 0; l < outputData.dimension_3(); l++){
319  outputData(i,j,k,l) = inputDataRight(i,j,k,l)/inputDataLeft(i,j);
320  }
321  }
322  }
323  }
324 };
325 template<class ViewType, class ViewType1,class ViewType2>
326 struct PFor_Not_Recip_Not_Const4_4 {
327  ViewType outputData;
328  typename ViewType1::const_type inputDataLeft;
329  typename ViewType2::const_type inputDataRight;
330  PFor_Not_Recip_Not_Const4_4(ViewType outputData_, ViewType1 inputDataLeft_,
331  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
332 
333  KOKKOS_INLINE_FUNCTION
334  void operator() (int i) const {
335  for(int j = 0; j < outputData.dimension_1(); j++){
336  for(int k = 0; k < outputData.dimension_2(); k++){
337  for(int l = 0; l < outputData.dimension_3(); l++){
338  outputData(i,j,k,l) = inputDataRight(i,j,k,l)*inputDataLeft(i,j);
339  }
340  }
341  }
342  }
343 };
344 template<class ViewType, class ViewType1,class ViewType2>
345 struct PFor__Recip__Const4_4 {
346  ViewType outputData;
347  typename ViewType1::const_type inputDataLeft;
348  typename ViewType2::const_type inputDataRight;
349  PFor__Recip__Const4_4(ViewType outputData_, ViewType1 inputDataLeft_,
350  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
351 
352  KOKKOS_INLINE_FUNCTION
353  void operator() (int i) const {
354  for(int j = 0; j < outputData.dimension_1(); j++){
355  for(int k = 0; k < outputData.dimension_2(); k++){
356  for(int l = 0; l < outputData.dimension_3(); l++){
357  outputData(i,j,k,l) = inputDataRight(i,j,k,l)/inputDataLeft(i,0);
358  }
359  }
360  }
361  }
362 };
363 template<class ViewType, class ViewType1,class ViewType2>
364 struct PFor_Not_Recip__Const4_4 {
365  ViewType outputData;
366  typename ViewType1::const_type inputDataLeft;
367  typename ViewType2::const_type inputDataRight;
368  PFor_Not_Recip__Const4_4(ViewType outputData_, ViewType1 inputDataLeft_,
369  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
370 
371  KOKKOS_INLINE_FUNCTION
372  void operator() (int i) const {
373  for(int j = 0; j < outputData.dimension_1(); j++){
374  for(int k = 0; k < outputData.dimension_2(); k++){
375  for(int l = 0; l < outputData.dimension_3(); l++){
376  outputData(i,j,k,l) = inputDataRight(i,j,k,l)/inputDataLeft(i,0);
377  }
378  }
379  }
380  }
381 };
382 //End Functors for parallel_for rank 4_4
383 
384 
385 //Partially specialized implementation of scalarMultiplyDataData with rank 4_4
386 
387 template<class ArrayOutData, class ArrayInDataLeft, class ArrayInDataRight, class Layout, class MemorySpace>
388  struct ArrayTools::scalarMultiplyDataData2Kokkos<ArrayOutData, ArrayInDataLeft, ArrayInDataRight, Layout, MemorySpace,4,4>{
389  scalarMultiplyDataData2Kokkos(ArrayOutData& outputData,
390  ArrayInDataLeft& inputDataLeft,
391  ArrayInDataRight& inputDataRight,
392  const bool reciprocal){
393  #ifdef HAVE_INTREPID_DEBUG
394  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataLeft.rank() != 2), std::invalid_argument,
395  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Left input data container must have rank 2.");
396  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() != 4)), std::invalid_argument,
397  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 4.");
398  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()), std::invalid_argument,
399  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input and output data containers must have the same rank of 4.");
400  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(0) != inputDataLeft.dimension(0) ), std::invalid_argument,
401  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions (number of integration domains) of the left and right data input containers must agree!");
402  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(1) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
403  ">>> ERROR (ArrayTools::scalarMultiplyDataData): First dimensions of the left and right data input containers (number of integration points) must agree or first dimension of the left data input container must be 1!");
404  for (int i=0; i<inputDataRight.rank(); i++) {
405  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimension ";
406  errmsg += (char)(48+i);
407  errmsg += " of the right input and output data containers must agree!";
408  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i)), std::invalid_argument, errmsg );
409  }
410 
411 
412 #endif
413  // get sizes
414 
415  int numCells = outputData.dimension(0);
416  int numDataPoints = inputDataLeft.dimension(1);
417 
418  if (numDataPoints != 1) {
419  if (reciprocal) {
420  Kokkos::parallel_for(numCells,PFor__Recip_Not_Const4_4<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
421  inputDataRight));
422  }
423  else {
424  Kokkos::parallel_for(numCells,PFor_Not_Recip_Not_Const4_4<ArrayOutData,ArrayInDataLeft,ArrayInDataRight >(outputData, inputDataLeft,
425  inputDataRight));
426  }
427  }
428  else{
429 
430  if (reciprocal) {
431 
432  Kokkos::parallel_for(numCells,PFor__Recip__Const4_4<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
433  inputDataRight));
434  }
435  else {
436  Kokkos::parallel_for(numCells,PFor_Not_Recip__Const4_4<ArrayOutData,ArrayInDataLeft,ArrayInDataRight >(outputData, inputDataLeft,
437  inputDataRight));
438  }
439  }
440  }
441 
442 };
443 
444 
445 //Functors for parallel_for rank 1_2
446 template<class ViewType, class ViewType1,class ViewType2>
447 struct PFor__Recip_Not_Const1_2 {
448  ViewType outputData;
449  typename ViewType1::const_type inputDataLeft;
450  typename ViewType2::const_type inputDataRight;
451  PFor__Recip_Not_Const1_2(ViewType outputData_, ViewType1 inputDataLeft_,
452  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
453 
454  KOKKOS_INLINE_FUNCTION
455  void operator() (int i) const {
456  for(int j = 0; j < outputData.dimension_1(); j++){
457  outputData(i,j) = inputDataRight(j)/inputDataLeft(i,j);
458  }
459  }
460 };
461 template<class ViewType, class ViewType1,class ViewType2>
462 struct PFor_Not_Recip_Not_Const1_2 {
463  ViewType outputData;
464  typename ViewType1::const_type inputDataLeft;
465  typename ViewType2::const_type inputDataRight;
466  PFor_Not_Recip_Not_Const1_2(ViewType outputData_, ViewType1 inputDataLeft_,
467  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
468 
469  KOKKOS_INLINE_FUNCTION
470  void operator() (int i) const {
471  for(int j = 0; j < outputData.dimension_1(); j++){
472  outputData(i,j) = inputDataRight(j)*inputDataLeft(i,j);
473  }
474  }
475 };
476 template<class ViewType, class ViewType1,class ViewType2>
477 struct PFor__Recip__Const1_2 {
478  ViewType outputData;
479  typename ViewType1::const_type inputDataLeft;
480  typename ViewType2::const_type inputDataRight;
481  PFor__Recip__Const1_2(ViewType outputData_, ViewType1 inputDataLeft_,
482  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
483 
484  KOKKOS_INLINE_FUNCTION
485  void operator() (int i) const {
486  for(int j = 0; j < outputData.dimension_1(); j++){
487  outputData(i,j) = inputDataRight(j)/inputDataLeft(i,0);
488  }
489  }
490 };
491 template<class ViewType, class ViewType1,class ViewType2>
492 struct PFor_Not_Recip__Const1_2 {
493  ViewType outputData;
494  typename ViewType1::const_type inputDataLeft;
495  typename ViewType2::const_type inputDataRight;
496  PFor_Not_Recip__Const1_2(ViewType outputData_, ViewType1 inputDataLeft_,
497  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
498 
499  KOKKOS_INLINE_FUNCTION
500  void operator() (int i) const {
501  for(int j = 0; j < outputData.dimension_1(); j++){
502  outputData(i,j) = inputDataRight(j)*inputDataLeft(i,0);
503  }
504  }
505 };
506 //End Functors for parallel_for rank 1_2
507 
508 //Partially specialized implementation of scalarMultiplyDataData with rank 1_2
509 
510  template<class ArrayOutData, class ArrayInDataLeft, class ArrayInDataRight, class Layout, class MemorySpace>
511  struct ArrayTools::scalarMultiplyDataData2Kokkos<ArrayOutData, ArrayInDataLeft, ArrayInDataRight, Layout, MemorySpace,1,2>{
512  scalarMultiplyDataData2Kokkos(ArrayOutData& outputData,
513  ArrayInDataLeft& inputDataLeft,
514  ArrayInDataRight& inputDataRight,
515  const bool reciprocal){
516  #ifdef HAVE_INTREPID_DEBUG
517  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataLeft.rank() != 2), std::invalid_argument,
518  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Left input data container must have rank 2.");
519  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() != 1) ), std::invalid_argument,
520  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 1.");
521  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()+1), std::invalid_argument,
522  ">>> ERROR (ArrayTools::scalarMultiplyDataData): The rank of the right input data container must be one less than the rank of the output data container.");
523  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(0) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
524  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimension of the right input data container and first dimension of the left data input container (number of integration points) must agree or first dimension of the left data input container must be 1!");
525  TEUCHOS_TEST_FOR_EXCEPTION( ( inputDataLeft.dimension(0) != outputData.dimension(0) ), std::invalid_argument,
526  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions of data output and left data input containers (number of integration domains) must agree!");
527  for (int i=0; i<inputDataRight.rank(); i++) {
528  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimensions ";
529  errmsg += (char)(48+i);
530  errmsg += " and ";
531  errmsg += (char)(48+i+1);
532  errmsg += " of the right input and output data containers must agree!";
533  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i+1)), std::invalid_argument, errmsg );
534  }
535  #endif
536 
537  // get sizes
538  int numCells = outputData.dimension(0);
539  int numDataPoints = inputDataLeft.dimension(1);
540 
541  if (numDataPoints != 1) {
542  if (reciprocal) {
543  Kokkos::parallel_for(numCells,PFor__Recip_Not_Const1_2<ArrayOutData,ArrayInDataLeft,ArrayInDataRight >(outputData, inputDataLeft,
544  inputDataRight));
545  }
546  else {
547  Kokkos::parallel_for(numCells,PFor_Not_Recip_Not_Const1_2<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
548  inputDataRight));
549  }
550  }
551  else{
552  if (reciprocal) {
553  Kokkos::parallel_for(numCells,PFor__Recip__Const1_2<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
554  inputDataRight));
555  }
556  else {
557  Kokkos::parallel_for(numCells,PFor_Not_Recip__Const1_2<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
558  inputDataRight));
559  }
560  }
561  }
562  };
563 
564 //Functors for parallel_for rank 2_3
565 template<class ViewType, class ViewType1,class ViewType2>
566 struct PFor__Recip_Not_Const2_3 {
567  ViewType outputData;
568  typename ViewType1::const_type inputDataLeft;
569  typename ViewType2::const_type inputDataRight;
570  PFor__Recip_Not_Const2_3(ViewType outputData_, ViewType1 inputDataLeft_,
571  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
572 
573  KOKKOS_INLINE_FUNCTION
574  void operator() (int i) const {
575 
576  for(int j = 0; j < outputData.dimension_1(); j++){
577  for(int k = 0; k < outputData.dimension_2(); k++){
578  outputData(i,j,k) = inputDataRight(j,k)/inputDataLeft(i,j);
579  }
580  }
581  }
582 };
583 template<class ViewType, class ViewType1,class ViewType2>
584 struct PFor_Not_Recip_Not_Const2_3 {
585  ViewType outputData;
586  typename ViewType1::const_type inputDataLeft;
587  typename ViewType2::const_type inputDataRight;
588  PFor_Not_Recip_Not_Const2_3(ViewType outputData_, ViewType1 inputDataLeft_,
589  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
590 
591  KOKKOS_INLINE_FUNCTION
592  void operator() (int i) const {
593  for(int j = 0; j < outputData.dimension_1(); j++){
594  for(int k = 0; k < outputData.dimension_2(); k++){
595  outputData(i,j,k) = inputDataRight(j,k)*inputDataLeft(i,j);
596  }
597  }
598  }
599 };
600 template<class ViewType, class ViewType1,class ViewType2>
601 struct PFor__Recip__Const2_3 {
602  ViewType outputData;
603  typename ViewType1::const_type inputDataLeft;
604  typename ViewType2::const_type inputDataRight;
605  PFor__Recip__Const2_3(ViewType outputData_, ViewType1 inputDataLeft_,
606  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
607 
608  KOKKOS_INLINE_FUNCTION
609  void operator() (int i) const {
610  for(int j = 0; j < outputData.dimension_1(); j++){
611  for(int k = 0; k < outputData.dimension_2(); k++){
612  outputData(i,j,k) = inputDataRight(j,k)/inputDataLeft(i,0);
613  }
614  }
615  }
616 };
617 template<class ViewType, class ViewType1,class ViewType2>
618 struct PFor_Not_Recip__Const2_3 {
619  ViewType outputData;
620  typename ViewType1::const_type inputDataLeft;
621  typename ViewType2::const_type inputDataRight;
622  PFor_Not_Recip__Const2_3(ViewType outputData_, ViewType1 inputDataLeft_,
623  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
624 
625  KOKKOS_INLINE_FUNCTION
626  void operator() (int i) const {
627  for(int j = 0; j < outputData.dimension_1(); j++){
628  for(int k = 0; k < outputData.dimension_2(); k++){
629  outputData(i,j,k) = inputDataRight(j,k)*inputDataLeft(i,0);
630  }
631  }
632  }
633 };
634 //End Functors for parallel_for rank 2_3
635 
636 //Partially specialized implementation of scalarMultiplyDataData with rank 2_3
637 
638  template<class ArrayOutData, class ArrayInDataLeft, class ArrayInDataRight, class Layout, class MemorySpace>
639 struct ArrayTools::scalarMultiplyDataData2Kokkos<ArrayOutData, ArrayInDataLeft, ArrayInDataRight, Layout, MemorySpace,2,3>{
640  scalarMultiplyDataData2Kokkos(ArrayOutData& outputData,
641  ArrayInDataLeft& inputDataLeft,
642  ArrayInDataRight& inputDataRight,
643  const bool reciprocal){
644 
645 #ifdef HAVE_INTREPID_DEBUG
646  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataLeft.rank() != 2), std::invalid_argument,
647  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Left input data container must have rank 2.");
648  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() != 2) ), std::invalid_argument,
649  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 2.");
650  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()+1), std::invalid_argument,
651  ">>> ERROR (ArrayTools::scalarMultiplyDataData): The rank of the right input data container must be one less than the rank of the output data container.");
652  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(0) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
653  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimension of the right input data container and first dimension of the left data input container (number of integration points) must agree or first dimension of the left data input container must be 1!");
654  TEUCHOS_TEST_FOR_EXCEPTION( ( inputDataLeft.dimension(0) != outputData.dimension(0) ), std::invalid_argument,
655  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions of data output and left data input containers (number of integration domains) must agree!");
656  for (int i=0; i<inputDataRight.rank(); i++) {
657  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimensions ";
658  errmsg += (char)(48+i);
659  errmsg += " and ";
660  errmsg += (char)(48+i+1);
661  errmsg += " of the right input and output data containers must agree!";
662  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i+1)), std::invalid_argument, errmsg );
663  }
664 #endif
665  // get sizes
666  int numCells = outputData.dimension(0);
667  int numDataPoints = inputDataLeft.dimension(1);
668  if (numDataPoints != 1) {
669  if (reciprocal) {
670  Kokkos::parallel_for(numCells,PFor__Recip_Not_Const2_3<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
671  inputDataRight));
672  }
673  else {
674  Kokkos::parallel_for(numCells,PFor_Not_Recip_Not_Const2_3<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
675  inputDataRight));
676  }
677  }
678  else{
679  if (reciprocal) {
680  Kokkos::parallel_for(numCells,PFor__Recip__Const2_3<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
681  inputDataRight));
682  }
683  else {
684  Kokkos::parallel_for(numCells,PFor_Not_Recip__Const2_3<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
685  inputDataRight));
686  }
687  }
688 
689  }
690  };
691 
692 //Functors for parallel_for rank 3_4
693 template<class ViewType, class ViewType1,class ViewType2>
694 struct PFor__Recip_Not_Const3_4 {
695  ViewType outputData;
696  typename ViewType1::const_type inputDataLeft;
697  typename ViewType2::const_type inputDataRight;
698  PFor__Recip_Not_Const3_4(ViewType outputData_, ViewType1 inputDataLeft_,
699  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
700 
701  KOKKOS_INLINE_FUNCTION
702  void operator() (int i) const {
703  for(int j = 0; j < outputData.dimension_1(); j++){
704  for(int k = 0; k < outputData.dimension_2(); k++){
705  for(int l = 0; l < outputData.dimension_3(); l++){
706  outputData(i,j,k,l) = inputDataRight(j,k,l)/inputDataLeft(i,j);
707  }
708  }
709  }
710  }
711 };
712 template<class ViewType, class ViewType1,class ViewType2>
713 struct PFor_Not_Recip_Not_Const3_4 {
714  ViewType outputData;
715  typename ViewType1::const_type inputDataLeft;
716  typename ViewType2::const_type inputDataRight;
717  PFor_Not_Recip_Not_Const3_4(ViewType outputData_, ViewType1 inputDataLeft_,
718  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
719 
720  KOKKOS_INLINE_FUNCTION
721  void operator() (int i) const {
722  for(int j = 0; j < outputData.dimension_1(); j++){
723  for(int k = 0; k < outputData.dimension_2(); k++){
724  for(int l = 0; l < outputData.dimension_3(); l++){
725  outputData(i,j,k,l) = inputDataRight(j,k,l)*inputDataLeft(i,j);
726  }
727  }
728  }
729  }
730 };
731 template<class ViewType, class ViewType1,class ViewType2>
732 struct PFor__Recip__Const3_4 {
733  ViewType outputData;
734  typename ViewType1::const_type inputDataLeft;
735  typename ViewType2::const_type inputDataRight;
736  PFor__Recip__Const3_4(ViewType outputData_, ViewType1 inputDataLeft_,
737  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
738 
739  KOKKOS_INLINE_FUNCTION
740  void operator() (int i) const {
741  for(int j = 0; j < outputData.dimension_1(); j++){
742  for(int k = 0; k < outputData.dimension_2(); k++){
743  for(int l = 0; l < outputData.dimension_3(); l++){
744  outputData(i,j,k,l) = inputDataRight(j,k,l)/inputDataLeft(i,0);
745  }
746  }
747  }
748  }
749 };
750 template<class ViewType, class ViewType1,class ViewType2>
751 struct PFor_Not_Recip__Const3_4 {
752  ViewType outputData;
753  typename ViewType1::const_type inputDataLeft;
754  typename ViewType2::const_type inputDataRight;
755  PFor_Not_Recip__Const3_4(ViewType outputData_, ViewType1 inputDataLeft_,
756  ViewType2 inputDataRight_):outputData(outputData_),inputDataLeft(inputDataLeft_),inputDataRight(inputDataRight_) {}
757 
758  KOKKOS_INLINE_FUNCTION
759  void operator() (int i) const {
760  for(int j = 0; j < outputData.dimension_1(); j++){
761  for(int k = 0; k < outputData.dimension_2(); k++){
762  for(int l = 0; l < outputData.dimension_3(); l++){
763  outputData(i,j,k,l) = inputDataRight(j,k,l)/inputDataLeft(i,0);
764  }
765  }
766  }
767  }
768 };
769 //End Functors for parallel_for rank 3_4
770 
771 //Partially specialized implementation of scalarMultiplyDataData with rank 3_4
772 
773  template<class ArrayOutData, class ArrayInDataLeft, class ArrayInDataRight, class Layout, class MemorySpace>
774 struct ArrayTools::scalarMultiplyDataData2Kokkos<ArrayOutData, ArrayInDataLeft, ArrayInDataRight, Layout, MemorySpace,3,4>{
775  scalarMultiplyDataData2Kokkos(ArrayOutData& outputData,
776  ArrayInDataLeft& inputDataLeft,
777  ArrayInDataRight& inputDataRight,
778  const bool reciprocal){
779 #ifdef HAVE_INTREPID_DEBUG
780  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataLeft.rank() != 2), std::invalid_argument,
781  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Left input data container must have rank 2.");
782  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.rank() != 3) ), std::invalid_argument,
783  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Right input data container must have rank 3.");
784  TEUCHOS_TEST_FOR_EXCEPTION( (outputData.rank() != inputDataRight.rank()+1), std::invalid_argument,
785  ">>> ERROR (ArrayTools::scalarMultiplyDataData): The rank of the right input data container must be one less than the rank of the output data container.");
786  TEUCHOS_TEST_FOR_EXCEPTION( ( (inputDataRight.dimension(0) != inputDataLeft.dimension(1)) && (inputDataLeft.dimension(1) != 1) ), std::invalid_argument,
787  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimension of the right input data container and first dimension of the left data input container (number of integration points) must agree or first dimension of the left data input container must be 1!");
788  TEUCHOS_TEST_FOR_EXCEPTION( ( inputDataLeft.dimension(0) != outputData.dimension(0) ), std::invalid_argument,
789  ">>> ERROR (ArrayTools::scalarMultiplyDataData): Zeroth dimensions of data output and left data input containers (number of integration domains) must agree!");
790  for (int i=0; i<inputDataRight.rank(); i++) {
791  std::string errmsg = ">>> ERROR (ArrayTools::scalarMultiplyDataData): Dimensions ";
792  errmsg += (char)(48+i);
793  errmsg += " and ";
794  errmsg += (char)(48+i+1);
795  errmsg += " of the right input and output data containers must agree!";
796  TEUCHOS_TEST_FOR_EXCEPTION( (inputDataRight.dimension(i) != outputData.dimension(i+1)), std::invalid_argument, errmsg );
797  }
798 #endif
799 
800 
801  int numCells = outputData.dimension(0);
802  int numDataPoints = inputDataLeft.dimension(1);
803 
804 
805 
806  if (numDataPoints != 1) {
807  if (reciprocal) {
808  Kokkos::parallel_for(numCells,PFor__Recip_Not_Const3_4<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
809  inputDataRight));
810  }
811  else {
812  Kokkos::parallel_for(numCells,PFor_Not_Recip_Not_Const3_4<ArrayOutData,ArrayInDataLeft,ArrayInDataRight >(outputData, inputDataLeft,
813  inputDataRight));
814  }
815  }
816  else{
817  if (reciprocal) {
818  Kokkos::parallel_for(numCells,PFor__Recip__Const3_4<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
819  inputDataRight));
820  }
821  else {
822  Kokkos::parallel_for(numCells,PFor_Not_Recip__Const3_4<ArrayOutData,ArrayInDataLeft,ArrayInDataRight>(outputData, inputDataLeft,
823  inputDataRight));
824  }
825  }
826  }
827  };
828 
829  }//end namespace
830 #endif
831 #endif
Definition file for scalar multiply operations of the array tools interface.