ホーム » VC OpenMP » #pragma omp critical

2023年12月
 12
3456789
10111213141516
17181920212223
24252627282930
31  

カテゴリー

アーカイブ

ブログ統計情報

  • 80,423 アクセス



#pragma omp critical

共通のリソースに対してのコードを書いていて,ちょっと気になったので調べてみた.
テスト用に書いたのコードは次の様なもの.

#ifdef		_OPENMP
#include	<omp.h>
#endif

#include	<clocale>
#include	<iostream>

#ifdef	_MSC_VER
	#include	<tchar.h>
#else
	#define		 _T(x)			x
	typedef		char			TCHAR ;
#endif

#ifdef	_UNICODE
	#define		_tmain			wmain
	#define		tout			wcout
#else
	#define		_tmain			main
	#define		tout			cout
#endif

bool	test_n	(const long n)
{
	std::tout << _T("test_") << n << _T("\t") ;
	{
		for (long index=0 ; index<10 ; index++) {
			#ifdef	_OPENMP
			//	#pragma	omp	critical	//	(test)		//	--- (C)
			#endif
			{
				std::tout << (n*10 + index+1) << _T("\t") ;
				}
			}
		}
	return	true ;
	}

bool	test_	(void)
{
	std::tout << _T("test_") << std::endl ;
	{
		#ifdef	_OPENMP
			#pragma	omp	parallel for
		#endif
		for (long index=0 ; index<10 ; index++) {
			#ifdef	_OPENMP
				#pragma	omp	critical	//	(test)		//	--- (P)
			#endif
			{
				test_n(index) ;
				std::tout << std::endl ;
				}
			}
		}
	return	true ;
	}

int	_tmain	(int argc,TCHAR* argv[])
{
	{
		::test_() ;
		}
	return	0 ;
	}

実行させると,期待通り.
#pragma omp critical


ここで,関数 test_n() の次の行を有効にしてしまうと…
#pragma omp critical // (test) // — (C)
test_
test_0 致命的なユーザー エラー 1002: 同一名の 1 つで ‘#pragma omp critical’ が不適切に入れ子にされています
致命的なユーザー エラー 1002: 同一名の 1 つで '#pragma omp critical' が不適切に入れ子にされています
それぞれを異なる名称で指定する必要がある.
#pragma omp critical (test_n) // — (C)
#pragma omp critical (test_) // — (P)
#pragma omp critical 異なる名称
VC リリース版ではうまく動作してしまうこともある?


Linux 環境でコンパイルした a.out を NAS 環境に持っていくと,DS220+ では実行できた.
-fopenmp を付けたコンパイルは不可
TS253D では「libgomp.so がない」となって実行できない.
OpenMP  a.out の NAS での実行

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.
%d人のブロガーが「いいね」をつけました。