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

SVD threading issue (lapack.dgesdd) #743

Open
zorba128 opened this issue Mar 14, 2019 · 1 comment
Open

SVD threading issue (lapack.dgesdd) #743

zorba128 opened this issue Mar 14, 2019 · 1 comment

Comments

@zorba128
Copy link

Hi

I noticed SVD decomposition retuns wrong results when
invoking this method concurrently on the multithreaded environment:

  • fails on: com.github.fommil.netlib.NativeRefLAPACK (netlib-native_ref-win-x86_64.dll)
  • fails on: com.github.fommil.netlib.NativeSystemLAPACK (netlib-native_system-win-x86_64.dll)
  • success on: com.github.fommil.netlib.NativeSystemLAPACK (netlib-native_system-linux-x86_64.so)
  • success on: com.github.fommil.netlib.F2jLAPACK

Not sure if this is matter of glue code or LAPACK itself. Wrapping SVD method invocation
in the synchronization block helps (produces same results as when running single-threaded).

I noticedthat this issue affects only left/right vectors,
singular values seem to be fine.

Please take a look at sample code below:

object BreezeMultiThreading extends App {
  implicit val ec: ExecutionContextExecutor = scala.concurrent.ExecutionContext.global
  val x = Seq.tabulate(1000) { i =>
    Future /*.successful*/ { // uncomment to run single-threaded
      println(s"Iteration $i")
      val rnd = new scala.util.Random(12345 + i)
      val input = DenseMatrix.tabulate[Double](100, 100)((_,_) => rnd.nextDouble())
      val svdec = svd(input)
      // val sum = svdec.singularValues.valuesIterator.sum
      val sum = svdec.leftVectors.valuesIterator.sum + svdec.rightVectors.valuesIterator.sum
      sum
    }
  }

  val sum = Await.result(Future.sequence(x).map(_.sum), Duration.Inf)
  // val exp = 291367.83234463 // singular values
  val exp = -19997.446618756203 // left/right vectors
  if (abs(sum - exp) < 0.00001)
    Console.out.println(s"Success: $sum")
  else
    Console.err.println(s"Failed: $sum, expected: $exp")
}

marcin

@dlwh
Copy link
Member

dlwh commented Jul 7, 2019

sorry for being slow. it's suspicious to me this only happens on windows so i doubt it's the glue code. I can add a lock if we're running on windows, i guess?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants