Linking mkl functions with JAVA

Linking mkl functions with JAVA

Hi

Please give me the details of how to link the mkl functions with JAVA.

Is there any setting option in JAVA to include the files "mkl_c.lib" and "libguide.lib"?

Or the procedure for calling mkl functions from JAVA is different compared to VC++?

Regards

Joesam

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Joesam,

Are you asking about Suns Java and its ports? If so, then basically, yes, the way to call MKL functions from Java is different.

Java implementations deem MKL as native code which is distinguished from Java bytecode. For calling native code from Java bytecode, Java supports the so-called Java Native Interface (JNI). You may read about JNI at the Suns web-site:

http://java.sun.com/j2se/1.5.0/docs/guide/jni/index.html

Roughly speaking, one needs to know three points about the JNI:

  • The keyword native of the Java Language which is used to mark stub methods.
  • The javah tool found inside JDK which is used to generate *.h files for the stubs.
  • Understand what the stubs are.

To simplify the get started stage of studying JNI, you may want to see the codes for the example Hello World! application which Im displaying hereby. Hopefully, this must help.

Thanks,

Yevgeny Latkin

Files list:

  • setup.bat
  • makefile
  • hello.java
  • hello.c

File listings:

File: setup.bat

set JAVA_HOME=C:injdk1.6

set PATH=%JAVA_HOME%in;%PATH%

call "C:Program FilesMicrosoft Visual Studio 8VCvcvarsall.bat"

File: makefile

help:

@echo # Usage: nmake {all/clean} [CC=icl]

@echo #

@echo # CC=icl - use Intel C++ compiler

! IFNDEF CC

CC = cl

! ENDIF

.PHONY: all clean

all:

@echo # compile the Java code

javac hello.java

@echo # create *.h for the stubs

javah hello

@echo # build the stubs library

$(CC) /LD /Fehello.dll hello.c /I.

/I$(JAVA_HOME)include /I$(JAVA_HOME)includewin32

@echo # remove needless files

del hello.obj

del hello.lib

del hello.exp

del hello.h

@echo # run the Java application

java -Djava.library.path=. hello

@echo # OK

clean:

-del hello.dll

-del Hello.class

File: hello.java

/**

* Demonstrating JNI.

*/

public final class hello {

/**

* Command-line options args[] ignored.

*/

public static void main(String args[]) {

hello();

}

/**

* Stub method.

*/

private static native void hello();

/**

* Load the stubs library.

*/

static {

System.loadLibrary("hello");

}

}

File: hello.c

#include "hello.h"

#include

#include

/*

* Class: hello

* Method: hello

* Signature: ()V

*/

JNIEXPORT void JNICALL Java_hello_hello(JNIEnv *env, jclass clazz) {

printf("hello
");

}

This article was very helpful.

Moving one step ahead, could you please suggest some example with makefile where JAVA is calling fortran with JNI as wrapper.

Thanks a lot in advance!!

Leave a Comment

Please sign in to add a comment. Not a member? Join today