llm.c icon indicating copy to clipboard operation
llm.c copied to clipboard

Fix MSVC compilation error with openMP

Open avflyer opened this issue 1 year ago • 7 comments

Fix MSVC compilation error with openMP https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c3015?view=msvc-170

Besides, with this PR, openMP can also be disabled on windows paltform with 'NO_OMP=1' in makefile.

avflyer avatar May 25 '24 06:05 avflyer

Not following exactly - are you saying the current code generates a C3015?

rosslwheeler avatar May 25 '24 06:05 rosslwheeler

Not following exactly - are you saying the current code generates a C3015?

yes, in my evironment with MSVC, it did. After this modification, this error disappeared.

avflyer avatar May 25 '24 06:05 avflyer

Our Windows CI and all current Windows builds are passing. What version of MSVC are you using? Please run: Cl /Bv. Also, what options are you using with Make?

rosslwheeler avatar May 25 '24 06:05 rosslwheeler

Our Windows CI and all current Windows builds are passing. What version of MSVC are you using? Please run: Cl /Bv. Also, what options are you using with Make?

Well, I configured this project with visual studio 2022, with MSVC 19.39.33523.0. I copyed all the c_flags and ld_flags from Makefile. Then I encounterd this error (C3015). 6ab8246f-3955-4e76-86ef-85bc19ae7850

As you suggested, this time I tried the CI's way of building, which employs an external make.exe program. Yes, it succeeded. I don't know what causes this difference.

Besides, to my knowlege, putting declaration of varariables which have possible impact on OMP before the '#pragma omp parallel' macro could be much more safe without other drawbacks.

avflyer avatar May 25 '24 07:05 avflyer

Glad it works for you now when using make and the Makefile!

As far as the other changes, let's discuss those over in the Issues area. Microsoft does have a compiler bug with OpenMP 5.2 support which I've filed with them.

rosslwheeler avatar May 25 '24 07:05 rosslwheeler

I'm not 100% sure, but I thought putting the declarations in front of the openmp statements would actually totally break this code. Aren't variables from outside the parallel region automatically shared?

ngc92 avatar May 25 '24 20:05 ngc92

I'm not 100% sure, but I thought putting the declarations in front of the openmp statements would actually totally break this code. Aren't variables from outside the parallel region automatically shared?

Thx for pointing out this. I checked the OMP usesage and found that I did have a misunderstanding of the memory model. declarations in front of the openmp statements will be implicitly handled as shared vars, not private. Adding the private(var) statement will make those vars private.

I have already fix the codes.

avflyer avatar May 26 '24 02:05 avflyer