DFS algorithm not working with ArBB

DFS algorithm not working with ArBB

I'm using intel ArBB to implement the DFS algorithm on an adjacency matrix to compare the performance with the usual c++ language, however there seems to be a problem and the algorithm is not working.
When i run it without using the call function it works fine, however when i use the call it enters an infinite loop.

This is the algorithm i implemented:

#include
#include
#define UNVISITED 0
#define VISITED 1
using namespace arbb;
using namespace std;

dense Matrix;
dense Mark;

void
DFS(i32 vertex, i32 numVertex)
{
_if (Mark[vertex] == VISITED) {
} _else {
Mark[vertex]=VISITED;
std::cout<<"v "<< std::endl;
i32 w=0;
i32 i=0;
////////////////////////// finding first neighbor
_for(i=0, i _if(Matrix(vertex,i) != 0) {
_break;
}_end_if;
}_end_for;

//////////////////////////// DFS algorithm
_for(w=i,w#if _CALL
call(DFS)(w, numVertex);
#else
DFS(w, numVertex);
#endif
_for(w=w+1, w _if(Matrix(vertex,w) != 0) {
_break;
}_end_if;
}_end_for;
}_end_for;
} _end_if
}

And here is the main:

int main()
{
i32 start=0;
i32 n=8;
Matrix = dense::dense(VERTICES,VERTICES);
Mark = dense::dense(VERTICES);
_for(i32 i=0,i {
Mark[i]=0;
_for(i32 j=0,j {
Matrix(i,j)=0;
}_end_for;
}_end_for;
//call(Matrix_Fill)(Matrix,n);
#if _CALL
call(DFS)(0, VERTICES);
#else
DFS(0, VERTICES);
#endif
return 0;
}

2 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
Zhang Z (Intel)的头像

The arbb::call() operator is always necessary in the main. Without it, the runtime won't create a closure for the function DFS, and DFS is executed just like a regular C++ function. The recursive call inside DFS do not need the arbb::call() operator, but it is not an error to use it either. A direct call (without using arbb::call() operator) is always inlined. A call via arbb::call() may or may not be inlined.

Please refer to the Function Invocation chapter in the Intel ArBB API reference manual to learn how to use arbb::call().

A bigger problem with this code is that it cannot be parallelized. The code expresses a sequential algorithm. It does not use any ArBB parallel constructs to express parallelism. Even we can get it run, it will run sequentially and much slower than equivalent C/C++ code because of the overhead introduced by the ArBB types and constructs. You may want to review the ArBB Code Tips webinar we did recently to learn more about expressing parallelism in ArBB.

登陆并发表评论。