Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7831 Discussions

OpenMP tasking issues in ICL and ICX

AndrewC
New Contributor III
1,034 Views

I believe there are  numerous problems with OpenMP tasking in ICL 2021.6.0  ( I suppose never to be fixed) and in ICX 2022.1.0


I will stand corrected by an OpenMP guru if my code is bogus! But I can't see anything wrong.

Problem #1
ICL compiled code executes incorrectly ( this has been extremely annoying) while ICX or (clang) compiled codes runs as expected - example function fails_intel_icl() 

Problem #2

ICL compiled code executes correctly, but ICX/Clang code crashes at runtime  - example function crash_icx_2022()

 

Problem #3

ICL compiled code executes correctly, but ICX/Clang will not even compile -example function clang_wont_compile()

 

I built and tested these projects using Visual Studio 2022/ Debug/x64 testing with the Classic Intel C++ compiler and Intel C++ 2022 compilers as well as Visual C++ Clang compilers.

The Problem #1 is quite a nasty issue. When compiled with ICL, the function fails_intel_icl() launches a series of tasks. Output will be different each time but the key thing to note is that some 'tasks' for a pair of integers never run, and  other times you will get "duplicate" tasks for the same pair of integers. When compiled with ICX/Clang the tasks all get executed as expected.

 


// this compiles and runs incorrectly under icl but runs correctly with icx or clang

void fails_intel_icl()
{
#	pragma omp parallel
	{
#	pragma omp single
		{
			for (auto iter = data.begin(); iter != data.end(); ++iter)
			{
				const auto a = iter->first;
				const auto b = iter->second;
				for (const auto aa : b)
				{
					if (aa != a)
					{
						{
#pragma omp critical
							std::cout << "Thread:" << omp_get_thread_num() << " launching task for " << ' ' << a << ',' << aa << std::endl;
						}
#	pragma omp task
						{
							DoTask(a, aa);
						}
					}
				}
			}
		}
	}
}

 

 

Full Code

#include <iostream>
#include <vector>
#include <omp.h>

std::vector<std::pair<int, std::vector<int>>> data;


void setup()
{
	std::vector<int> tmp({ 1,2,3,4,5 });
	for (int i = 0; i < 5; i++)
	{
		data.push_back({ i,tmp });
	}
}



void DoTask(int a, int b)
{
	{
#pragma omp critical
		std::cout << "Thread " << omp_get_thread_num() << ' ' << a << ',' << b << std::endl;
	}
}

// runs correctly under icl, but crashes at runtime with icx and clang
void crash_icx_2022()
{
#	pragma omp parallel
	{
#	pragma omp single
		{
			for (auto iter = data.begin(); iter != data.end(); ++iter)
			{
				const auto& a = iter->first;
				const auto& b = iter->second;
				for (const auto& aa : b)
				{
					if (aa != a)
					{
						{
#pragma omp critical
							std::cout << "Thread:" << omp_get_thread_num() << " launching task for " << ' ' << a << ',' << aa << std::endl;
						}
#	pragma omp task
						{
							DoTask(a, aa);
						}
					}
				}
			}
		}
	}
}


// this compiles and runs incorrectly under icl but runs correctly with icx or clang

void fails_intel_icl()
{
#	pragma omp parallel
	{
#	pragma omp single
		{
			for (auto iter = data.begin(); iter != data.end(); ++iter)
			{
				const auto a = iter->first;
				const auto b = iter->second;
				for (const auto aa : b)
				{
					if (aa != a)
					{
						{
#pragma omp critical
							std::cout << "Thread:" << omp_get_thread_num() << " launching task for " << ' ' << a << ',' << aa << std::endl;
						}
#	pragma omp task
						{
							DoTask(a, aa);
						}
					}
				}
			}
		}
	}
}

// wont even compile with icx or clang, but runs correctly with icl
#ifndef __clang__
void clang_wont_compile()
{
#	pragma omp parallel
	{
#	pragma omp single
		{
			for (const auto& [a, b] : data)
			{
				for (const auto& aa : b)
				{
					if (aa != a)
					{
#	pragma omp task
						{
							DoTask(a, aa);
						}
					}
				}
			}
		}
	}
}
#endif



void testTaskingBug()
{
	setup();

	std::cout << "Starting test using copies  iter " << std::endl;
	fails_intel_icl();
	std::cout << "Starting test using references and iter " << std::endl;
	crash_icx_2022();
#ifndef __clang__
	std::cout << "Starting test using C++17 loop " << std::endl;
	clang_wont_compile();
#endif
}
int main()
{
	testTaskingBug();
	return 0;
}
0 Kudos
10 Replies
AndrewC
New Contributor III
994 Views

I found the clang compiler error when compiling the function clang_wont_compile() is a long standing standards issue with capturing structured bindings in C++17 that compilers interpret differently and is supposed to be cleared up by the C++20 standard. It can be worked around quite easily

0 Kudos
AndrewC
New Contributor III
986 Views

I have tested with clang version 14.0.6 and it does not crash on the code that crashes icx at runtime. So obviously clang has been fixed in a version later than whatever icx is based on.

0 Kudos
NoorjahanSk_Intel
Moderator
950 Views

Hi,

 

Thanks for reaching out to us.

We are working on your issue. We will get back to you soon.

 

Thanks & Regards,

Noorjahan.

 

0 Kudos
Viet_H_Intel
Moderator
875 Views

Hi,

For issue #1:  At some point in the future, the classic C/C++ compilers will enter “Legacy Product Support” mode signaling the end of regular updates to the classic compiler base, and they will no longer appear in oneAPI toolkits. So, the change to get this fixed in icl is very low. Please see https://www.intel.com/content/www/us/en/developer/articles/technical/adoption-of-llvm-complete-icx.html


For issue #2: I think you had reported this issue to us before and it's a known issue from LLVM community https://bugs.llvm.org/show_bug.cgi?id=33678


For #3: I will check our internal compiler to see if it still crashes or not and will update you.


Thanks,


0 Kudos
Viet_H_Intel
Moderator
859 Views

I checked and didn't see the crash with upcoming compiler.

Thanks,


0 Kudos
Viet_H_Intel
Moderator
637 Views

Hi,

 

We've released oneAPI 2022.3. Can you upgrade to this version and let us know if you still have issue?

 

Thanks,

 

0 Kudos
AndrewC
New Contributor III
633 Views

I upgraded to One API 2022.3, but unfortunately encountered two blocking issues that have forced me to revert to OneAPI 2022.2

0 Kudos
Viet_H_Intel
Moderator
627 Views

Unfortunately that you hit other issues, but did it fix the original OpenMP problems you initially reported in this thread?

Thanks,


0 Kudos
AndrewC
New Contributor III
609 Views

Yes it is fixed in the OneAPI 2022.3 distribution

0 Kudos
Viet_H_Intel
Moderator
429 Views

Let's close this thread as fixed. Please create new tickets for other issues you encountered with oneAPI 2022.3


Thanks,



0 Kudos
Reply