LAPACK Archives

[Lapack] thread-safe version of dlamch

Thanks!   -Sherry

On Mon, Jul 27, 2015 at 8:18 PM, Piotr Luszczek <luszczek@Domain.Removed>
wrote:

Sherry,

it's been a while since I put the new dlamch.f code in LAPACK.

I managed to dig up a version in modern C. See below.

Piotr

#include <float.h>

#ifndef FLT_DIGITS
#define FLT_DIGITS 24
#endif
#ifndef DBL_DIGITS
#define DBL_DIGITS 53
#endif

float
slamch(char *cmach) {
  char ch = cmach[0];
  float sfmin, small, one = 1.0, zero = 0.0;

  if ('B' == ch || 'b' == ch) {
    return FLT_RADIX;
  } else if ('E' == ch || 'e' == ch) {
    return FLT_EPSILON;
  } else if ('L' == ch || 'l' == ch) {
    return FLT_MAX_EXP;
  } else if ('M' == ch || 'm' == ch) {
    return FLT_MIN_EXP;
  } else if ('N' == ch || 'n' == ch) {
    return FLT_DIGITS;
  } else if ('O' == ch || 'o' == ch) {
    return FLT_MAX;
  } else if ('P' == ch || 'p' == ch) {
    return FLT_EPSILON * FLT_RADIX;
  } else if ('R' == ch || 'r' == ch) {
    return FLT_ROUNDS < 2 ? one : zero;
  } else if ('S' == ch || 's' == ch) {
    /* Use SMALL plus a bit, to avoid the possibility of rounding causing
overflow
       when computing  1/sfmin. */
    sfmin = FLT_MIN;
    small = one / FLT_MAX;
    if (small >= sfmin) sfmin = small * (one + FLT_EPSILON);
    return sfmin;
  } else if ('U' == ch || 'u' == ch) {
    return FLT_MIN;
  }

  return zero;
}
double
dlamch(char *cmach) {
  char ch = cmach[0];
  double sfmin, small, one = 1.0, zero = 0.0;

  if ('B' == ch || 'b' == ch) {
    return FLT_RADIX;
  } else if ('E' == ch || 'e' == ch) {
    return DBL_EPSILON;
  } else if ('L' == ch || 'l' == ch) {
    return DBL_MAX_EXP;
  } else if ('M' == ch || 'm' == ch) {
    return DBL_MIN_EXP;
  } else if ('N' == ch || 'n' == ch) {
    return DBL_DIGITS;
  } else if ('O' == ch || 'o' == ch) {
    return DBL_MAX;
  } else if ('P' == ch || 'p' == ch) {
    return DBL_EPSILON * FLT_RADIX;
  } else if ('R' == ch || 'r' == ch) {
    return FLT_ROUNDS < 2 ? one : zero;
  } else if ('S' == ch || 's' == ch) {
    /* Use SMALL plus a bit, to avoid the possibility of rounding causing
overflow
       when computing  1/sfmin. */
    sfmin = DBL_MIN;
    small = one / DBL_MAX;
    if (small >= sfmin) sfmin = small * (one + DBL_EPSILON);
    return small;
  } else if ('U' == ch || 'u' == ch) {
    return DBL_MIN;
  }

  return zero;

}

On 7/25/15 2:11 AM, Xiaoye S. Li wrote:

I notice that lapack 3.5.0 now has a thread-safe version of dlamch.f,
which uses several Fortran intrinsics (supported by newer Fortran).

Is there any C version of thread-safe dlamch?

I tried to use f2c, got the following errors related to intrinsics
(probably f2c software is out of date; cannot handle intrinsics):

Error on line 93 of dlamch.f: Declaration error for digits: unknown
intrinsic function

Error on line 93 of dlamch.f: Declaration error for epsilon: unknown
intrinsic function

Error on line 93 of dlamch.f: Declaration error for huge: unknown
intrinsic function

Error on line 93 of dlamch.f: Declaration error for maxexponent: unknown
intrinsic function

Error on line 93 of dlamch.f: Declaration error for minexponent: unknown
intrinsic function

Error on line 93 of dlamch.f: Declaration error for radix: unknown
intrinsic function

Error on line 93 of dlamch.f: Declaration error for tiny: unknown
intrinsic function


I am updating SuperLU to be thread-safe.  I am using an old f2c'ed
dlamch.c (from CLAPACK), which contains lots of SAVE variables, and not
thread-safe.


Sherry



_______________________________________________
Lapack mailing list
Lapack@Domain.Removed
http://lists.eecs.utk.edu/mailman/listinfo/lapack


-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://lists.eecs.utk.edu/mailman/private/lapack/attachments/20150727/b25f20a1/attachment.html>

<Prev in Thread] Current Thread [Next in Thread>


For additional information you may use the LAPACK/ScaLAPACK Forum.
Or one of the mailing lists, or