Kokkos Core Kernels Package  Version of the Day
Kokkos_Parallel.hpp
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
46 
47 #ifndef KOKKOS_PARALLEL_HPP
48 #define KOKKOS_PARALLEL_HPP
49 
50 #include <cstddef>
51 #include <Kokkos_Core_fwd.hpp>
52 #include <Kokkos_View.hpp>
53 #include <Kokkos_ExecPolicy.hpp>
54 
55 #ifdef KOKKOSP_ENABLE_PROFILING
56 #include <impl/Kokkos_Profiling_Interface.hpp>
57 #include <typeinfo>
58 #endif
59 
60 #include <impl/Kokkos_AllocationTracker.hpp>
61 #include <impl/Kokkos_Tags.hpp>
62 #include <impl/Kokkos_Traits.hpp>
63 #include <impl/Kokkos_FunctorAdapter.hpp>
64 
65 #ifdef KOKKOS_HAVE_DEBUG
66 #include<iostream>
67 #endif
68 
69 //----------------------------------------------------------------------------
70 //----------------------------------------------------------------------------
71 
72 namespace Kokkos {
73 namespace Impl {
74 
75 //----------------------------------------------------------------------------
83 template< class Functor
84  , class Policy
85  , class EnableFunctor = void
86  , class EnablePolicy = void
87  >
89  typedef Kokkos::DefaultExecutionSpace execution_space ;
90 };
91 
92 template< class Functor , class Policy >
94  < Functor , Policy
95  , typename enable_if_type< typename Functor::device_type >::type
96  , typename enable_if_type< typename Policy ::execution_space >::type
97  >
98 {
99  typedef typename Policy ::execution_space execution_space ;
100 };
101 
102 template< class Functor , class Policy >
104  < Functor , Policy
105  , typename enable_if_type< typename Functor::execution_space >::type
106  , typename enable_if_type< typename Policy ::execution_space >::type
107  >
108 {
109  typedef typename Policy ::execution_space execution_space ;
110 };
111 
112 template< class Functor , class Policy , class EnableFunctor >
114  < Functor , Policy
115  , EnableFunctor
116  , typename enable_if_type< typename Policy::execution_space >::type
117  >
118 {
119  typedef typename Policy ::execution_space execution_space ;
120 };
121 
122 template< class Functor , class Policy , class EnablePolicy >
124  < Functor , Policy
125  , typename enable_if_type< typename Functor::device_type >::type
126  , EnablePolicy
127  >
128 {
129  typedef typename Functor::device_type execution_space ;
130 };
131 
132 template< class Functor , class Policy , class EnablePolicy >
134  < Functor , Policy
135  , typename enable_if_type< typename Functor::execution_space >::type
136  , EnablePolicy
137  >
138 {
139  typedef typename Functor::execution_space execution_space ;
140 };
141 
142 //----------------------------------------------------------------------------
149 template< class FunctorType , class ExecPolicy > class ParallelFor ;
150 
156 template< class FunctorType , class ExecPolicy > class ParallelReduce ;
157 
164 template< class FunctorType , class ExecPolicy > class ParallelScan ;
165 
166 } // namespace Impl
167 } // namespace Kokkos
168 
169 //----------------------------------------------------------------------------
170 //----------------------------------------------------------------------------
171 
172 namespace Kokkos {
173 
195 template< class ExecPolicy , class FunctorType >
196 inline
197 void parallel_for( const ExecPolicy & policy
198  , const FunctorType & functor
199  , const std::string& str = ""
200  , typename Impl::enable_if< ! Impl::is_integral< ExecPolicy >::value >::type * = 0
201  )
202 {
203 #ifdef KOKKOSP_ENABLE_PROFILING
204  uint64_t kpID = 0;
205  if(Kokkos::Experimental::profileLibraryLoaded()) {
206  Kokkos::Experimental::beginParallelFor("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
207  }
208 #endif
209 
210  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
211  Impl::ParallelFor< FunctorType , ExecPolicy > closure( functor , policy );
212  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
213 
214  closure.execute();
215 
216 #ifdef KOKKOSP_ENABLE_PROFILING
217  if(Kokkos::Experimental::profileLibraryLoaded()) {
218  Kokkos::Experimental::endParallelFor(kpID);
219  }
220 #endif
221 }
222 
223 template< class FunctorType >
224 inline
225 void parallel_for( const size_t work_count
226  , const FunctorType & functor
227  , const std::string& str = ""
228  )
229 {
230  typedef typename
231  Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space
232  execution_space ;
233  typedef RangePolicy< execution_space > policy ;
234 
235 #ifdef KOKKOSP_ENABLE_PROFILING
236  uint64_t kpID = 0;
237  if(Kokkos::Experimental::profileLibraryLoaded()) {
238  Kokkos::Experimental::beginParallelFor("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
239  }
240 #endif
241 
242  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
243  Impl::ParallelFor< FunctorType , policy > closure( functor , policy(0,work_count) );
244  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
245 
246  closure.execute();
247 
248 #ifdef KOKKOSP_ENABLE_PROFILING
249  if(Kokkos::Experimental::profileLibraryLoaded()) {
250  Kokkos::Experimental::endParallelFor(kpID);
251  }
252 #endif
253 }
254 
255 template< class ExecPolicy , class FunctorType >
256 inline
257 void parallel_for( const std::string & str
258  , const ExecPolicy & policy
259  , const FunctorType & functor )
260 {
261  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
262  Kokkos::fence();
263  std::cout << "KOKKOS_DEBUG Start parallel_for kernel: " << str << std::endl;
264  #endif
265 
266  parallel_for(policy,functor,str);
267 
268  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
269  Kokkos::fence();
270  std::cout << "KOKKOS_DEBUG End parallel_for kernel: " << str << std::endl;
271  #endif
272  (void) str;
273 }
274 
275 //----------------------------------------------------------------------------
276 //----------------------------------------------------------------------------
277 
312 template< class ExecPolicy , class FunctorType >
313 inline
314 void parallel_reduce( const ExecPolicy & policy
315  , const FunctorType & functor
316  , const std::string& str = ""
317  , typename Impl::enable_if< ! Impl::is_integral< ExecPolicy >::value >::type * = 0
318  )
319 {
320  // typedef typename
321  // Impl::FunctorPolicyExecutionSpace< FunctorType , ExecPolicy >::execution_space
322  // execution_space ;
323 
324  typedef Kokkos::Impl::FunctorValueTraits< FunctorType , typename ExecPolicy::work_tag > ValueTraits ;
325 
326  typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
327  , typename ValueTraits::value_type
328  , typename ValueTraits::pointer_type
329  >::type value_type ;
330 
331  Kokkos::View< value_type
332  , HostSpace
333  , Kokkos::MemoryUnmanaged
334  >
335  result_view ;
336 
337 #ifdef KOKKOSP_ENABLE_PROFILING
338  uint64_t kpID = 0;
339  if(Kokkos::Experimental::profileLibraryLoaded()) {
340  Kokkos::Experimental::beginParallelReduce("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
341  }
342 #endif
343 
344  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
345  Impl::ParallelReduce< FunctorType , ExecPolicy > closure( functor , policy , result_view );
346  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
347 
348  closure.execute();
349 
350 #ifdef KOKKOSP_ENABLE_PROFILING
351  if(Kokkos::Experimental::profileLibraryLoaded()) {
352  Kokkos::Experimental::endParallelReduce(kpID);
353  }
354 #endif
355 }
356 
357 // integral range policy
358 template< class FunctorType >
359 inline
360 void parallel_reduce( const size_t work_count
361  , const FunctorType & functor
362  , const std::string& str = ""
363  )
364 {
365  typedef typename
366  Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space
367  execution_space ;
368 
369  typedef RangePolicy< execution_space > policy ;
370 
371  typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
372 
373  typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
374  , typename ValueTraits::value_type
375  , typename ValueTraits::pointer_type
376  >::type value_type ;
377 
378  Kokkos::View< value_type
379  , HostSpace
380  , Kokkos::MemoryUnmanaged
381  >
382  result_view ;
383 
384 #ifdef KOKKOSP_ENABLE_PROFILING
385  uint64_t kpID = 0;
386  if(Kokkos::Experimental::profileLibraryLoaded()) {
387  Kokkos::Experimental::beginParallelReduce("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
388  }
389 #endif
390 
391  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
392  Impl::ParallelReduce< FunctorType , policy > closure( functor , policy(0,work_count) , result_view );
393  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
394 
395  closure.execute();
396 
397 #ifdef KOKKOSP_ENABLE_PROFILING
398  if(Kokkos::Experimental::profileLibraryLoaded()) {
399  Kokkos::Experimental::endParallelReduce(kpID);
400  }
401 #endif
402 
403 }
404 
405 // general policy and view ouput
406 template< class ExecPolicy , class FunctorType , class ViewType >
407 inline
408 void parallel_reduce( const ExecPolicy & policy
409  , const FunctorType & functor
410  , const ViewType & result_view
411  , const std::string& str = ""
412  , typename Impl::enable_if<
413  ( Kokkos::is_view<ViewType>::value && ! Impl::is_integral< ExecPolicy >::value
414 #ifdef KOKKOS_HAVE_CUDA
415  && ! Impl::is_same<typename ExecPolicy::execution_space,Kokkos::Cuda>::value
416 #endif
417  )>::type * = 0 )
418 {
419 
420 #ifdef KOKKOSP_ENABLE_PROFILING
421  uint64_t kpID = 0;
422  if(Kokkos::Experimental::profileLibraryLoaded()) {
423  Kokkos::Experimental::beginParallelReduce("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
424  }
425 #endif
426 
427  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
428  Impl::ParallelReduce< FunctorType, ExecPolicy > closure( functor , policy , result_view );
429  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
430 
431  closure.execute();
432 
433 #ifdef KOKKOSP_ENABLE_PROFILING
434  if(Kokkos::Experimental::profileLibraryLoaded()) {
435  Kokkos::Experimental::endParallelReduce(kpID);
436  }
437 #endif
438 
439 }
440 
441 // general policy and pod or array of pod output
442 template< class ExecPolicy , class FunctorType >
443 void parallel_reduce( const ExecPolicy & policy
444  , const FunctorType & functor
445 #ifdef KOKKOS_HAVE_CUDA
446  , typename Impl::enable_if<
447  ( ! Impl::is_integral< ExecPolicy >::value &&
448  ! Impl::is_same<typename ExecPolicy::execution_space,Kokkos::Cuda>::value )
449  , typename Kokkos::Impl::FunctorValueTraits< FunctorType , typename ExecPolicy::work_tag >::reference_type>::type result_ref
450  , const std::string& str = ""
451  , typename Impl::enable_if<! Impl::is_same<typename ExecPolicy::execution_space,Kokkos::Cuda>::value >::type* = 0
452  )
453 #else
454  , typename Impl::enable_if<
455  ( ! Impl::is_integral< ExecPolicy >::value)
456  , typename Kokkos::Impl::FunctorValueTraits< FunctorType , typename ExecPolicy::work_tag >::reference_type
457  >::type result_ref
458  , const std::string& str = ""
459  )
460 #endif
461 {
462  typedef Kokkos::Impl::FunctorValueTraits< FunctorType , typename ExecPolicy::work_tag > ValueTraits ;
463  typedef Kokkos::Impl::FunctorValueOps< FunctorType , typename ExecPolicy::work_tag > ValueOps ;
464 
465  // Wrap the result output request in a view to inform the implementation
466  // of the type and memory space.
467 
468  typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
469  , typename ValueTraits::value_type
470  , typename ValueTraits::pointer_type
471  >::type value_type ;
472 
473  Kokkos::View< value_type
474  , HostSpace
475  , Kokkos::MemoryUnmanaged
476  >
477  result_view( ValueOps::pointer( result_ref )
478  , ValueTraits::value_count( functor )
479  );
480 
481 #ifdef KOKKOSP_ENABLE_PROFILING
482  uint64_t kpID = 0;
483  if(Kokkos::Experimental::profileLibraryLoaded()) {
484  Kokkos::Experimental::beginParallelReduce("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
485  }
486 #endif
487 
488  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
489  Impl::ParallelReduce< FunctorType, ExecPolicy > closure( functor , policy , result_view );
490  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
491 
492  closure.execute();
493 
494 #ifdef KOKKOSP_ENABLE_PROFILING
495  if(Kokkos::Experimental::profileLibraryLoaded()) {
496  Kokkos::Experimental::endParallelReduce(kpID);
497  }
498 #endif
499 
500 }
501 
502 // integral range policy and view ouput
503 template< class FunctorType , class ViewType >
504 inline
505 void parallel_reduce( const size_t work_count
506  , const FunctorType & functor
507  , const ViewType & result_view
508  , const std::string& str = ""
509  , typename Impl::enable_if<( Kokkos::is_view<ViewType>::value
510 #ifdef KOKKOS_HAVE_CUDA
511  && ! Impl::is_same<
512  typename Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space,
513  Kokkos::Cuda>::value
514 #endif
515  )>::type * = 0 )
516 {
517  typedef typename
518  Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space
519  execution_space ;
520 
521  typedef RangePolicy< execution_space > ExecPolicy ;
522 
523 #ifdef KOKKOSP_ENABLE_PROFILING
524  uint64_t kpID = 0;
525  if(Kokkos::Experimental::profileLibraryLoaded()) {
526  Kokkos::Experimental::beginParallelReduce("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
527  }
528 #endif
529 
530  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
531  Impl::ParallelReduce< FunctorType, ExecPolicy > closure( functor , ExecPolicy(0,work_count) , result_view );
532  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
533 
534  closure.execute();
535 
536 #ifdef KOKKOSP_ENABLE_PROFILING
537  if(Kokkos::Experimental::profileLibraryLoaded()) {
538  Kokkos::Experimental::endParallelReduce(kpID);
539  }
540 #endif
541 
542 }
543 
544 // integral range policy and pod or array of pod output
545 template< class FunctorType >
546 inline
547 void parallel_reduce( const size_t work_count
548  , const FunctorType & functor
549  , typename Kokkos::Impl::FunctorValueTraits<
550  typename Impl::if_c<Impl::is_execution_policy<FunctorType>::value ||
551  Impl::is_integral<FunctorType>::value,
552  void,FunctorType>::type
553  , void >::reference_type result
554  , const std::string& str = ""
555  , typename Impl::enable_if< true
556 #ifdef KOKKOS_HAVE_CUDA
557  && ! Impl::is_same<
558  typename Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space,
559  Kokkos::Cuda>::value
560 #endif
561  >::type * = 0 )
562 {
563  typedef Kokkos::Impl::FunctorValueTraits< FunctorType , void > ValueTraits ;
564  typedef Kokkos::Impl::FunctorValueOps< FunctorType , void > ValueOps ;
565 
566  typedef typename
567  Kokkos::Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space
568  execution_space ;
569 
571 
572  // Wrap the result output request in a view to inform the implementation
573  // of the type and memory space.
574 
575  typedef typename Kokkos::Impl::if_c< (ValueTraits::StaticValueSize != 0)
576  , typename ValueTraits::value_type
577  , typename ValueTraits::pointer_type
578  >::type value_type ;
579 
580  Kokkos::View< value_type
581  , HostSpace
582  , Kokkos::MemoryUnmanaged
583  >
584  result_view( ValueOps::pointer( result )
585  , ValueTraits::value_count( functor )
586  );
587 
588 #ifdef KOKKOSP_ENABLE_PROFILING
589  uint64_t kpID = 0;
590  if(Kokkos::Experimental::profileLibraryLoaded()) {
591  Kokkos::Experimental::beginParallelReduce("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
592  }
593 #endif
594 
595  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
596  Impl::ParallelReduce< FunctorType , policy > closure( functor , policy(0,work_count) , result_view );
597  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
598 
599  closure.execute();
600 
601 #ifdef KOKKOSP_ENABLE_PROFILING
602  if(Kokkos::Experimental::profileLibraryLoaded()) {
603  Kokkos::Experimental::endParallelReduce(kpID);
604  }
605 #endif
606 
607 }
608 #ifndef KOKKOS_HAVE_CUDA
609 template< class ExecPolicy , class FunctorType , class ResultType >
610 inline
611 void parallel_reduce( const std::string & str
612  , const ExecPolicy & policy
613  , const FunctorType & functor
614  , ResultType * result)
615 {
616  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
617  Kokkos::fence();
618  std::cout << "KOKKOS_DEBUG Start parallel_reduce kernel: " << str << std::endl;
619  #endif
620 
621  parallel_reduce(policy,functor,result,str);
622 
623  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
624  Kokkos::fence();
625  std::cout << "KOKKOS_DEBUG End parallel_reduce kernel: " << str << std::endl;
626  #endif
627  (void) str;
628 }
629 
630 template< class ExecPolicy , class FunctorType , class ResultType >
631 inline
632 void parallel_reduce( const std::string & str
633  , const ExecPolicy & policy
634  , const FunctorType & functor
635  , ResultType & result)
636 {
637  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
638  Kokkos::fence();
639  std::cout << "KOKKOS_DEBUG Start parallel_reduce kernel: " << str << std::endl;
640  #endif
641 
642  parallel_reduce(policy,functor,result,str);
643 
644  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
645  Kokkos::fence();
646  std::cout << "KOKKOS_DEBUG End parallel_reduce kernel: " << str << std::endl;
647  #endif
648  (void) str;
649 }
650 
651 template< class ExecPolicy , class FunctorType >
652 inline
653 void parallel_reduce( const std::string & str
654  , const ExecPolicy & policy
655  , const FunctorType & functor)
656 {
657  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
658  Kokkos::fence();
659  std::cout << "KOKKOS_DEBUG Start parallel_reduce kernel: " << str << std::endl;
660  #endif
661 
662  parallel_reduce(policy,functor,str);
663 
664  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
665  Kokkos::fence();
666  std::cout << "KOKKOS_DEBUG End parallel_reduce kernel: " << str << std::endl;
667  #endif
668  (void) str;
669 }
670 #endif
671 
672 } // namespace Kokkos
673 
674 //----------------------------------------------------------------------------
675 //----------------------------------------------------------------------------
676 
677 namespace Kokkos {
678 
833 template< class ExecutionPolicy , class FunctorType >
834 inline
835 void parallel_scan( const ExecutionPolicy & policy
836  , const FunctorType & functor
837  , const std::string& str = ""
838  , typename Impl::enable_if< ! Impl::is_integral< ExecutionPolicy >::value >::type * = 0
839  )
840 {
841 #ifdef KOKKOSP_ENABLE_PROFILING
842  uint64_t kpID = 0;
843  if(Kokkos::Experimental::profileLibraryLoaded()) {
844  Kokkos::Experimental::beginParallelScan("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
845  }
846 #endif
847 
848  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
849  Impl::ParallelScan< FunctorType , ExecutionPolicy > closure( functor , policy );
850  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
851 
852  closure.execute();
853 
854 #ifdef KOKKOSP_ENABLE_PROFILING
855  if(Kokkos::Experimental::profileLibraryLoaded()) {
856  Kokkos::Experimental::endParallelScan(kpID);
857  }
858 #endif
859 
860 }
861 
862 template< class FunctorType >
863 inline
864 void parallel_scan( const size_t work_count
865  , const FunctorType & functor
866  , const std::string& str = "" )
867 {
868  typedef typename
869  Kokkos::Impl::FunctorPolicyExecutionSpace< FunctorType , void >::execution_space
870  execution_space ;
871 
873 
874 #ifdef KOKKOSP_ENABLE_PROFILING
875  uint64_t kpID = 0;
876  if(Kokkos::Experimental::profileLibraryLoaded()) {
877  Kokkos::Experimental::beginParallelScan("" == str ? typeid(FunctorType).name() : str, 0, &kpID);
878  }
879 #endif
880 
881  Kokkos::Impl::shared_allocation_tracking_claim_and_disable();
882  Impl::ParallelScan< FunctorType , policy > closure( functor , policy(0,work_count) );
883  Kokkos::Impl::shared_allocation_tracking_release_and_enable();
884 
885  closure.execute();
886 
887 #ifdef KOKKOSP_ENABLE_PROFILING
888  if(Kokkos::Experimental::profileLibraryLoaded()) {
889  Kokkos::Experimental::endParallelScan(kpID);
890  }
891 #endif
892 
893 }
894 
895 template< class ExecutionPolicy , class FunctorType >
896 inline
897 void parallel_scan( const std::string& str
898  , const ExecutionPolicy & policy
899  , const FunctorType & functor)
900 {
901  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
902  Kokkos::fence();
903  std::cout << "KOKKOS_DEBUG Start parallel_scan kernel: " << str << std::endl;
904  #endif
905 
906  parallel_scan(policy,functor,str);
907 
908  #if KOKKOS_ENABLE_DEBUG_PRINT_KERNEL_NAMES
909  Kokkos::fence();
910  std::cout << "KOKKOS_DEBUG End parallel_scan kernel: " << str << std::endl;
911  #endif
912  (void) str;
913 }
914 
915 } // namespace Kokkos
916 
917 //----------------------------------------------------------------------------
918 //----------------------------------------------------------------------------
919 
920 namespace Kokkos {
921 namespace Impl {
922 
923 template< class FunctorType , class Enable = void >
924 struct FunctorTeamShmemSize
925 {
926  static inline size_t value( const FunctorType & , int ) { return 0 ; }
927 };
928 
929 template< class FunctorType >
930 struct FunctorTeamShmemSize< FunctorType , typename Impl::enable_if< 0 < sizeof( & FunctorType::team_shmem_size ) >::type >
931 {
932  static inline size_t value( const FunctorType & f , int team_size ) { return f.team_shmem_size( team_size ) ; }
933 };
934 
935 template< class FunctorType >
936 struct FunctorTeamShmemSize< FunctorType , typename Impl::enable_if< 0 < sizeof( & FunctorType::shmem_size ) >::type >
937 {
938  static inline size_t value( const FunctorType & f , int team_size ) { return f.shmem_size( team_size ) ; }
939 };
940 
941 } // namespace Impl
942 } // namespace Kokkos
943 
944 //----------------------------------------------------------------------------
945 //----------------------------------------------------------------------------
946 
947 #endif /* KOKKOS_PARALLEL_HPP */
948 
Implementation detail of parallel_scan.
void parallel_reduce(const ExecPolicy &policy, const FunctorType &functor, const std::string &str="", typename Impl::enable_if< !Impl::is_integral< ExecPolicy >::value >::type *=0)
Parallel reduction.
View to an array of data.
Memory management for host memory.
Implementation of the ParallelFor operator that has a partial specialization for the device...
Given a Functor and Execution Policy query an execution space.
Execution policy for work over a range of an integral type.
void parallel_for(const ExecPolicy &policy, const FunctorType &functor, const std::string &str="", typename Impl::enable_if< !Impl::is_integral< ExecPolicy >::value >::type *=0)
Execute functor in parallel according to the execution policy.
Implementation detail of parallel_reduce.