Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tpetra: Mac Clang has trouble reading -9.6322e-41 as float #6611

Closed
mhoemmen opened this issue Jan 19, 2020 · 0 comments
Closed

Tpetra: Mac Clang has trouble reading -9.6322e-41 as float #6611

mhoemmen opened this issue Jan 19, 2020 · 0 comments
Labels
type: bug The primary issue is a bug in Trilinos code or tests

Comments

@mhoemmen
Copy link
Contributor

Bug Report

@trilinos/tpetra

Description

With Clang on a Mac, TpetraCore_MatrixMatrix_UnitTests_MPI_4 fails with Scalar=float and complex<float> while trying to read line 398 of tpetra/core/test/MatrixMatrix/matrices/cdt_m.mtx. Line 398 looks like this:

  3860  2784 -9.6322e-41

It turns out that -9.6322e-41 is a subnormal number in float. The test prints the following:

  p=0: *** Caught standard std::exception of type 'std::runtime_error' :
1:
1:   .../packages/tpetra/core/inout/MatrixMarket_Tpetra.hpp:2352:
1:
1:   Throw number = 2
1:
1:   Throw test that evaluated to true: readSuccess == 0
1:
1:   Failed to read the Matrix Market sparse matrix file: Failed to get real value from line 398 of input

I inserted print statements to figure out what file it was having trouble reading.

Weirdly, Clang had no trouble with the following example:

#include <iostream>
#include <sstream>

int main() {
  std::istringstream is ("-9.6322e-41");
  float fl{};
  is >> fl;
  std::cout << fl << std::endl;
  return 0;
}

Both Mac Clang, and GCC 9.2 with -std=c++17, run fine and print -9.63225e-41. However, when I change the code that reads real values from

istr >> the_realValue;

to

if (std::is_same<Real, float>::value) {
  double dblVal {};
  istr >> dblVal;
  the_realValue = static_cast<Real> (dblVal);
}
else {
  istr >> the_realValue;
}

the test passes.

Steps to Reproduce

Build TpetraCore's tests with Mac Clang; here is part of the output of clang++ --version:

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
@mhoemmen mhoemmen added the type: bug The primary issue is a bug in Trilinos code or tests label Jan 19, 2020
mhoemmen added a commit that referenced this issue Jan 23, 2020
jmgate pushed a commit to tcad-charon/Trilinos that referenced this issue Jan 24, 2020
…s:develop' (a7632d8).

* trilinos-develop:
  Tpetra,kokkos-kernels: Fix trilinos#6633
  Reformulates the driver in a residual form. That is, we invoke Vcycles to correct the existing solution using the residual as the right hand side.  We then removes a few matvecs and some setup stages that are not actually needed. In particular, we take advantage of the fact that the initial guess is zero on the presmoothing side of the MG cycle. Also removed the smoother setup for the coarsest region level when we have not requested to smooth on this level.
  Tpetra: Add debug output to sparse matrix-matrix multiply test
  Belos: Fix test build failure on Mac Clang (missing header)
  Tpetra: Fix Scalar=float BCRS test failure on Mac Clang
  Anasazi: Fix trilinos#6612
  Tpetra: Fix trilinos#6611
jmgate pushed a commit to tcad-charon/Trilinos that referenced this issue Jan 24, 2020
…s:develop' (a7632d8).

* trilinos-develop:
  Tpetra,kokkos-kernels: Fix trilinos#6633
  Reformulates the driver in a residual form. That is, we invoke Vcycles to correct the existing solution using the residual as the right hand side.  We then removes a few matvecs and some setup stages that are not actually needed. In particular, we take advantage of the fact that the initial guess is zero on the presmoothing side of the MG cycle. Also removed the smoother setup for the coarsest region level when we have not requested to smooth on this level.
  Tpetra: Add debug output to sparse matrix-matrix multiply test
  Belos: Fix test build failure on Mac Clang (missing header)
  Tpetra: Fix Scalar=float BCRS test failure on Mac Clang
  Anasazi: Fix trilinos#6612
  Tpetra: Fix trilinos#6611
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug The primary issue is a bug in Trilinos code or tests
Projects
None yet
Development

No branches or pull requests

1 participant