Start of change

Using OpenBLAS library

OpenBLAS library is a BLAS (Basic Linear Algebra Subroutines) library, which contains a set of routines that provide matrix/vector linear algebra functions. OpenBLAS runs on IBM z14® or newer and supports dynamic linking to it.

Installation location

  • /usr/lpp/cbclib/lib/
    • Dynamic library: libopenblas.dll
    • Side deck: libopenblas.x
  • /usr/lpp/cbclib/include/openblas/
    • Header files: cblas.h and others (not included as MVS data sets)

Using OpenBLAS with an application running unauthorized

You can compile your program with the OpenBLAS library. For example, in Open XL C/C++ for z/OS®:

ibm-clang64 main.c -c -I/usr/lpp/cbclib/include/openblas/

You can use the following command to link the OpenBLAS library in Open XL C/C++ for z/OS.

ibm-clang64 main.o /usr/lpp/cbclib/include/openblas/
Set the LIBPATH environment variable.
export LIBPATH=$LIBPATH:/usr/lpp/cbclib/lib/
Then, run the executable file.
a.out

Using OpenBLAS with an application running authorized

When running authorized, certain operations, such as printing, are restricted. OpenBLAS might need to print error messages under certain circumstances, so it is good practice to supply your print functions for OpenBLAS to call instead of the default print functions when running authorized; otherwise, OpenBLAS might abend if an error condition is encountered.

To supply alternative functions, take the following steps:
  1. Write your alternative functions for printf, fprintf, vfprintf, and perror, which use authorized services only and have the same prototypes as the original functions. The alternative functions must handle errors in a way that is appropriate for the application. For example, they can write to a job log by using authorized services, such as Write To Operator, or they can send a return code to the calling program.
  2. In your application program, include cblas.h and common.h.
  3. In your application program, before calling any other OpenBLAS functions, call the following functions to set OpenBLAS to use your alternative functions instead of the defaults, passing each a pointer to your corresponding alternative function:
    • __openblas_set_printf
    • __openblas_set_fprintf
    • __openblas_set_vfprintf
    • __openblas_set_perror
  4. Specify the following compile options when compiling your application program:
    -DzOS -D__OPENBLAS_AUTHORIZED_ZOS

Example

The following example shows how an application program calls OpenBLAS running authorized.
/* main.c */ 

#include <stdio.h>
#include <stdarg.h>
#include "cblas.h"
#include "common.h"

// User-supplied alternative print functions for running authorized
// Note: The commented-out calls to vprintf, vfprintf, and perror must be replaced by
//       user-supplied code that uses only authorized services.

// User-supplied alternative function for printf
int my_printf (const char *fmt, ...) {
  va_list args;
  va_start (args, fmt);
  /* vprintf (fmt, args); */  // Replace with code using only authorized services
  va_end (args);
  return 0;
}

// User-supplied alternative function for fprintf
int my_fprintf (FILE *fp, const char *fmt, ...) {
  va_list args;
  va_start (args, fmt);
  /* vfprintf (fp, fmt, args); */  // Replace with code using only authorized services
  va_end (args);
  return 0;
}

// User-supplied alternative function for vfprintf
int my_vfprintf (FILE *fp, const char *fmt, char **args) {
  /* vfprintf (fp, fmt, args); */  // Replace with code using only authorized services
  return 0;
}

// User-supplied alternative function for perror
void my_perror (const char *msg) {
  extern int errno;
  /* printf ("my_perror: %s errno=%d\n", msg, errno); */  // Replace with code using only authorized services
}

main(){
  // Set OpenBLAS to use the alternative print functions
  __openblas_set_printf (&my_printf);
  __openblas_set_fprintf (&my_fprintf);
  __openblas_set_vfprintf (&my_vfprintf);
  __openblas_set_perror (&my_perror);
  
  
  // Application code that calls OpenBLAS goes here
}

Compiling, linking, and running an application running authorized that uses OpenBLAS

You can compile your program with the OpenBLAS library. For example, in Open XL C/C++ for z/OS:

ibm-clang64 main.c -DzOS -D__OPENBLAS_AUTHORIZED_ZOS -c -I/usr/lpp/cbclib/include/openblas/

You can use the following command to link the OpenBLAS library. For example, in Open XL C/C++ for z/OS:

ibm-clang64 main.o /usr/lpp/cbclib/lib/libopenblas.x
Set the LIBPATH environment variable.
export LIBPATH=$LIBPATH:/usr/lpp/cbclib/lib/
Then, run the executable file.
a.out

Related information

End of change