-3
的任何实例是一些代码,在C/CUDA正在做,但出于某种原因,一些错误似乎是被编译停止该程序并运行。不太确定如何解决这些错误,尝试更改演员表,以及多次校对整个代码。没有很大的用C编码,它似乎并不像这个错误是问题是通过网上搜索的内容非常具体。任何见解或帮助将不胜感激。所以下面重载函数错误
#include <cstdlib>
#include <stdio.h>
#include <limits.h>
using namespace std;
const int NUMTHREADS = 1024;
// Number of vertices in the graph
#define V 9
// A utility function to find the vertex with minimum distance value, from
// the set of vertices not yet included in shortest path tree
int minDistance(int dist[], bool sptSet[]) {
// Initialize min value
int min = INT_MAX, min_index;
for (int v = 0; v < V; v++)
if (sptSet[v] == false && dist[v] <= min)
min = dist[v], min_index = v;
return min_index;
}
// A utility function to print the constructed distance array
int printSolution(int dist[], int n) {
printf("Vertex Distance from Source\n");
for (int i = 0; i < V; i++)
printf("%d \t\t %d\n", i, dist[i]);
}//end of method
// Funtion that implements Dijkstra's single source shortest path algorithm
// for a graph represented using adjacency matrix representation
__global__ void updateDistance(bool* sptSet[],int* graph[],int* dist[],int u,int V){
Int i = threadIdx.x
if(i<V){
if((!sptSet[i] && *graph[u*V+i] && dist[u] != INT_MAX && *dist[u]+graph[u*V+i] < *dist[i]))
*dist[i] = *dist[u] + *graph[u*V+i];
}
}//end of method
long* generateAdjMatrix(int count){
long* randoMatrix = (long*)malloc(count*count*sizeof(long));
int i,j;
srand(time(NULL));
for(i=0;i<count;i++){
for(j=0;j<count;j++){
if(i != j){
Long randomResult = rand()%2;
randoMatrix[(i*count)+j] = randomResult;
randoMatrix[(j*count)+i] = randomResult;
}
}
}
Return randoMatrix;
}//end of method
// driver program to test above function
int main() {
//gpu
int *d_dist[V];
int *d_graph[V];
bool *d_sptSet[V];
int src = 0;
long* matrix;
int *dist[V]; // The output array. dist[i] will hold the shortest
// distance from src to i
bool* sptSet = (bool)malloc(V*sizeof(bool));
int* graph = (int *)malloc(V*sizeof(int));
int* dist = (int *)malloc(V*sizeof(int));
Matrix = generateAdjMatrix(V);
// Initialize all distances as INFINITE and stpSet[] as false
for (int i = 0; i < V; i++)
dist[i] = INT_MAX, sptSet[i] = false;
// Distance of source vertex from itself is always 0
dist[src] = 0;
//allocate GPU variables in memory
cudaMalloc(&d_sptSet,(V*sizeof(bool)));
cudaMalloc(&d_dist,(V*sizeof(int)));
cudaMalloc(&d_graph,(V*sizeof(int)));
// Find shortest path for all vertices
for (int count = 0; count < V-1; count++) {
// Pick the minimum distance vertex from the set of vertices not
// yet processed. u is always equal to src in first iteration.
int u = minDistance(dist, sptSet);
// Mark the picked vertex as processed
sptSet[u] = true;
//after updating distance, copy the updates to GPU
cudaMemcpy(d_sptSet,sptSet,V*sizeof(bool),cudaMemcpyHostToDevice);
cudaMemcpy(d_dist,dist,V*sizeof(int),cudaMemcpyHostToDevice);
cudaMemcpy(d_graph,graph,V*sizeof(int),cudaMemcpyHostToDevice);
//call updatedistance
updateDistance<<<V,NUMTHREADS>>>(d_sptSet,d_graph,d_dist,u,V);
cudaMemcpy(dist,d_dist,V*sizeof(int),cudaMemcpyDeviceToHost);
cudaMemcpy(sptSet,d_sptSet,V*sizeof(int),cudaMemcpyDeviceToHost);
}//end of for
// print the constructed distance array
printSolution(dist, V);
return 0;
}//end of main
我得到的错误是:
符合-expected一 “)” 39
重载函数 “cudaMalloc” 的 - 没有实例的参数匹配(119线) (同样为线120和121)
-from线119-121,它也说 “参数的类型有:INT()[图9中,无符号长”
严重的是,[SO]不是免费错误固定服务。请不要把它当作一个。如果不能发现在线路37'中INT I = threadIdx.x'两个错误,则需要修改某些基本的C++的参考材料。我已经投票结束了这一点。 – talonmies
同意。尝试修复这些基本的语法错误并回来。 –