Magic outputs that I am experiencing.

Aug 10, 2015 at 8:07pm
I have coded a quite long code and I use boost for multithreading (3 threads, two of them depend on each other) I am obtaining very weird results, namely:

ISSUE 1 ) If I define one more variable in one class my code compiles correctly but it will not produce the same results. I do not know why, but results are worse if I define one random variable more.. Right now there are like 60 variables defined in that class.

ISSUE 2 ) The other day, I removed one variable that I was not using and then the code performed worse... this is magic also.

ISSUE 3 )Another day, I had to remove this variable I was not using, if would not have removed it, it would have worked worse. This is just the opposite that happened to me in ISSUE 2.

ISSUE 4 ) Similar to previous errors. I had a library that I was not using, so I removed the include file and it compiled well but the performance was worse (?)... after a few ours were I changed a couple of lines (which were not related to this library) I could remove this include file without decreasing the performance of the code... Really weird..

Is any of you familiar with this issues?
I know that all this errors come from the fact that I am not an expert in C++ , but I would like to learn to avoid them.... many thanks for your time.


Edit: By 'it performs worse' I do not exactly mean that. It just does not perform in any way. It is like the code does not enter in the boost threads or something like that, but I do not obtain any input.
Last edited on Aug 10, 2015 at 8:12pm
Aug 10, 2015 at 8:19pm
Sounds like your build is doing funky things. At least that is my guess. Try doing a clean build by removing object files and recompiling everything. Also, it would be nice to know what compiler are you using? How much worse does the code perform? How are you measuring performance? What extra compiler flags are you using? Are any of these extra flags meant for optimization?
Aug 10, 2015 at 8:25pm
Thanks for you questions

I did a clean build but the same weird things happens...

I think I use gcc compiler.

By 'it performs worse' I do not exactly mean that. It just does not perform in any way. It is like the code does not enter in the boost threads or something like that, but I do not obtain any input.

Yes I use optimization flags:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")

Last edited on Aug 10, 2015 at 8:29pm
Aug 10, 2015 at 8:37pm
Might be worth posting smallest test case that you can to see if there is anything obviously wrong.
Last edited on Aug 10, 2015 at 8:37pm
Aug 10, 2015 at 8:40pm
James2250 it is difficult to do that.. it is a quite long code (more than 5000 lines...). It is difficult to see what I am doing wrong.
Aug 10, 2015 at 8:46pm
I am sorry I cannot give more details.. but it is not a specific error, it is just weird things that happen to my code from time to time...
Aug 10, 2015 at 11:20pm
you may be invoking undefined behaviour.
Run through valgrind to detect invalid access
Topic archived. No new replies allowed.