Skip to content

Instantly share code, notes, and snippets.

View OpenGamma-Blog's full-sized avatar

OpenGamma OpenGamma-Blog

View GitHub Profile
@OpenGamma-Blog
OpenGamma-Blog / gist:2781598
Created May 24, 2012 13:40
JNI Example 1 - OpenGamma
/*
* Class: NativeInterfaceTest
* Method: dgemv_critical_
* Signature: ([C[I[I[D[D[I[D[I[D[D[I)V
*/
JNIEXPORT void JNICALL Java_NativeInterfaceTestLAPACK_dgemv_1critical_1 (j<type> foo, ...)
{
j<type> foo;
#define MACRO_criticalGetPointer(var)\
@OpenGamma-Blog
OpenGamma-Blog / gist:2781613
Created May 24, 2012 13:42
JNI Example 2 - OpenGamma
gcc -cpp -O3 -fPIC -o <lib name>.so -shared -Wl,-soname,<lib name>.so -I . -I ${JAVAROOT}/include/ -I ${JAVAROOT}/include/linux/ <file name>.c -l<BLAS lib name> -l<LAPACK lib name>
@OpenGamma-Blog
OpenGamma-Blog / gist:2781617
Created May 24, 2012 13:43
JNI Example 3 - OpenGamma
static {
try {
System.loadLibrary("<lib name>"); // no "lib" prefix or ".so" suffix
} catch (UnsatisfiedLinkError e) {
System.err.println("Cannot find <lib name> hooks.\n" + e);
System.exit(1);
}
@OpenGamma-Blog
OpenGamma-Blog / gist:2781621
Created May 24, 2012 13:44
JNA Example 1 - OpenGamma
// interface for LAPACK via JNA
public interface LAPACKLibrary extends Library {
LAPACKLibrary INSTANCE = (LAPACKLibrary)
Native.loadLibrary("liblapack.so",LAPACKLibrary.class);
LAPACKLibrary SYNC_INSTANCE = (LAPACKLibrary) Native.synchronizedLibrary(INSTANCE);
void dgemv_(...);
}
@OpenGamma-Blog
OpenGamma-Blog / gist:2828153
Created May 29, 2012 12:29
Accessing Native Maths Libraries 1
#define DGEMV_F77 F77_FUNC(dgemv,DGEMV)
#ifdef __cplusplus
extern "C"
#endif
void DGEMV_F77(char* trans, int* m, int* n, double* alpha, double* a, int* lda, double* x, int* incx, double* beta, double* y, int* incy);
@OpenGamma-Blog
OpenGamma-Blog / gist:2828162
Created May 29, 2012 12:31
Accessing Native Maths Libraries 2
#ifdef __cplusplus
extern "C"
#endif
/*
* Class: OGBLASRawWrapper
* Method: wrapped_dgemv
* Signature: (CIID[DI[DID[DI)V
*/
JNIEXPORT void JNICALL Java_com_opengamma_maths_nativewrappers_OGBLASRawWrapper_wrapped_1dgemv(JNIEnv * env, jclass theClass, jchar trans, jint m, jint n, jdouble alpha, jdoubleArray a, jint _offset_a ,jint lda, jdoubleArray x, jint _offset_x ,jint incx, jdouble beta, jdoubleArray y, jint _offset_y ,jint incy) {
char* _OG_ctrans = (char*) &trans;
@OpenGamma-Blog
OpenGamma-Blog / gist:2828167
Created May 29, 2012 12:34
Accessing Native Maths Libraries 3
public static void dgemv(char trans, int m, int n, double alpha, double[] a, int _offset_a, int lda, double[] x, int _offset_x, int incx, double beta, double[] y, int _offset_y, int incy)
{
#ifdef THREAD_SAFETY_ENTRY_PT
#include THREAD_SAFETY_ENTRY_PT_CODE
#endif
wrapped_dgemv(trans, m, n, alpha, a, _offset_a, lda, x, _offset_x, incx, beta, y, _offset_y, incy);
#ifdef THREAD_SAFETY_EXIT_PT
#include THREAD_SAFETY_EXIT_PT_CODE
#endif
#ifdef ERROR_HANDLER
@OpenGamma-Blog
OpenGamma-Blog / gist:2828169
Created May 29, 2012 12:35
Accessing Native Maths Libraries 4
private static native void wrapped_dgemv(char trans, int m, int n, double alpha, double[] a, int _offset_a, int lda, double[] x, int _offset_x, int incx, double beta, double[] y, int _offset_y, int incy);
@OpenGamma-Blog
OpenGamma-Blog / gist:2828177
Created May 29, 2012 12:38
Accessing Native Maths Libraries 5
// implement fortran xerbla
#define XERBLA_F77 F77_FUNC(xerbla,XERBLA)
// global cache of the VM ptr
JavaVM *JVMcache;
// Called when the native library is loaded
#ifdef __cplusplus
extern "C"
#endif
@OpenGamma-Blog
OpenGamma-Blog / gist:2843161
Created May 31, 2012 12:43
Testing Java Code in Maths Libraries 1
%% A translation of http://commons.apache.org/math/userguide/linear.html Example in section 3.2
%% Apache Commons Math is refered to as ACM
clear all; close all; clc;
% assume the jars in in the pwd, add to java class path
javaaddpath([pwd,'/commons-math3-3.0.jar']);
javaaddpath([pwd,'/octave.jar']);
% basenames for classes we'll be using
ACMBasename='org.apache.commons.math3.linear.';