- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
I have got two vectors, nodeList and nodesToInsert .And I want to insert the nodes from nodesToInsert
to the finalNodeList vector.
checkNodeForInsertion() is a dummy function which here is just returning true. In actual system it consist of
logic which is working fine.
The final outcome of the program is to have all the nodes in finalNodesList vector.
The working code is as follows:-
#include "tbb/task_scheduler_init.h"
#include "tbb/parallel_reduce.h"
#include "tbb/blocked_range.h"
#include
#include
#include
using namespace tbb;
using namespace std;
class Parallel_StringFinder{
vector
vector
public:
vector
void operator()(const blocked_range
string stringTemp;
string edgeToInsert;
bool flag1=false,flag2=false,toInsert=false;
for(size_t I = r.begin(); I< r.end();++I)
{
edgeToInsert = nodesToInsert.at(I);
toInsert = false;
for (int it=0; it!=edgeList.size(); it++)
{
stringTemp = edgeList.at(it);
if(stringTemp.size()!=edgeToInsert.size())
{
flag1 = true;
continue;
}
else
{
flag2 = true;
flag1=false;
toInsert = checkNodeForInsertion(stringTemp,edgeToInsert);
if((toInsert)==0)
break;
}
}
if(toInsert){
finalNodesList.push_back(edgeToInsert);
cout<<"................Node inserted-->"<
if(flag1&&!flag2){
finalNodesList.push_back(edgeToInsert);
cout<<"................Node inserted-->"<
}
}
Parallel_StringFinder(vector
{}
Parallel_StringFinder(Parallel_StringFinder& stringFinder,split)
{
cout<
this->nodesToInsert = stringFinder.nodesToInsert;
}
void join(const Parallel_StringFinder& stringFinder)
{
cout<
}
bool checkNodeForInsertion(string temp1,string temp2)
{
return true;
}
};
int main()
{
task_scheduler_init init;
vector
edgeList.push_back("GHQR");
edgeList.push_back("QRMN");
edgeList.push_back("KLMN");
edgeList.push_back("MNYZ");
edgeList.push_back("ABYZ");
edgeList.push_back("ABCD");
edgeList.push_back("CDYZ");
vector
nodesToInsert.push_back("KLMNABCD");
nodesToInsert.push_back("GHQRKLMN");
Parallel_StringFinder pf(edgeList,nodesToInsert,edgeList);
parallel_reduce(blocked_range
vector
for(int i=0;i
int i;
cout<<"Enter some value continue..."
cin>>i;
}
How the code is now behaving:-
When the code runs, it
Sometimes run fine.
But most of the times it gives me error
"Unhandled exception at 0x7c81eb33 in IntelCompetition.exe: Microsoft C++ exception: tbb::captured_exception at memory location 0x0012f930.."
and lands up in the file task.h at following code snippet
static void spawn_root_and_wait( task& root ) {
__TBB_ASSERT( root.is_owned_by_current_thread(), "root not owned by current thread" );
this line---> root.prefix().owner->spawn_root_and_wait( root, root.prefix().next );
}
Please let me know if more infomation is needed
Thanks
With regards
Deependu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page