Skip to content
Snippets Groups Projects
Commit f0cac967 authored by Alam's avatar Alam
Browse files

Wahahaa

parent 20f275bd
No related merge requests found
...@@ -2,7 +2,10 @@ CC = gcc ...@@ -2,7 +2,10 @@ CC = gcc
flags = -g -Wall -o flags = -g -Wall -o
output = main output = main
file = omp_hello.c file = omp_hello.c
opemp_directive = -fopenmp openmp_directive = -fopenmp
seq_file = dijsktra-sequential.c
seq_out = seq_main
make : make :
$(CC) $(flags) $(output) $(file) $(opemp_directive) $(CC) $(flags) $(output) $(file) $(openmp_directive)
$(CC) $(flags) $(seq_out) $(seq_file) $(openmp_directive)
...@@ -16,19 +16,7 @@ int minDistance(int V, int dist[], bool sptSet[]) { ...@@ -16,19 +16,7 @@ int minDistance(int V, int dist[], bool sptSet[]) {
return min_index; return min_index;
} }
int printSolution(FILE *file, int V, int dist[]) { int dijkstra(int V, int graph[V * V], int dist[V], int src) {
for (int i = 0; i < V; i++) {
fprintf(file,"%d",dist[i]);
if(i<(V-1)){
fprintf(file," ");
}
}
fprintf(file,"\n");
}
void dijkstra(int V, int graph[V * V], int dist[V], int src) {
bool sptSet[V]; bool sptSet[V];
for (int i = 0; i < V; i++) for (int i = 0; i < V; i++)
...@@ -102,7 +90,6 @@ int main(int argc, char **argv) { ...@@ -102,7 +90,6 @@ int main(int argc, char **argv) {
int* globalDist = malloc(N * sizeof(int)); int* globalDist = malloc(N * sizeof(int));
dijkstra(N, graph, globalDist, i); dijkstra(N, graph, globalDist, i);
printSolution(output_file,N, globalDist);
free(globalDist); free(globalDist);
} }
//end //end
......
File deleted
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <omp.h> #include <omp.h>
void printGraph(int n_nodes, int* graph); void printGraph(int n_nodes, int* graph);
void initGraph(int* graph, int n_nodes){ void initGraph(int* graph, int n_nodes){
for(int i = 0; i < n_nodes; i++){ for(int i = 0; i < n_nodes; i++){
...@@ -15,14 +12,12 @@ void initGraph(int* graph, int n_nodes){ ...@@ -15,14 +12,12 @@ void initGraph(int* graph, int n_nodes){
} else { } else {
graph[i*n_nodes + j] = 0; graph[i*n_nodes + j] = 0;
} }
} }
} }
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int seed = 13517096; int seed = 13517096;
int* graph; int* graph;
int* minimumLocalDist; int* minimumLocalDist;
...@@ -33,7 +28,7 @@ int main(int argc, char *argv[]) { ...@@ -33,7 +28,7 @@ int main(int argc, char *argv[]) {
int thrMinimum; int thrMinimum;
char *visited; char *visited;
clock_t start,end; double start,end;
srand(seed); srand(seed);
...@@ -70,7 +65,7 @@ int main(int argc, char *argv[]) { ...@@ -70,7 +65,7 @@ int main(int argc, char *argv[]) {
// printGraph(n_nodes, graph); // printGraph(n_nodes, graph);
start = clock(); start = omp_get_wtime();
for(int sourceNode = 0 ; sourceNode < n_nodes ; sourceNode++){ for(int sourceNode = 0 ; sourceNode < n_nodes ; sourceNode++){
...@@ -119,6 +114,7 @@ int main(int argc, char *argv[]) { ...@@ -119,6 +114,7 @@ int main(int argc, char *argv[]) {
thrMinimum = 0; thrMinimum = 0;
//reduce , find minimum node //reduce , find minimum node
#pragma omp for
for (int thr = 1; thr < thread_count ; thr++){ for (int thr = 1; thr < thread_count ; thr++){
// thr is infinity // thr is infinity
if(minimumLocalDist[thr]==-1) continue; if(minimumLocalDist[thr]==-1) continue;
...@@ -146,12 +142,11 @@ int main(int argc, char *argv[]) { ...@@ -146,12 +142,11 @@ int main(int argc, char *argv[]) {
} }
end = clock(); end = omp_get_wtime();
double time_taken = (double) (end-start) / CLOCKS_PER_SEC; double time_taken = end-start;
printf("Time elapsed : %f\n", time_taken); printf("Time elapsed : %f\n", time_taken);
free(visited); free(visited);
free(minDist); free(minDist);
free(graph); free(graph);
......
seq_main 0 → 100755
File added
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment