2016-04-23 15 views
-3

Also unten ist etwas Code, der in C/CUDA getan wird, aber aus irgendeinem Grund scheinen einige Fehler zu verhindern, dass dieses Programm kompiliert und ausgeführt wird. Ich bin mir nicht sicher, wie ich diese Fehler beheben kann, habe versucht, die Umwandlungen zu ändern und den gesamten Code mehrmals zu lesen. Nicht so toll beim Codieren in C, und es scheint nicht so, als ob dieser Fehler durch die Online-Suche sehr spezifisch ist. Jede Einsicht oder Hilfe wäre willkommen.Keine Instanz des überladenen Funktionsfehlers

#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 

Die Fehler Ich erhalte sind:

-Erwartete a ")" in Zeile 39

-kein Instanz überladene Funktion "cudaMalloc" stimmt mit dem Argument (Linie 119) (gleiche gilt für die Leitung 120 und 121)

-von Linie 119-121 es sagt auch "Argument-Typen sind: int() [9, unsigned long"

+3

Im Ernst, [SO] ist kein kostenloser Fehlerkorrekturdienst. Bitte behandle es nicht wie eins. Wenn Sie die zwei Fehler in "Int i = threadIdx.x" in Zeile 37 nicht finden können, müssen Sie einige grundlegende C++ - Referenzmaterialien überarbeiten. Ich habe dafür gestimmt, dies zu beenden. – talonmies

+0

Einverstanden. Versuchen Sie, diese grundlegenden Syntaxfehler zu beheben, und kommen Sie zurück. –

Antwort

0

mit Talonmies und Regis vereinbaren.

Darüber hinaus haben Sie andere Typ Fehler Zeile 40, und Ihre Arbeit Verteilung von updateDistance mit mehreren Blöcken wird nicht unbedingt gut, da Sie alle Blöcke arbeiten an denselben Daten haben.

Schließlich weisen Sie nicht genügend Speicher für Ihre Puffer zu (V Einträge, in diesem Fall 9 Zugriff auf alle 1024 Threads an den verbundenen Orten).

Ich glaube, Sie möchten vielleicht einen tieferen Blick in die Programmieranleitung und vielleicht eine gründliche Anleitung.

Verwandte Themen