Changeset 5704 in /cluster/svnroot


Ignore:
Timestamp:
May 23, 2016 11:42:05 PM (5 years ago)
Author:
skylar
Message:

initialize thread count in parallel pragma

Location:
bccd-ng/bw-institute/2016/day06/matmul
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • bccd-ng/bw-institute/2016/day06/matmul/matmul.c

    r5702 r5704  
    3838// Return an array of random number seeds. Epoch time is used as a base, incremented by thread ID
    3939unsigned int *init_random_seeds() {
    40     unsigned int i,*seeds;
     40    unsigned int i,*seeds,num_threads;
    4141    time_t t = time(NULL);
     42#ifdef _OPENMP
     43#pragma omp parallel
     44    {
     45        num_threads = omp_get_num_threads();
     46    }
     47#else
     48    num_threads = 1;
     49#endif
    4250
    43     seeds = safe_malloc_unsigned_int(NUM_THREADS,"Allocating random seed array");
     51    seeds = safe_malloc_unsigned_int(num_threads,"Allocating random seed array");
    4452
    4553#ifdef DEBUG
    46     fprintf(stderr,"Setting seed for %d threads\n",NUM_THREADS);
     54    fprintf(stderr,"Setting seed for %u threads\n",num_threads);
    4755#endif
    48     for(i=0;i<NUM_THREADS;i++) {
     56    for(i=0;i<num_threads;i++) {
    4957        // Guarantee different starting seeds for random numbers in each thread
    5058        seeds[i] = t+i;
  • bccd-ng/bw-institute/2016/day06/matmul/matmul.h

    r5701 r5704  
    1616#include <omp.h>
    1717
    18 #ifdef _OPENMP
    19 #define NUM_THREADS omp_get_num_threads()
    20 #else
    21 #define NUM_THREADS 1
     18#ifndef _OPENMP
    2219#include <sys/time.h> // gettimeofday(2)
    2320#endif
Note: See TracChangeset for help on using the changeset viewer.