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

cblas: compatibility for compilers without C99 complex number support (e.g. Visual Studio) #95

Closed
zchothia opened this issue Apr 23, 2012 · 1 comment
Assignees
Milestone

Comments

@zchothia
Copy link
Contributor

Hello Xianyi,

Visual Studio is unable to compile <cblas.h> included with OpenBLAS, due to its
use of the _Complex type which assumes C99 support. Here is a patch which switches
to a binary-compatible structure in cases where the complex number type is not available: https://gist.github.com/2470335.

With this change in place, this test program can now be built with Visual Studio 2010:

#include <stdio.h>

#include <openblas/cblas.h>

int main(void) {
  int N = 2, incX = 1, incY = 1;
  double x[] = {1.0, 2.0, 3.0, 4.0};
  double y[] = {1.0, 2.0, 3.0, 4.0};
  openblas_complex_double result = cblas_zdotu(N, x, incX, y, incY);
  printf("result = %lf + %lfi\n", openblas_complex_double_real(result),
                                  openblas_complex_double_imag(result));
  // Expected output: -10.000000 + 28.000000i
  return 0;
}

I have tested this change on Linux and Windows (MinGW) and have not observed any adverse effects.

Best,

--Zaheer

Additional notes:

  • <f77blas.h> has the same issue, but already contains a workaround, so I didn't make any changes.

  • The approach I have used is similar to that used in LAPACKE (see <lapacke_config.h>).
    There are several utility routines (make_complex, *_real, *_imag) included, which
    are not strictly necessary, but permit writing code which works with either complex type.

    It should be noted that OPENBLAS_COMPLEX_STRUCT is not a drop-in replacement
    for OPENBLAS_COMPLEX_C99. For instance, this snippet works with C99's _Complex,
    but fails to compile with the struct form:

    openblas_complex_double z1 = openblas_make_complex_double(1.0, 2.0);
    openblas_complex_double z2 = openblas_make_complex_double(3.0, 4.0);
    openblas_complex_double z3 = z1 + z2;

    For this reason, it may be preferrable to entirely drop the C99 _Complex type and
    always use the struct form, leaving conversion to client code. This is the approach
    taken by Intel's MKL, which is described in more detail here.

@ghost ghost assigned xianyi Apr 23, 2012
xianyi pushed a commit that referenced this issue Apr 24, 2012
@xianyi
Copy link
Collaborator

xianyi commented Apr 24, 2012

Hi Zaheer,

Thank you for your effort and patch on CBLAS complex issue.

Xianyi

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