Hi everybody.
I want to write breadth first search with openacc.
Everything is right to me but this line
#pragma acc update host(stop[0])
#pragma acc update device(curLevel[0])
dosen’t work , update cluase dosen’t work!!!
anyone can help me!?!
//Global include and variables
/*Openacc test */
#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <queue>
#include <set>
#include <string>
#include <omp.h>
#include <vector>
#include <map>
using namespace std;
int main()
{
cout << "\n **** Start prog Test functionality of OPENACC *** \n" << endl;
// //define variables
int * restrict graphIndex;
int * restrict data;
int * restrict dist;
int * restrict parent;
int * restrict curIndex;
bool * restrict vis;
bool * restrict mask;
int * restrict curLevel;
bool * restrict stop;
int sizeOne = 1;
int noOfNodes, noOfEdges, numOfNeighbour;
// FILE *in_file = fopen("test__Meta_undirected.txt", "r");
FILE *in_file = fopen("fMeta.txt", "r");
fscanf(in_file, "%d %d", &noOfNodes, &noOfEdges);
// //initialize variables
data = new int[noOfEdges*2];
dist = new int[noOfNodes];
parent = new int[noOfNodes];
curIndex = new int[noOfNodes];
vis = new bool[noOfNodes];
mask = new bool[noOfNodes];
int src, dest;
graphIndex = new int[noOfNodes + sizeOne];
curLevel = new int[sizeOne];
stop = new bool[sizeOne];
graphIndex[0] = 0;
curIndex[0] = 0;
for (int i = 1 ; i <=noOfNodes; i++)
{
fscanf(in_file, "%d ", &numOfNeighbour);
graphIndex[i] = numOfNeighbour + graphIndex[i-1];
cout << i << " : ";
curIndex[i] = 0;
cout << graphIndex[i] << endl;
}
fclose(in_file);
//FILE *data_file = fopen("test__data__undirected.txt", "r");
FILE *data_file = fopen("fData.txt", "r");
fscanf(data_file , "%d %d", &noOfNodes, &noOfEdges);
int index;
for (int i = 0; i < noOfEdges; i++)
{
fscanf(data_file, "%d %d", &src, &dest);
index = graphIndex[src] + curIndex[src];
cout << endl << i << ": index - " << index << " : " << src << " -> " << dest << endl;
data[index] = dest;
curIndex[src]++;
index = graphIndex[dest] + curIndex[dest];
cout << endl << i << " index - " << index << " : " << dest << " -> " << src << endl;
data[index] = src;
curIndex[dest]++;
//cout << endl << i << ":" << src << " , " << dest << endl;
}
for (int i = 0; i < noOfNodes; i++){
dist[i] = 0;
parent[i] = -1;
vis[i] = false;
mask[i] = false;
curIndex[i] = 0;
}
for (int i = 0; i < noOfEdges * 2; i++)
{
cout << endl << "index: " << i << "data: " << data[i];
}
do{
cout << endl << "please insert source node :" ;
cin >> src;
if (src == -1) break;
for (int j = graphIndex[src]; j < graphIndex[src + 1]; j++)
{
cout << data[j] << " ";
}
} while (1);
cout << endl << "please insert source node :" ;
cin >> src;
for (int j = graphIndex[src]; j < graphIndex[src + 1]; j++)
{
mask[data[j]] = true;
vis[data[j]] = true;//go to true
parent[data[j]] = src;
curIndex[data[j]] = 1;
dist[data[j]] = 1;
cout << endl << "data: " << data[j] ;
}
int j;
curLevel[0] = 1;
stop[0] = false;;
// //openACC Try
// //start data region
int counter = 0;
#pragma acc data region copyin(data[0:noOfEdges], curLevel[0:1] , stop[0:1] , curIndex[0:noOfNodes] , mask[0:noOfNodes] , vis[0:noOfNodes] , graphIndex[0:noOfNodes]) , copy( dist[0:noOfNodes] , parent[0:noOfNodes] )
{
//
do{
counter++;
stop[0] = false;
#pragma acc update device(stop[0])
#pragma acc update device(curLevel[0])
#pragma acc kernels
{
#pragma acc for independent
for (int i = 0; i < noOfNodes; i++)
{
if (mask[i]==true && curIndex[i] == curLevel[0])
{
#pragma acc for independent
for ( j = graphIndex[i] ; j < graphIndex[i + 1]; j++)
{
if (vis[data[j]] == false) {
vis[data[j]] = true;//go to true
mask[data[j]] = true;
parent[data[j]] = i;
stop[0] = true;
curIndex[data[j]] = curLevel[0] + 1;
dist[data[j]] = dist[i] + 1;
}
}
}
}
}//end acc kenels
curLevel[0] = curLevel[0] + 1;
#if defined(_OPENACC)
#pragma acc update host(stop[0])
#pragma acc update device(curLevel[0])
#endif
cout << endl << stop[0] << "----------------------" << curLevel[0] << "----------------------";
//
} while (counter==8);
//while (stop[0]);
} //end data region
for (int i = 0; i < noOfNodes; i++)
{
cout << endl << i << ": " << dist[i] << " - " << parent[i];
}
//
//
return 0;
}