Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
92 Views

Variable died for no reason

During the C++ application execution one of the variables dies for no reason. I think that the causes of this problem are connected to memory. However, I don't have any ideas how to solve this problem. What could be the cause of this problem?

0 Kudos
6 Replies
Highlighted
Beginner
92 Views

It seems that site doesn't work correctly so I have to continue here:

Hi!

I discovered that some simple arithmetic OpenMP parallel programs runs faster with using icpc compiler instead of g++.
However, when I have tried to compile big OpenMP application (which works correctly with g++) with icpc, it has broken. Using manual code debugging I have discovered that the issue is that one of the variables dies for no reason. I have faced this issue earlier with this application and g++ compiler, but in different mode. It works like:
//no parallel code before this problem
cout<<"var is alive"<<endl;//all works correctly
cout<<var<<endl;
var2 = 0;
cout<<"var is dead"<<endl;
cout<<var<<endl;//program dies

I face this problem on a completely different devices, so I think that it doesn't matter. Are there any general causes of such phenomena? What should I do to solve this problem?

0 Kudos
Highlighted
92 Views

Grigorii Vasilev wrote:

I have faced this issue earlier with this application and g++ compiler, but in different mode. It works like:

...

You have the answer in this sentence - something is wrong in your code. it looks one thread has overwritten a stack of another thread

1. is "program dies" segfault, kill, illegal instruction or what? what is the back trace?

2. is the problem appears in serial block or in parallel section?

0 Kudos
Highlighted
Beginner
92 Views

Problem is solved. In my particular case the cause of the problem was that absolutely another variable was changed by different threads/functions, so I have made that variable const.

So, if you have similar problem you should check all code.

0 Kudos
Highlighted
Moderator
92 Views

Hi,

Since your problem is solved, can we close this thread?

0 Kudos
Highlighted
Beginner
92 Views

Hi!

Yes.

0 Kudos
Highlighted
Moderator
92 Views

Thanks for the confirmation.

0 Kudos