KOKKOS_INLINE_FUNCTION void operator()( typename sched_type::member_type & ) { if ( ! m_future.is_null() ) { Kokkos::task_spawn( Kokkos::TaskSingle( m_sched ) , TestTaskSpawn( m_sched , future_type() ) ); } }
KOKKOS_INLINE_FUNCTION void operator()( typename policy_type::member_type & , value_type & result ) { #if 0 printf( "\nTestFib(%ld) %d %d\n" , n , int( ! fib_m1.is_null() ) , int( ! fib_m2.is_null() ) ); #endif if ( n < 2 ) { result = n ; } else if ( ! fib_m2.is_null() && ! fib_m1.is_null() ) { result = fib_m1.get() + fib_m2.get(); } else { // Spawn new children and respawn myself to sum their results: // Spawn lower value at higher priority as it has a shorter // path to completion. fib_m2 = policy.task_spawn( TestFib(policy,n-2) , Kokkos::TaskSingle , Kokkos::TaskHighPriority ); fib_m1 = policy.task_spawn( TestFib(policy,n-1) , Kokkos::TaskSingle ); Kokkos::Future<Space> dep[] = { fib_m1 , fib_m2 }; Kokkos::Future<Space> fib_all = policy.when_all( 2 , dep ); if ( ! fib_m2.is_null() && ! fib_m1.is_null() && ! fib_all.is_null() ) { // High priority to retire this branch policy.respawn( this , Kokkos::TaskHighPriority , fib_all ); } else { #if 0 printf( "TestFib(%ld) insufficient memory alloc_capacity(%d) task_max(%d) task_accum(%ld)\n" , n , policy.allocation_capacity() , policy.allocated_task_count_max() , policy.allocated_task_count_accum() ); #endif Kokkos::abort("TestFib insufficient memory"); } } }
KOKKOS_INLINE_FUNCTION void operator()( typename sched_type::member_type &, value_type & result ) { #if 0 printf( "\nTestFib(%ld) %d %d\n", n, int( !fib_m1.is_null() ), int( !fib_m2.is_null() ) ); #endif if ( n < 2 ) { result = n; } else if ( !fib_m2.is_null() && !fib_m1.is_null() ) { result = fib_m1.get() + fib_m2.get(); } else { // Spawn new children and respawn myself to sum their results. // Spawn lower value at higher priority as it has a shorter // path to completion. fib_m2 = Kokkos::task_spawn( Kokkos::TaskSingle( sched, Kokkos::TaskPriority::High ) , TestFib( sched, n - 2 ) ); fib_m1 = Kokkos::task_spawn( Kokkos::TaskSingle( sched ) , TestFib( sched, n - 1 ) ); Kokkos::Future< Space > dep[] = { fib_m1, fib_m2 }; Kokkos::Future< Space > fib_all = Kokkos::when_all( dep, 2 ); if ( !fib_m2.is_null() && !fib_m1.is_null() && !fib_all.is_null() ) { // High priority to retire this branch. Kokkos::respawn( this, fib_all, Kokkos::TaskPriority::High ); } else { #if 1 printf( "TestFib(%ld) insufficient memory alloc_capacity(%d) task_max(%d) task_accum(%ld)\n" , n , sched.allocation_capacity() , sched.allocated_task_count_max() , sched.allocated_task_count_accum() ); #endif Kokkos::abort( "TestFib insufficient memory" ); } } }