| 60 | } |
| 61 | |
| 62 | bool a11c(void) |
| 63 | { bool ok = true; |
| 64 | |
| 65 | // Test setup |
| 66 | size_t i, j, n_total = 10; |
| 67 | float *a = new float[n_total]; |
| 68 | float *b = new float[n_total]; |
| 69 | for(i = 0; i < n_total; i++) |
| 70 | a[i] = float(i); |
| 71 | |
| 72 | // number of threads |
| 73 | size_t number_threads = NUMBER_THREADS; |
| 74 | |
| 75 | // set of workers |
| 76 | worker_t worker[NUMBER_THREADS]; |
| 77 | // threads for each worker |
| 78 | boost::thread* bthread[NUMBER_THREADS]; |
| 79 | |
| 80 | // Break the work up into sub work for each thread |
| 81 | size_t n = n_total / number_threads; |
| 82 | size_t n_tmp = n; |
| 83 | float* a_tmp = a; |
| 84 | float* b_tmp = b; |
| 85 | worker[0].setup(n_tmp, a_tmp, b_tmp); |
| 86 | for(j = 1; j < number_threads; j++) |
| 87 | { n_tmp = n + 1; |
| 88 | a_tmp = a_tmp + n - 1; |
| 89 | b_tmp = b_tmp + n - 1; |
| 90 | if( j == (number_threads - 1) ) |
| 91 | n_tmp = n_total - j * n + 1; |
| 92 | |
| 93 | worker[j].setup(n_tmp, a_tmp, b_tmp); |
| 94 | |
| 95 | // create this thread |
| 96 | bthread[j] = new boost::thread(worker[j]); |
| 97 | } |
| 98 | |
| 99 | // do this threads portion of the work |
| 100 | worker[0](); |
| 101 | |
| 102 | // wait for other threads to finish |
| 103 | for(j = 1; j < number_threads; j++) |
| 104 | { bthread[j]->join(); |
| 105 | delete bthread[j]; |
| 106 | } |
| 107 | |
| 108 | // check the result |
| 109 | float eps = 100.f * std::numeric_limits<float>::epsilon(); |
| 110 | for(i = 1; i < n ; i++) |
| 111 | ok &= std::fabs( (2. * b[i] - a[i] - a[i-1]) / b[i] ) <= eps; |
| 112 | |
| 113 | delete [] a; |
| 114 | delete [] b; |
| 115 | |
| 116 | return ok; |
| 117 | } |
| 118 | // END C++ |