Diagnostic 1392: variable "entity" in firstprivate or lastprivate clause of an OpenMP pragma must be shared in the enclosing context

Cause
One case that the Intel C++ Compiler will emitting this diagnostic message is when using the "firstprivate" of OpenMP* with a wrong syntax.

Example
t.cpp:

 

#include <stdio.h>

int main(int argc, char* argv[]) 
{
	int mysum=0;

#pragma omp for firstprivate(mysum)
	for (int i=0; i<1000; i++) {
		mysum += i; 
	}

	printf("mysum=%drn", mysum);
	return 0;
}

 

Output from build environment on Windows:

C:\temp\>icl /c /Od /Qopenmp t.cpp
Intel® C++ Compiler XE for applications running on IA-32, Version 12.0.0.104 Build 20101006 Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

t.cpp
t.cpp(7): error: variable "mysum" in firstprivate or lastprivate clause of an OpenMP pragma must be
shared in the enclosing context
  #pragma omp for firstprivate(mysum)
  ^

compilation aborted for t.cpp (code 2)

C:\temp\> 

Resolution

For the case in t.cpp, change the

#pragma omp for firstprivate(mysum)

 to

#pragma omp parallel for firstprivate(mysum)
有关编译器优化的更完整信息,请参阅优化通知