Skip to content
Snippets Groups Projects
Commit cafa9b60 authored by Saskia Imani's avatar Saskia Imani
Browse files

Input-based block and thread numbers

parent a93b69eb
No related merge requests found
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <omp.h>
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
...@@ -17,17 +16,16 @@ long *initialize_result(int n); ...@@ -17,17 +16,16 @@ long *initialize_result(int n);
void write_output(long matrix[], int n_row, int n_col, double time); void write_output(long matrix[], int n_row, int n_col, double time);
__global__ __global__
void dijkstra(int n, long matrix[], long result[]) { void dijkstra(int n, int sub_n, long matrix[], long result[]) {
long *connected; // Array of 'boolean' on whether vertice [i] is connected to source long *connected; // Array of 'boolean' on whether vertice [i] is connected to source
long *distance; // Distance of vertice [i] from source long *distance; // Distance of vertice [i] from source
int my_rank = blockIdx.x * blockDim.x + threadIdx.x; int my_rank = blockIdx.x * blockDim.x + threadIdx.x;
int stride = blockDim.x * gridDim.x;
connected = (long*)malloc(n * sizeof(long)); connected = (long*)malloc(n * sizeof(long));
distance = (long *)malloc(n * sizeof(long)); distance = (long *)malloc(n * sizeof(long));
for (int SOURCE_V = my_rank; SOURCE_V < n; SOURCE_V += stride) { for (int SOURCE_V = my_rank * sub_n; SOURCE_V < (my_rank + 1) * sub_n; SOURCE_V++) {
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
if (i == SOURCE_V) { if (i == SOURCE_V) {
connected[i] = TRUE; connected[i] = TRUE;
...@@ -87,6 +85,8 @@ int main (int argc, char **argv) { ...@@ -87,6 +85,8 @@ int main (int argc, char **argv) {
/* Read number of vertices */ /* Read number of vertices */
printf("Number of vertices (n): "); scanf("%d", &n); printf("Number of vertices (n): "); scanf("%d", &n);
printf("Number of blocks : "); scanf("%d", &num_blocks);
printf("Number of threads : "); scanf("%d", &num_thrads);
matrix = initialize_matrix(13517142, n); matrix = initialize_matrix(13517142, n);
printf("\nGenerated %d * %d matrix.\n", n, n); printf("\nGenerated %d * %d matrix.\n", n, n);
...@@ -94,8 +94,10 @@ int main (int argc, char **argv) { ...@@ -94,8 +94,10 @@ int main (int argc, char **argv) {
result = initialize_result(n); result = initialize_result(n);
start = clock(); start = clock();
int sub_n = n / (num_blocks * num_threads);
dijkstra<<<n,1>>>(n, matrix, result); dijkstra<<<num_blocks,num_threads>>>(n, sub_n, matrix, result);
cudaDeviceSynchronize(); cudaDeviceSynchronize();
......
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