[Closed] SDK – anything against OpenMP?
Hi,
I’m curious: is there anything speaking against using openMP everywhere?
It’s so easy (the basics at least) but it’s used nowhere in the samples which brings me to this quesion. I used two lines, one for the include and one line before a regular for loop and gained 500ms from that. So simple, so efficient.
Thanks!
Thanks Klvnk,
so from what I’ve read, one can use OpenMP as long as no internal functions are used because those functions are not thread safe? And everything related to rendering should be coded thread safe?
Could you share the code? I was playing with multithreading lately without any performance gains, I was trying to calculate vertex normals on highpoly mesh, I used WinAPI function CreateThread, I was able to calculate it correctly, but the more threads I created the longer it took to calculate.
Hi Tamyl,
sorry for the late reply.
- open the project settings and navigate to: Configuration Properties > C/C++ > Language and change “Open MP Support” to “Yes”.
- put “#include <omp.h>” in your file(s)
- put “#pragma omp parallel for” directly one line above a “for (int i = 0; i < 100000; i++)”
You should read some tutorials on how OpenMP works, for example if you try to print out i in the code above you will not get “0, 1, 2, 3, 4,…” but “0, 3, 4, 2, 1,…”
See the Shell (SolidifyPW) modifier, function BuildData in BuildNormalInfo.cpp, there’s also a critical section handling with omp.
Interesting! Which SDK version are you looking at? I’ve searched BuildMeshInfo::BuildData in the whole project of the Max 2013 version and there is nothing about critical section handling with omp… :shrug:
I’m using 2014 SDK
if ((aA == 0.0f) || (aB == 0.0f) || (aC == 0.0f))
{
#pragma omp critical
degFaces.Append(1,&j);
fnorms[j] = Point3(0.0f,0.0f,0.0f);
}