Issue 53154
Summary OpenMP target: `omp_pteam_mem_alloc` leaves variable thread-private
Labels new issue
Assignees
Reporter jkelling
    To my understanding of OpenMP 5.0 2.11.2 (page 154, lines 4-6) a variable declared inside a `parallel` region within a `teams` region should become shared between all threads executing that parallel region when using the following `omp allocate` construct with the `omp_pteam_mem_alloc` allocator:
```c++
#pragma omp allocate(varName) allocator(omp_pteam_mem_alloc)
```

Using the current Clan Main (95a436f8cca6991dc0f30588d9b1af3223818168) this test fails:
```c++
#include <iostream>
#include <cstdio>

#include <omp.h>

int main()
{
	int maxThreads = omp_get_max_threads();
	constexpr int numTeams = 4;

	int aLocal[numTeams];
	int aTeam[numTeams];

	std::cout << "maxThreads=" << maxThreads
		<< "\tnumTeams=" << numTeams << std::endl;

#pragma omp target data map(tofrom:aLocal,aTeam)
#pragma omp target
	{
#pragma omp teams num_teams(numTeams) thread_limit(maxThreads)
		{
#pragma omp distribute
			for(int t = 0; t < omp_get_num_teams(); ++t)
			{
				int team = 0;
#pragma omp parallel //num_threads(maxThreads)
				{
					int local = 0;
#pragma omp allocate(local) allocator(omp_pteam_mem_alloc)
#pragma omp atomic update
					local += t+1;
#pragma omp atomic update
					team += t+1;
#pragma omp barrier
					// printf("TEAM %d, THREAD=%d, local=%d, team=%d\n"
					// 	, (int)(omp_get_team_num()), (int)(omp_get_thread_num()), local, team);
					if(omp_get_thread_num() == 0)
						aLocal[t] = local;
				}
				aTeam[t] = team;
			}
		}
	}

	bool good = true;
	for(int a = 0; a < numTeams; ++a)
	{
		if(aLocal[a] != aTeam[a])
		{
			std::cerr << "allocator(omp_pteam_mem_alloc) not shared in team for team " << a << ": "
				<< aLocal[a] << " != " << aTeam[a] << '\n';
			good = false;
		}
	}

	return !good;
}
```
([on github](https://github.com/jkelling/omp5tests/blob/master/allocate/allocate.cpp))
* `CXXFLAGS=-"fopenmp -fopenmp=libomp -fopenmp-targets=x86_64-pc-linux-gnu -Wall -pedantic -Wopenmp-target -fopenmp=libomp -g -fopenmp"`

This shows, that the variable `local` remains private to each thread. Declaring `local` as `static` makes it shared in the whole target region (between all teams). In either case the `allocate` construct has no effect.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to