diff --git a/dn3/server b/dn3/server index 33c4ffe..7572992 100755 Binary files a/dn3/server and b/dn3/server differ diff --git a/dn3/server.c b/dn3/server.c index 023d8cc..e57f9fd 100644 --- a/dn3/server.c +++ b/dn3/server.c @@ -5,8 +5,8 @@ #include #include -#define N_THREADS 9 -#define N_DIMENSIONS 200000000 +#define N_THREADS 130 +#define N_DIMENSIONS 2000000 pthread_barrier_t b; long *p_s; @@ -14,10 +14,6 @@ long *q_s; double res[N_THREADS]; int active_threads[N_THREADS]; -// odd number of threads lock -pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; -pthread_spinlock_t slock; - void setup() { p_s = (long *) malloc(N_DIMENSIONS * sizeof(long)); q_s = (long *) malloc(N_DIMENSIONS * sizeof(long)); @@ -44,7 +40,8 @@ void *calculate(void* arg) { pthread_barrier_wait( &b ); int n_threads = N_THREADS; - + + // handle the odd number of threads! if(n_threads % 2 == 1) { if ( *myrank == N_THREADS - 1) { res[*myrank - 1] += res[*myrank]; @@ -54,15 +51,17 @@ void *calculate(void* arg) { } pthread_barrier_wait( &b ); - + + // Do not split threads if there is a single thread if (n_threads != 1) { - n_threads = N_THREADS / 2; if (*myrank >= n_threads) { active_threads[*myrank] = -1; } } + + // Do a tree based sumation while(1) { if(active_threads[*myrank] != -1) { res[*myrank] = res[*myrank * 2] + res[*myrank *2 + 1]; @@ -90,14 +89,8 @@ int main() { double dt = omp_get_wtime(); // start timing int p[N_THREADS]; - //if(N_THREADS %2 != 0 && N_THREADS >= 2) { - // printf("Number of threads must be even!\n"); - // return 1; - //} - // // barrier & lock pthread_barrier_init( &b, NULL, N_THREADS ); - pthread_spin_init(&slock, PTHREAD_PROCESS_PRIVATE); for(int i = 0; i < N_THREADS; i++ ) { p[i] = i; @@ -107,14 +100,15 @@ int main() { for(int i=0; i