/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to dict_hw/src/hw_sched.c

  • Committer: Suren A. Chilingaryan
  • Date: 2010-08-09 00:10:31 UTC
  • Revision ID: csa@dside.dyndns.org-20100809001031-59vi0m04osiimrvz
Timing measurements are fixed, openmp support to accelerate image reduction

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define _GNU_SOURCE
 
2
 
1
3
#include <stdio.h>
2
4
#include <stdlib.h>
3
5
#include <string.h>
4
6
 
 
7
#ifdef HW_HAVE_SCHED_HEADERS
 
8
# include <sys/types.h>
 
9
# include <unistd.h>
 
10
# include <sched.h>
 
11
#endif /* HW_HAVE_SCHED_HEADERS */
 
12
 
5
13
#include "normxcorr_hw_msg.h"
6
14
#include "hw_sched.h"
7
15
 
37
45
 
38
46
static int hw_sched_initialized = 0;
39
47
 
 
48
 
 
49
int hw_sched_get_cpu_count() {
 
50
#ifdef HW_HAVE_SCHED_HEADERS
 
51
    int err;
 
52
 
 
53
    int cpu_count;
 
54
    cpu_set_t mask;
 
55
 
 
56
    err = sched_getaffinity(getpid(), sizeof(mask), &mask);
 
57
    if (err) return 1;
 
58
 
 
59
# ifdef CPU_COUNT
 
60
    cpu_count = CPU_COUNT(&mask);
 
61
# else
 
62
#  ifndef CPU_SETSIZE
 
63
#    define CPU_SET_SIZE 64
 
64
#  endif /* CPU_SETSIZE */
 
65
    for (cpu_count = 0; cpu_count < CPU_SETSIZE; cpu_count++) {
 
66
        if (!CPU_ISSET(cpu_count, &mask)) break;
 
67
    }
 
68
# endif
 
69
 
 
70
    if (!cpu_count) cpu_count = 1;
 
71
    return cpu_count;    
 
72
#else /* HW_HAVE_SCHED_HEADERS */
 
73
    return 1;
 
74
#endif /* HW_HAVE_SCHED_HEADERS */
 
75
}
 
76
 
40
77
int hw_sched_init() {
41
78
    if (!hw_sched_initialized) {
42
79
        g_thread_init(NULL);
 
80
 
 
81
#ifdef HAVE_OPENMP
 
82
        int cpus = hw_sched_get_cpu_count() / 2;
 
83
        omp_set_num_threads(cpus?cpus:1);
 
84
#endif /* HAVE_OPENMP */
 
85
 
43
86
        hw_sched_initialized = 1;
44
87
    }
45
88
 
47
90
}
48
91
 
49
92
 
50
 
 
51
93
HWSched hw_sched_create(int ppu_count) {
52
94
    int i;
53
95
    int err = 0;