OpenMP set_num_threads() is not working

Besides calling omp_get_num_threads() outside of the parallel region in your case, calling omp_set_num_threads() still doesn’t guarantee that the OpenMP runtime will use exactly the specified number of threads. omp_set_num_threads() is used to override the value of the environment variable OMP_NUM_THREADS and they both control the upper limit of the size of the thread team that … Read more

Fastest way to clamp a real (fixed/floating point) value?

Both GCC and clang generate beautiful assembly for the following simple, straightforward, portable code: double clamp(double d, double min, double max) { const double t = d < min ? min : d; return t > max ? max : t; } > gcc -O3 -march=native -Wall -Wextra -Wc++-compat -S -fverbose-asm clamp_ternary_operator.c GCC-generated assembly: maxsd … Read more

JavaScript numbers to Words

JavaScript is parsing the group of 3 numbers as an octal number when there’s a leading zero digit. When the group of three digits is all zeros, the result is the same whether the base is octal or decimal. But when you give JavaScript ‘009’ (or ‘008’), that’s an invalid octal number, so you get … Read more

Rounding up to the second decimal place [duplicate]

Check out http://www.php.net/manual/en/function.round.php <?php echo round(3.6451895227869, 2); ?> EDIT Try using this custom function http://www.php.net/manual/en/function.round.php#102641 <?php function round_up ( $value, $precision ) { $pow = pow ( 10, $precision ); return ( ceil ( $pow * $value ) + ceil ( $pow * $value – ceil ( $pow * $value ) ) ) / $pow; … Read more