Skip to content
Snippets Groups Projects
Commit ce48d222 authored by Ayoub Boughourfi's avatar Ayoub Boughourfi
Browse files

Upload New File

parent 2bf19b76
No related branches found
No related tags found
No related merge requests found
#include "dijkstra_cuda.cuh"
#include "cuda_helpers.cuh"
#include <stdio.h>
#include <float.h>
// Einfacher CUDA-Kernel für Dijkstra
__global__ void dijkstra_kernel(double* graph, double* dist, bool* visited, int numVertices, int u) {
int v = blockIdx.x * blockDim.x + threadIdx.x;
if (v < numVertices) {
if (!visited[v] && graph[u * numVertices + v] > 0 &&
dist[u] != DBL_MAX &&
dist[u] + graph[u * numVertices + v] < dist[v]) {
dist[v] = dist[u] + graph[u * numVertices + v];
}
}
}
// Vereinfachte Dijkstra-Implementierung für CUDA
std::vector<double> DijkstraCUDA::run(const std::vector<std::vector<double>>& graph, int src) {
int numVertices = graph.size();
// Ergebnisvektor für Distanzen
std::vector<double> result(numVertices, DBL_MAX);
result[src] = 0.0;
// Einfache sequentielle Implementierung, die bei Bedarf später
// durch eine echte CUDA-Implementierung ersetzt werden kann
std::vector<bool> visited(numVertices, false);
for (int i = 0; i < numVertices; i++) {
// Finde Knoten mit minimaler Distanz
double minDist = DBL_MAX;
int u = -1;
for (int v = 0; v < numVertices; v++) {
if (!visited[v] && result[v] < minDist) {
minDist = result[v];
u = v;
}
}
if (u == -1) break;
visited[u] = true;
// Einfache Nachbarschaftsverarbeitung (keine echte CUDA-Nutzung)
for (int v = 0; v < numVertices; v++) {
if (!visited[v] && graph[u][v] > 0 &&
result[u] != DBL_MAX &&
result[u] + graph[u][v] < result[v]) {
result[v] = result[u] + graph[u][v];
}
}
}
return result;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment