title: OpenBLAS sgemm, special requirements? sometimes I get nan
body: <p>I have this declaration in my header somewhere:</p>
  
  <pre><code>typedef float real;
  typedef int integer;
  extern "C" {
  extern int sgemm_(char *transa, char *transb,
    integer *m, integer *n, integer *k,
    const real *alpha,
    const real *a, integer *lda,
    const real *b, integer *ldb,
    const real *beta,
    real *c, integer *ldc);
  }
  </code></pre>
  
  <p>Then I'm linking against the OpenBLAS lib (or optionally also other BLAS libs, e.g. MKL). And then I'm directly calling <code>sgemm_</code> in my C++ code. (The code should in principle work with any BLAS library.)</p>
  
  <p>I'm not sure if this is a bad idea or not. Or what I should take care of. E.g. do I need a special alignment? Or do I need to take care in multi-threaded environments?</p>
  
  <p>(E.g. I was looking a bit through the OpenBLAS code (<code>SGEMM</code> kernel specifically), and it looks like it assumes special alignment requirements (but maybe I got that wrong).)</p>
  
  <p>It mostly seems to work fine. Except that in some cases (non-deterministically, maybe 10% of the cases, for some complex test cases, I get <code>nan</code> in my result; and it seems to not happen in our production code).</p>