Page 1 of 1

Do we need to put class declaration in the shared clause

PostPosted: Mon Jul 01, 2013 9:27 pm
by ayongwust_sjtu
I sincerely hope and appreciate that somebody could share ideas.

Today, I found that if we want to involve OpenMP in our project, we need to put the class declaration in the shared clause, otherwise, we get a compiling error:

error C3052: 'OpenMesh::PolyConnectivity::FHandle' : variable doesn't appear in a data-sharing clause under a default(none) clause

#pragma omp parallel for default(none) private(faceHandle_) shared(intFacesSize_, TriMesh::FHandle)
for(int faceIndex_ = 0; faceIndex_ < intFacesSize_; ++faceIndex_) {
faceHandle_ = TriMesh::FHandle(faceIndex_);
}


Is this a requirement asked by OpenMP, or asked by the third-party library I am using????
It makes me not confident to use them together.

Re: Do we need to put class declaration in the shared clause

PostPosted: Fri Jul 05, 2013 2:54 am
by chabachull
Hi,

This error is due to the way you are using OpenMP.
You have put the "default(none)" clause in your parallel pragma. This clause requires that all the elements you are using in your parallel region should appear either in a "private(...)" or "shared(...)" clause.

You can write the same openmp line without the "default(none)" clause, and all the items that are not referenced in a data sharing clause will be considered by the runtime as shared variables. Then you will not have to add "TriMesh::FHandle" in the shared clause, and your code will be equivalent than the one you presented.

This should work:
Code: Select all
#pragma omp parallel for private(faceHandle_)
for(int faceIndex_ = 0; faceIndex_ < intFacesSize_; ++faceIndex_) {
  faceHandle_ = TriMesh::FHandle(faceIndex_);
}

Re: Do we need to put class declaration in the shared clause

PostPosted: Fri Jul 05, 2013 7:41 am
by MarkB
Just to be clear, you get that error message when compiling the code as present, is that correct?
Is TriMesh::FHandle a static class member?
What compiler are you using?

Re: Do we need to put class declaration in the shared clause

PostPosted: Fri Jul 05, 2013 10:40 am
by ayongwust_sjtu
First of all, I should say thanks to chabachull and MarkB. I appreciate for your help. :D

Secondly, I think I should re-depicte my case, because many of you, like MarB, might be confused by my case description.

This Monday, I compile the following code with VS2010:
Code: Select all
int intFacesSize_ = this->n_faces();
TriMesh::FHandle faceHandle_;
#pragma omp parallel for default(none) private(faceHandle_) shared(intFacesSize_)
for(int faceIndex_ = 0; faceIndex_ < intFacesSize_; ++faceIndex_) {
faceHandle_ = TriMesh::FHandle(faceIndex_);
}

I got a compile error:
error C3052: 'OpenMesh::PolyConnectivity::FHandle' : variable doesn't appear in a data-sharing clause under a default(none) clause

I felt so strange, then I tried the code below, and the compiling passed without error
Code: Select all
int intFacesSize_ = this->n_faces();
TriMesh::FHandle faceHandle_;
#pragma omp parallel for default(none) private(faceHandle_) shared(intFacesSize_, TriMesh::FHandle)
for(int faceIndex_ = 0; faceIndex_ < intFacesSize_; ++faceIndex_) {
faceHandle_ = TriMesh::FHandle(faceIndex_);
}


So, it made me so puzzled that why I need to put the class declaration in the shared clause?????? :x

Thirdly, let me give feedbacks to chabachull and MarkB.
To chabachull : Yes. Your proposal works. There are no errors using your suggestion.
Code: Select all
#pragma omp parallel private(faceHandle_, faceCorners_, faceEdges_, n, t, b)// shared(intFacesSize_, OSUTriMeshT::FHandle)

But, I really not want to ignore default(none) in my code and let the compiler decides the behaviors of my variables.

To MarkB: I am using Vs2010. and the FaceHandle is an ordinary struct as:

Code: Select all
/// Handle for a face entity
struct FaceHandle : public BaseHandle
{
  explicit FaceHandle(int _idx=-1) : BaseHandle(_idx) {}
};


Finally, I hope somebody could help me out.

Re: Do we need to put class declaration in the shared clause

PostPosted: Fri Jul 05, 2013 1:04 pm
by MarkB
This looks like a compiler error to me. The OpenMP implementation in VS2010 is rather old (it only supports Version 2.0).
If you are serious about doing OpenMP development, I would advise you to switch compiler.
I believe you can use the Intel compilers from inside Visual Studio.

Re: Do we need to put class declaration in the shared clause

PostPosted: Fri Jul 05, 2013 3:45 pm
by ayongwust_sjtu
Dear MarkB,
I am glad to see your quick instructions. I appreciate that.

Based on that, I have two questions:
1. This looks like a compiler error to me. The OpenMP implementation in VS2010 is rather old (it only supports Version 2.0).
Do you mean I'd better not use OpenMP in VS2010?
Come on, my friend. Please focus on the problem I am encountering right now. Why do I need to put the class declaration in the shared clause????
My problem is a new one to OpenMP users? Does the OpenMP execute right if I put put the class declaration in the shared clause?

2. If you are serious about doing OpenMP development, I would advise you to switch compiler. I believe you can use the Intel compilers from inside Visual Studio.
Oh, boy! This is the first time to hear about Intel compilers.
But I grateful for your suggestions, and like to do a google search about it.
Could you kindly help me out of my first question?

Best Wishes,
Xianyong.

Re: Do we need to put class declaration in the shared clause

PostPosted: Mon Jul 08, 2013 2:44 am
by MarkB
ayongwust_sjtu wrote:Why do I need to put the class declaration in the shared clause????

You should not need to. I think the compiler is at fault here. It looks like the checking it needs to do when you specify default(none) is getting confused by a typedef somewhere.

ayongwust_sjtu wrote: Does the OpenMP execute right if I put put the class declaration in the shared clause?

Most likely, yes.