diff --git a/include/spla/schedule.hpp b/include/spla/schedule.hpp index ddb763016..ed601515f 100644 --- a/include/spla/schedule.hpp +++ b/include/spla/schedule.hpp @@ -79,6 +79,15 @@ namespace spla { */ SPLA_API ref_ptr make_schedule(); + /** + * @brief Immediately executes provided task and return only when task is finished + * + * @param task Task to execute immediately + * + * @return Ok if finished without errors + */ + SPLA_API Status execute_immediate(ref_ptr task); + /** * @brief Scheduled callback function * diff --git a/src/algorithm.cpp b/src/algorithm.cpp index 384b5fc02..b8739c992 100644 --- a/src/algorithm.cpp +++ b/src/algorithm.cpp @@ -58,14 +58,9 @@ namespace spla { while (!frontier_empty) { depth->set_int(current_level); - ref_ptr bfs_body = make_schedule(); - ref_ptr bfs_assign = make_sched_v_assign_masked(v, frontier_prev, depth, SECOND_INT); - ref_ptr bfs_step = make_sched_mxv_masked(frontier_new, v, A, frontier_prev, MULT_INT, OR_INT, zero, complement); - ref_ptr bfs_check = make_sched_v_reduce(frontier_size, zero, frontier_new, PLUS_INT); - bfs_body->step_task(bfs_assign); - bfs_body->step_task(bfs_step); - bfs_body->step_task(bfs_check); - bfs_body->submit(); + spla::execute_immediate(make_sched_v_assign_masked(v, frontier_prev, depth, SECOND_INT)); + spla::execute_immediate(make_sched_mxv_masked(frontier_new, v, A, frontier_prev, MULT_INT, OR_INT, zero, complement)); + spla::execute_immediate(make_sched_v_reduce(frontier_size, zero, frontier_new, PLUS_INT)); int observed_vertices; frontier_size->get_int(observed_vertices); diff --git a/src/schedule.cpp b/src/schedule.cpp index 8da066e78..6778ab530 100644 --- a/src/schedule.cpp +++ b/src/schedule.cpp @@ -37,6 +37,12 @@ namespace spla { return ref_ptr(new ScheduleSingleThread); } + Status execute_immediate(ref_ptr task) { + auto schedule = make_schedule(); + schedule->step_task(std::move(task)); + return schedule->submit(); + } + ref_ptr make_sched_callback( ScheduleCallback callback, ref_ptr desc) { diff --git a/tests/test_mxv.cpp b/tests/test_mxv.cpp index 81c9aff38..62c45723b 100644 --- a/tests/test_mxv.cpp +++ b/tests/test_mxv.cpp @@ -70,9 +70,7 @@ TEST(mxv_masked_comp, naive) { iM->set_int(2, 2, 3); iM->set_int(3, 4, -1); - auto schedule = spla::make_schedule(); - schedule->step_task(spla::make_sched_mxv_masked(ir, imask, iM, iv, spla::MULT_INT, spla::PLUS_INT, iinit, true)); - schedule->submit(); + spla::execute_immediate(spla::make_sched_mxv_masked(ir, imask, iM, iv, spla::MULT_INT, spla::PLUS_INT, iinit, true)); int r; diff --git a/tests/test_vector.cpp b/tests/test_vector.cpp index d4a4fc2e4..ffcb466a0 100644 --- a/tests/test_vector.cpp +++ b/tests/test_vector.cpp @@ -80,9 +80,7 @@ TEST(vector, reduce_plus) { isum += X[k]; } - auto schedule = spla::make_schedule(); - schedule->step_task(spla::make_sched_v_reduce(ir, istart, ivec, spla::PLUS_INT)); - schedule->submit(); + spla::execute_immediate(spla::make_sched_v_reduce(ir, istart, ivec, spla::PLUS_INT)); int result; ir->get_int(result); @@ -110,9 +108,7 @@ TEST(vector, reduce_mult) { isum *= X[k]; } - auto schedule = spla::make_schedule(); - schedule->step_task(spla::make_sched_v_reduce(ir, istart, ivec, spla::MULT_INT)); - schedule->submit(); + spla::execute_immediate(spla::make_sched_v_reduce(ir, istart, ivec, spla::MULT_INT)); int result; ir->get_int(result); @@ -142,9 +138,7 @@ TEST(vector, assign_plus) { R[I[k]] = R[I[k]] + S; } - auto schedule = spla::make_schedule(); - schedule->step_task(spla::make_sched_v_assign_masked(ivec, imask, ival, spla::PLUS_INT)); - schedule->submit(); + spla::execute_immediate(spla::make_sched_v_assign_masked(ivec, imask, ival, spla::PLUS_INT)); for (int k = 0; k < N; k++) { int r; @@ -175,9 +169,7 @@ TEST(vector, assign_second) { R[I[k]] = S; } - auto schedule = spla::make_schedule(); - schedule->step_task(spla::make_sched_v_assign_masked(ivec, imask, ival, spla::SECOND_INT)); - schedule->submit(); + spla::execute_immediate(spla::make_sched_v_assign_masked(ivec, imask, ival, spla::SECOND_INT)); for (int k = 0; k < N; k++) { int r;