hi all,
I am trying to figure out for last 2 days why this code is not working. The code is giving me memory access error.
Link Copied
You are executing parallel_reduce on the range [0..7) (size of edgeList). Then inside Parallel_StringFinder::operator() you are using this range [0..7) to index into nodesToInsert array which is of size [0..2):
edgeToInsert = nodesToInsert.at(I);
Obviously, when I >= 2 nodesToInsert.at() function throws out_of_range exception.
Here is how you can track down such kind of errors in MSVC:
0. Run the program under debugger.
1. Check out "Output" window after execution. Output windows contains something like:
[...]
First-chance exception at 0x7c812aeb (kernel32.dll) in static_tbb.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0085ba58..
First-chance exception at 0x7c812aeb (kernel32.dll) in static_tbb.exe: Microsoft C++ exception: tbb::captured_exception at memory location 0x0012f440..
Unhandled exception at 0x7c812aeb (kernel32.dll) in static_tbb.exe: Microsoft C++ exception: tbb::captured_exception at memory location 0x0012f440..
[...]
Notice there was canceled (First-chance exception) std::out_of_range exception. Which is probably the cause of the problem.
2. Then you go to the Debug->Exceptions window. There you must mark "std::exception" (this is the base class of std::out_of_range exception).
3. Run the program once again.
Not debugger will stop execution when first std::out_of_range exception is thrown.
In the Call Stack window you can see where exception occurs:
edgeToInsert = nodesToInsert.at(I);
Also you can see than I == 3, and nodesToInsert.size() == 2.
Further reasoning is straightforward.
I am trying to figure out for last 2 days why this code is not working. The code is giving me memory access error.
You are executing parallel_reduce on the range [0..7) (size of edgeList). Then inside Parallel_StringFinder::operator() you are using this range [0..7) to index into nodesToInsert array which is of size [0..2):
edgeToInsert = nodesToInsert.at(I);
Obviously, when I >= 2 nodesToInsert.at() function throws out_of_range exception.
You are executing parallel_reduce on the range [0..7) (size of edgeList). Then inside Parallel_StringFinder::operator() you are using this range [0..7) to index into nodesToInsert array which is of size [0..2):
edgeToInsert = nodesToInsert.at(I);
Obviously, when I >= 2 nodesToInsert.at() function throws out_of_range exception.
Here is how you can track down such kind of errors in MSVC:
0. Run the program under debugger.
1. Check out "Output" window after execution. Output windows contains something like:
[...]
First-chance exception at 0x7c812aeb (kernel32.dll) in static_tbb.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0085ba58..
First-chance exception at 0x7c812aeb (kernel32.dll) in static_tbb.exe: Microsoft C++ exception: tbb::captured_exception at memory location 0x0012f440..
Unhandled exception at 0x7c812aeb (kernel32.dll) in static_tbb.exe: Microsoft C++ exception: tbb::captured_exception at memory location 0x0012f440..
[...]
Notice there was canceled (First-chance exception) std::out_of_range exception. Which is probably the cause of the problem.
2. Then you go to the Debug->Exceptions window. There you must mark "std::exception" (this is the base class of std::out_of_range exception).
3. Run the program once again.
Not debugger will stop execution when first std::out_of_range exception is thrown.
In the Call Stack window you can see where exception occurs:
edgeToInsert = nodesToInsert.at(I);
Also you can see than I == 3, and nodesToInsert.size() == 2.
Further reasoning is straightforward.
Here is how you can track down such kind of errors in MSVC:
0. Run the program under debugger.
1. Check out "Output" window after execution. Output windows contains something like:
[...]
First-chance exception at 0x7c812aeb (kernel32.dll) in static_tbb.exe: Microsoft C++ exception: std::out_of_range at memory location 0x0085ba58..
First-chance exception at 0x7c812aeb (kernel32.dll) in static_tbb.exe: Microsoft C++ exception: tbb::captured_exception at memory location 0x0012f440..
Unhandled exception at 0x7c812aeb (kernel32.dll) in static_tbb.exe: Microsoft C++ exception: tbb::captured_exception at memory location 0x0012f440..
[...]
Notice there was canceled (First-chance exception) std::out_of_range exception. Which is probably the cause of the problem.
2. Then you go to the Debug->Exceptions window. There you must mark "std::exception" (this is the base class of std::out_of_range exception).
3. Run the program once again.
Not debugger will stop execution when first std::out_of_range exception is thrown.
In the Call Stack window you can see where exception occurs:
edgeToInsert = nodesToInsert.at(I);
Also you can see than I == 3, and nodesToInsert.size() == 2.
Further reasoning is straightforward.
Hello Dmitriv V'jukov sir,
Thanks for your kind help and the way to setup the workbench. I was so indulge in problem that I was not able to think of this mistake.
Thanks once again sir.
Please keep correcting me in future.
With regards
Deependu
For more complete information about compiler optimizations, see our Optimization Notice.