-
Notifications
You must be signed in to change notification settings - Fork 20
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
Open
andrewkallai
wants to merge
12
commits into
master
Choose a base branch
from
task_threadset
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Free-agent thread #859
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
56178e3
Adding first test, does not compile.
andrewkallai 2ebfa83
Adding test template, does not compile. Significant changes are needed.
andrewkallai 585edf0
Adding update to the test with the fib as the main body of work.
9766080
Merge branch 'task_threadset' of https://github.com/OpenMP-Validation…
6cdb55e
Updating comment.
a2d04ef
Update test_task_threadset.c
andrewkallai 156f4fe
Changes, out of memory error.
andrewkallai 8c41a8c
changes
andrewkallai 0f9dfec
add
andrewkallai 6dc79aa
add
andrewkallai 4b462c3
a
andrewkallai cb96c86
add changes with shared clause
andrewkallai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 default threadset (should be omp_team) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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); | ||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.