-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread safety of embree device? #207
Comments
API calls to the same object are not thread safe in general, thus you cannot have two threads modify some geometry. However, the rtcIntersect/rtcOccluded calls can be invoked from multiple threads, thus what you do is correct. Where is the crash appearing? |
Thanks, I think I can do some unit test first to check my code |
Here is my code. _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); The function below is used parallely outside. std::vector<bool> MeshEmbreeBVH::ray_intersected(const Vector3d &origin, const std::vector<Vector3d> &direction,
float dnear /*= 0.0f*/, float dfar /*= FLT_MAX*/,
int mask /*= 0xFFFFFFFF*/) {
std::vector<bool> hits(direction.size());
std::vector<RTCRay> rays(direction.size());
for (int i = 0; i < direction.size(); ++i) {
RTCRay ray;
ray.org_x = origin(0);
ray.org_y = origin(1);
ray.org_z = origin(2);
ray.dir_x = direction[i](0);
ray.dir_y = direction[i](1);
ray.dir_z = direction[i](2);
ray.tnear = dnear;
ray.tfar = dfar;
ray.mask = -1;
ray.time = 0.0f;
ray.flags = 0;
ray.id = i;
rays[i] = ray;
}
RTCIntersectContext context;
rtcInitIntersectContext(&context);
context.flags = RTC_INTERSECT_CONTEXT_FLAG_NONE;
rtcOccluded1M(scene_, &context, rays.data(), rays.size(), sizeof(RTCRay));
CHECK_EMBREE_ERROR(device_);
std::vector<bool> results(rays.size(), false);
for (int i = 0; i < rays.size(); ++i) {
if (rays[i].tfar == -std::numeric_limits<float>::infinity()) {
results[i] = true;
} else {
results[i] = false;
}
}
return results;
} And the macro is #define CHECK_EMBREE_ERROR(device) \
{ \
auto error = rtcGetDeviceError(device); \
CHECK(error == RTC_ERROR_NONE) << "Error code " << error; \
} So the only thing that I am uncertain is |
Does the code work if you do not parallelize this function? |
@svenwoop yes, it works if I comment out openmp |
Could you please give a stack trace where it crashes exactly? |
I think I have solved the problem. It is not related to embree. Thanks! |
I have a embree device and a scene created and commited in the main thread, and I want to do rtcIntersect using the same device from different threads (using openmp).
Sometimes the program just hang forever or crashes randomly.
I would like to ask that if Embree device is thread safe or not? This will help me to isolate the problem.
Thanks,
Han
The text was updated successfully, but these errors were encountered: