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
- Dynamic library:
/usr/lpp/cbclib/include/openblas/- Header files:
cblas.hand others (not included as MVS data sets)
- Header files:
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/
LIBPATH environment
variable.export LIBPATH=$LIBPATH:/usr/lpp/cbclib/lib/
a.outUsing 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.
- Write your alternative functions for
printf,fprintf,vfprintf, andperror, 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. - In your application program, include
cblas.handcommon.h. - 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
- Specify the following compile options when compiling your application
program:
-DzOS -D__OPENBLAS_AUTHORIZED_ZOS
Example
/* 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
LIBPATH environment
variable.export LIBPATH=$LIBPATH:/usr/lpp/cbclib/lib/
a.outRelated information
- For a list of OpenBLAS functions and code examples of calling the functions, see code examples.
- For description of the authorized program facility, see Authorized Program Facility and Access Method Services.
- For a list of services that are provided when running authorized, see Library function support.
