Skip to content

Free-agent thread #859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,14 @@ $(CURDIR)/tests/4.5/application_kernels/qmcpack_target_static_lib.c.o: $(CURDIR)
%.c.run: $(OBJS_C)
$(call log_section_header,"RUN",$(SYSTEM),$(@:.run=),$(LOG_NOTE),$(OMP_VERSION),$(notdir $(@:.run=.log)))
@echo -e $(TXTGRN)"\n\n" running: $@ $(TXTNOC) $(if $(LOG), ${RECORD}$(notdir $(@:.run=.log)))

# If .../test_<envname>_env_<value>...
$(if $(findstring _THREADS_RESERVE,$@), \
-$(call loadModules,$(C_COMPILER_MODULE)) \
$(BSRUN)$(RUN_TEST) --env OMP_THREAD_LIMIT 16 \
--env OMP_THREADS_RESERVE "structured(5)$(comma)free_agent(2)" \
$(@:.run=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.run=.log)) \
&& echo "PASS" > $(LOGTEMPFILE) || echo "FAIL" > $(LOGTEMPFILE)), \
$(if $(findstring _env_,$@), \
-$(call loadModules,$(C_COMPILER_MODULE)) \
$(BSRUN)$(RUN_TEST) --env \
Expand All @@ -325,10 +332,11 @@ $(CURDIR)/tests/4.5/application_kernels/qmcpack_target_static_lib.c.o: $(CURDIR)
-$(call loadModules,$(C_COMPILER_MODULE)) $(BSRUN)$(RUN_TEST) $(@:.run=.o) $(VERBOSE) $(if $(LOG),$(RECORD)$(notdir $(@:.run=.log))\
&& echo "PASS" > $(LOGTEMPFILE) \
|| echo "FAIL" > $(LOGTEMPFILE)) \
)
))
-$(call log_section_footer,"RUN",$(SYSTEM),$$(cat $(LOGTEMPFILE)),$(LOG_NOTE),$(notdir $(@:.run=.log)))
-@$(if $(LOG), rm $(LOGTEMPFILE))


# run c++ app rule
%.cpp.run: $(OBJS_CPP)
$(call log_section_header,"RUN",$(SYSTEM),$(@:.run=),$(LOG_NOTE),$(OMP_VERSION),$(notdir $(@:.run=.log)))
Expand Down
96 changes: 96 additions & 0 deletions tests/6.0/task/test_task_threadset_THREADS_RESERVE.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//--------------test_task_threadset.c-----------------------------------------//
// OpenMP API Version 6.0 November 2024
// Pg. 901, line 30
// ***********
// DIRECTIVE:task
// CLAUSE:threadset
// ***********
// This test checks the functionality of the threadset clause with the task
// directive. The example referenced here is "5.10 Free Agent Threads" which is
// taken from the 6.0 examples document. It checks if the task is executed by a
// free-agent thread when threadset(omp_pool) is used, and that the result of
// the Fibonacci calculation is correct when both omp_pool and omp_team is used.
//----------------------------------------------------------------------------//

#include "ompvv.h"
#include <omp.h>

// not too large
#define N 5

int count = 0;

int fib_seq(int n) {
if (n < 2)
return n;
return fib_seq(n - 1) + fib_seq(n - 2);
}

int fib(int n, int use_pool) {
int i, j;

if (use_pool) {
if (omp_is_free_agent()) {
#pragma omp atomic
count++;
}
}
if (n < 2)
return n;
if (use_pool) {
#pragma omp task shared(i) threadset(omp_pool)
i = fib(n - 1, use_pool);
#pragma omp task shared(j) threadset(omp_pool)
j = fib(n - 2, use_pool);
#pragma omp taskwait
} else {
#pragma omp task shared(i) threadset(omp_team)
i = fib(n - 1, use_pool);
#pragma omp task shared(j) threadset(omp_team)
j = fib(n - 2, use_pool);
#pragma omp taskwait
}

return (i + j);
}

int task_work(int n, int use_pool) {
int errors = 0;
count = 0;
int result;

omp_set_num_threads(OMPVV_NUM_THREADS_HOST);
#pragma omp parallel
#pragma omp single
{
result = fib(n, use_pool);
}
if (use_pool) {
OMPVV_WARNING_IF(
count == 0,
"no free-agent threads in region"); // count should be greater than 0 if
// a free-agent thread executed the
// task
}
OMPVV_TEST_AND_SET(errors, result != fib_seq(n));
return errors;
}

int test_task_threadset() {
int errors = 0;
int n = N;

// Test task with threadset(omp_pool)
errors += task_work(n, 1);

// Test task with threadset omp_team
errors += task_work(n, 0);

return errors;
}

int main() {
int errors = 0;
OMPVV_TEST_AND_SET(errors, test_task_threadset() != 0);
OMPVV_REPORT_AND_RETURN(errors);
}