diff --git a/omp_hello.c b/omp_hello.c index 34d6b946b1151e1843f09d63ead555d393d772fd..8d3567472777029d07f23811b7fde4954d0219f3 100644 --- a/omp_hello.c +++ b/omp_hello.c @@ -4,10 +4,48 @@ void Hello(void); /* Thread function */ +void printGraph(int n_nodes, int* graph); + + +void initGraph(int* graph, int n_nodes){ + + for(int i = 0; i < n_nodes; i++){ + for(int j = 0; j <= i; j++){ + + if(i == j){ + + graph[i*n_nodes+j] = 0; + + } else { + + graph[i*n_nodes + j] = rand()%1000; + graph[j*n_nodes + i] = graph[i*n_nodes + j]; + + } + } + } +} int main(int argc, char *argv[]) { - int thread_count = strtol(argv[1], NULL, 10); - + + + int seed = 13517096; + int* graph; + + srand(seed); + + int thread_count = strtol(argv[1], NULL, 10); + int n_nodes = strtol(argv[2],NULL,10); + + // Graph initialization + graph = malloc(n_nodes*n_nodes*sizeof(int)); + initGraph(graph,n_nodes); + + + + printGraph(n_nodes,graph); + + #pragma omp parallel num_threads(thread_count) Hello(); @@ -20,3 +58,13 @@ void Hello(void) { printf("Hello from thread %d of %d\n", my_rank, thread_count); } + + +void printGraph(int n_nodes, int* graph) { + for (int i = 0; i < n_nodes; i++) { + for(int j= 0 ; j < n_nodes; j++){ + printf("%d ", graph[i*n_nodes + j]); + } + printf("\n"); + } +}