/** * @brief * cmp_placement_sets - sort placement sets by * total cpus * total memory * free cpus * free memory * * @param[in] v1 - node partition 1 * @param[in] v2 - node partition 2 * * @return int * @retval -1 : if v1 < v2 * @retval 0 : if v1 == v2 * @retval 1 : if v1 > v2 */ int cmp_placement_sets(const void *v1, const void *v2) { node_partition *np1, *np2; schd_resource *ncpus1, *ncpus2; schd_resource *mem1, *mem2; int rc = 0; if (v1 == NULL && v2 == NULL) return 0; if (v1 == NULL && v2 != NULL) return -1; if (v1 != NULL && v2 == NULL) return 1; np1 = *((node_partition **) v1); np2 = *((node_partition **) v2); ncpus1 = find_resource(np1->res, getallres(RES_NCPUS)); ncpus2 = find_resource(np2->res, getallres(RES_NCPUS)); if (ncpus1 != NULL && ncpus2 != NULL) rc = cmpres(ncpus1->avail, ncpus2->avail); if (!rc) { mem1 = find_resource(np1->res, getallres(RES_MEM)); mem2 = find_resource(np2->res, getallres(RES_MEM)); if (mem1 != NULL && mem2 != NULL) rc = cmpres(mem1->avail, mem2->avail); } if (!rc) { if (ncpus1 != NULL && ncpus2 != NULL) rc = cmpres(dynamic_avail(ncpus1), dynamic_avail(ncpus2)); } if (!rc) { if (mem1 != NULL && mem2 != NULL) rc = cmpres(dynamic_avail(mem1), dynamic_avail(mem2)); } return rc; }
/* With pow.c r5497, the following test fails on a 64-bit Linux machine * due to a double-rounding problem when rescaling the result: * Error with underflow_up2 and extended exponent range * x = 7.fffffffffffffff0@-1, * y = 4611686018427387904, MPFR_RNDN * Expected 1.0000000000000000@-1152921504606846976, inex = 1, flags = 9 * Got 0, inex = -1, flags = 9 * With pow_ui.c r5423, the following test fails on a 64-bit Linux machine * as underflows and overflows are not handled correctly (the approximation * error is ignored): * Error with mpfr_pow_ui, flags cleared * x = 7.fffffffffffffff0@-1, * y = 4611686018427387904, MPFR_RNDN * Expected 1.0000000000000000@-1152921504606846976, inex = 1, flags = 9 * Got 0, inex = -1, flags = 9 */ static void underflow_up2 (void) { mpfr_t x, y, z, z0, eps; mpfr_exp_t n; int inex; int rnd; n = 1 - mpfr_get_emin (); MPFR_ASSERTN (n > 1); if (n > ULONG_MAX) return; mpfr_init2 (eps, 2); mpfr_set_ui_2exp (eps, 1, -1, MPFR_RNDN); /* 1/2 */ mpfr_div_ui (eps, eps, n, MPFR_RNDZ); /* 1/(2n) rounded toward zero */ mpfr_init2 (x, sizeof (unsigned long) * CHAR_BIT + 1); inex = mpfr_ui_sub (x, 1, eps, MPFR_RNDN); MPFR_ASSERTN (inex == 0); /* since n < 2^(size_of_long_in_bits) */ inex = mpfr_div_2ui (x, x, 1, MPFR_RNDN); /* 1/2 - eps/2 exactly */ MPFR_ASSERTN (inex == 0); mpfr_init2 (y, sizeof (unsigned long) * CHAR_BIT); inex = mpfr_set_ui (y, n, MPFR_RNDN); MPFR_ASSERTN (inex == 0); /* 0 < eps < 1 / (2n), thus (1 - eps)^n > 1/2, and 1/2 (1/2)^n < (1/2 - eps/2)^n < (1/2)^n. */ mpfr_inits2 (64, z, z0, (mpfr_ptr) 0); RND_LOOP (rnd) { unsigned int ufinex = MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT; int expected_inex; char sy[256]; mpfr_set_ui (z0, 0, MPFR_RNDN); expected_inex = rnd == MPFR_RNDN || rnd == MPFR_RNDU || rnd == MPFR_RNDA ? (mpfr_nextabove (z0), 1) : -1; sprintf (sy, "%lu", (unsigned long) n); mpfr_clear_flags (); inex = mpfr_pow (z, x, y, (mpfr_rnd_t) rnd); cmpres (0, x, sy, (mpfr_rnd_t) rnd, z0, expected_inex, z, inex, ufinex, "underflow_up2", "mpfr_pow"); test_others (NULL, sy, (mpfr_rnd_t) rnd, x, y, z, inex, ufinex, "underflow_up2"); } mpfr_clears (x, y, z, z0, eps, (mpfr_ptr) 0); }
static void underflow_up3 (void) { mpfr_t x, y, z, z0; int inex; int rnd; int i; mpfr_init2 (x, 64); mpfr_init2 (y, sizeof (mpfr_exp_t) * CHAR_BIT); mpfr_init2 (z, 32); mpfr_init2 (z0, 2); inex = mpfr_set_exp_t (y, mpfr_get_emin () - 2, MPFR_RNDN); MPFR_ASSERTN (inex == 0); for (i = -1; i <= 1; i++) RND_LOOP (rnd) { unsigned int ufinex = MPFR_FLAGS_UNDERFLOW | MPFR_FLAGS_INEXACT; int expected_inex; mpfr_set_ui (x, 2, MPFR_RNDN); if (i < 0) mpfr_nextbelow (x); if (i > 0) mpfr_nextabove (x); /* x = 2 + i * eps, y = emin - 2, x^y ~= 2^(emin - 2) */ expected_inex = rnd == MPFR_RNDU || rnd == MPFR_RNDA || (rnd == MPFR_RNDN && i < 0) ? 1 : -1; mpfr_set_ui (z0, 0, MPFR_RNDN); if (expected_inex > 0) mpfr_nextabove (z0); mpfr_clear_flags (); inex = mpfr_pow (z, x, y, (mpfr_rnd_t) rnd); cmpres (0, x, "emin - 2", (mpfr_rnd_t) rnd, z0, expected_inex, z, inex, ufinex, "underflow_up3", "mpfr_pow"); test_others (NULL, "emin - 2", (mpfr_rnd_t) rnd, x, y, z, inex, ufinex, "underflow_up3"); } mpfr_clears (x, y, z, z0, (mpfr_ptr) 0); }
static void underflow_up1 (void) { mpfr_t delta, x, y, z, z0; mpfr_exp_t n; int inex; int rnd; int i; n = mpfr_get_emin (); if (n < LONG_MIN) return; mpfr_init2 (delta, 2); inex = mpfr_set_ui_2exp (delta, 1, -2, MPFR_RNDN); MPFR_ASSERTN (inex == 0); mpfr_init2 (x, 8); inex = mpfr_set_ui (x, 2, MPFR_RNDN); MPFR_ASSERTN (inex == 0); mpfr_init2 (y, sizeof (long) * CHAR_BIT + 4); inex = mpfr_set_si (y, n, MPFR_RNDN); MPFR_ASSERTN (inex == 0); mpfr_init2 (z0, 2); mpfr_set_ui (z0, 0, MPFR_RNDN); mpfr_init2 (z, 32); for (i = 0; i <= 12; i++) { unsigned int flags = 0; char sy[16]; /* Test 2^(emin - i/4). * --> Underflow iff i > 4. * --> Zero in MPFR_RNDN iff i >= 8. */ if (i != 0 && i != 4) flags |= MPFR_FLAGS_INEXACT; if (i > 4) flags |= MPFR_FLAGS_UNDERFLOW; sprintf (sy, "emin - %d/4", i); RND_LOOP (rnd) { int zero; zero = (i > 4 && (rnd == MPFR_RNDZ || rnd == MPFR_RNDD)) || (i >= 8 && rnd == MPFR_RNDN); mpfr_clear_flags (); inex = mpfr_pow (z, x, y, (mpfr_rnd_t) rnd); cmpres (1, "2", sy, (mpfr_rnd_t) rnd, zero ? z0 : (mpfr_ptr) NULL, -1, z, inex, flags, "underflow_up1", "mpfr_pow"); test_others ("2", sy, (mpfr_rnd_t) rnd, x, y, z, inex, flags, "underflow_up1"); } inex = mpfr_sub (y, y, delta, MPFR_RNDN); MPFR_ASSERTN (inex == 0); } mpfr_clears (delta, x, y, z, z0, (mpfr_ptr) 0); }
/* Compare the result (z1,inex1) of mpfr_pow with all flags cleared with those of mpfr_pow with all flags set and of the other power functions. Arguments x and y are the input values; sx and sy are their string representations (sx may be null); rnd contains the rounding mode; s is a string containing the function that called test_others. */ static void test_others (const void *sx, const char *sy, mpfr_rnd_t rnd, mpfr_srcptr x, mpfr_srcptr y, mpfr_srcptr z1, int inex1, unsigned int flags, const char *s) { mpfr_t z2; int inex2; int spx = sx != NULL; if (!spx) sx = x; mpfr_init2 (z2, mpfr_get_prec (z1)); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_pow (z2, x, y, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_pow, flags set"); /* If y is an integer that fits in an unsigned long and is not -0, we can test mpfr_pow_ui. */ if (MPFR_IS_POS (y) && mpfr_integer_p (y) && mpfr_fits_ulong_p (y, MPFR_RNDN)) { unsigned long yy = mpfr_get_ui (y, MPFR_RNDN); mpfr_clear_flags (); inex2 = mpfr_pow_ui (z2, x, yy, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_pow_ui, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_pow_ui (z2, x, yy, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_pow_ui, flags set"); /* If x is an integer that fits in an unsigned long and is not -0, we can also test mpfr_ui_pow_ui. */ if (MPFR_IS_POS (x) && mpfr_integer_p (x) && mpfr_fits_ulong_p (x, MPFR_RNDN)) { unsigned long xx = mpfr_get_ui (x, MPFR_RNDN); mpfr_clear_flags (); inex2 = mpfr_ui_pow_ui (z2, xx, yy, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_ui_pow_ui, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_ui_pow_ui (z2, xx, yy, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_ui_pow_ui, flags set"); } } /* If y is an integer but not -0 and not huge, we can test mpfr_pow_z, and possibly mpfr_pow_si (and possibly mpfr_ui_div). */ if (MPFR_IS_ZERO (y) ? MPFR_IS_POS (y) : (mpfr_integer_p (y) && MPFR_GET_EXP (y) < 256)) { mpz_t yyy; /* If y fits in a long, we can test mpfr_pow_si. */ if (mpfr_fits_slong_p (y, MPFR_RNDN)) { long yy = mpfr_get_si (y, MPFR_RNDN); mpfr_clear_flags (); inex2 = mpfr_pow_si (z2, x, yy, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_pow_si, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_pow_si (z2, x, yy, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_pow_si, flags set"); /* If y = -1, we can test mpfr_ui_div. */ if (yy == -1) { mpfr_clear_flags (); inex2 = mpfr_ui_div (z2, 1, x, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_ui_div, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_ui_div (z2, 1, x, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_ui_div, flags set"); } /* If y = 2, we can test mpfr_sqr. */ if (yy == 2) { mpfr_clear_flags (); inex2 = mpfr_sqr (z2, x, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_sqr, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_sqr (z2, x, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_sqr, flags set"); } } /* Test mpfr_pow_z. */ mpz_init (yyy); mpfr_get_z (yyy, y, MPFR_RNDN); mpfr_clear_flags (); inex2 = mpfr_pow_z (z2, x, yyy, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_pow_z, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_pow_z (z2, x, yyy, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_pow_z, flags set"); mpz_clear (yyy); } /* If y = 0.5, we can test mpfr_sqrt, except if x is -0 or -Inf (because the rule for mpfr_pow on these special values is different). */ if (MPFR_IS_PURE_FP (y) && mpfr_cmp_str1 (y, "0.5") == 0 && ! ((MPFR_IS_ZERO (x) || MPFR_IS_INF (x)) && MPFR_IS_NEG (x))) { mpfr_clear_flags (); inex2 = mpfr_sqrt (z2, x, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_sqrt, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_sqrt (z2, x, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_sqrt, flags set"); } #if MPFR_VERSION >= MPFR_VERSION_NUM(2,4,0) /* If y = -0.5, we can test mpfr_rec_sqrt, except if x = -Inf (because the rule for mpfr_pow on -Inf is different). */ if (MPFR_IS_PURE_FP (y) && mpfr_cmp_str1 (y, "-0.5") == 0 && ! (MPFR_IS_INF (x) && MPFR_IS_NEG (x))) { mpfr_clear_flags (); inex2 = mpfr_rec_sqrt (z2, x, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_rec_sqrt, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_rec_sqrt (z2, x, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_rec_sqrt, flags set"); } #endif /* If x is an integer that fits in an unsigned long and is not -0, we can test mpfr_ui_pow. */ if (MPFR_IS_POS (x) && mpfr_integer_p (x) && mpfr_fits_ulong_p (x, MPFR_RNDN)) { unsigned long xx = mpfr_get_ui (x, MPFR_RNDN); mpfr_clear_flags (); inex2 = mpfr_ui_pow (z2, xx, y, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_ui_pow, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_ui_pow (z2, xx, y, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_ui_pow, flags set"); /* If x = 2, we can test mpfr_exp2. */ if (xx == 2) { mpfr_clear_flags (); inex2 = mpfr_exp2 (z2, y, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_exp2, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_exp2 (z2, y, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_exp2, flags set"); } /* If x = 10, we can test mpfr_exp10. */ if (xx == 10) { mpfr_clear_flags (); inex2 = mpfr_exp10 (z2, y, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, flags, s, "mpfr_exp10, flags cleared"); __gmpfr_flags = MPFR_FLAGS_ALL; inex2 = mpfr_exp10 (z2, y, rnd); cmpres (spx, sx, sy, rnd, z1, inex1, z2, inex2, MPFR_FLAGS_ALL, s, "mpfr_exp10, flags set"); } } mpfr_clear (z2); }