Skip to content

Commit

Permalink
Merge pull request #41 from SFI-Mechatronics/dev
Browse files Browse the repository at this point in the history
Release 0.9

* Replaces JNA with JNI for a considerable performance gain
  • Loading branch information
markaren authored Aug 16, 2018
2 parents 188f47e + 00d1712 commit 0063126
Show file tree
Hide file tree
Showing 64 changed files with 2,498 additions and 1,717 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*.war
*.ear

*.dll
*.so

!resources/**/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FMI4j is a software package for dealing with Functional Mock-up Units (FMUs) on
FMI4j supports [FMI](http://fmi-standard.org/) 2.0 for **Model Exchange** and **Co-simulation**.
For Model Exchange, solvers from [Apache Commons Math](http://commons.apache.org/proper/commons-math/userguide/ode.html) can be used.

Compared to other FMI libraries targeting the JVM, FMI4j is considerable faster due to the fact that we use JNI instead of JNA. A speedup of 2-5x should be excpected.

The package consists of:
* [A software API for interacting with FMUs](#api)
Expand Down
24 changes: 9 additions & 15 deletions library/FMI4j/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ subprojects { sub ->

repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

def slf4j_version = '1.7.25'
def junit_version = '5.2.0'

dependencies {

sub.plugins.withId ('kotlin') {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

implementation group: 'org.slf4j', name: 'slf4j-api', version: slf4j_version
runtimeOnly group: 'org.slf4j', name: 'slf4j-log4j12', version: slf4j_version
Expand All @@ -39,17 +35,15 @@ subprojects { sub ->
useJUnitPlatform()
}

sub.plugins.withId ('kotlin') {
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = ['-Xjvm-default=enable']
}
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = ['-Xjvm-default=enable']
}
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

}

Expand Down
97 changes: 94 additions & 3 deletions library/FMI4j/fmi-import/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

import org.apache.tools.ant.taskdefs.condition.Os

plugins {
id "c"
id "com.github.johnrengelman.shadow" version "2.0.4"
}

Expand All @@ -10,9 +13,6 @@ dependencies {
api project(':fmi-import-solvers-api')
api project(':fmi-modeldescription')

implementation group: 'net.java.dev.jna', name: 'jna', version: '4.5.2'
implementation group: 'net.java.dev.jna', name: 'jna-platform', version: '4.5.2'

testImplementation project(':fmi-import-solvers-apache-math3')
testImplementation group: 'org.siani.javafmi', name: 'fmu-wrapper', version: '2.24.4'

Expand All @@ -23,3 +23,94 @@ shadowJar {
classifier = null
version = null
}

model {

platforms {
if (Os.isFamily(Os.FAMILY_UNIX)) {
linux32 {
architecture "x86"
operatingSystem "linux"
}
linux64 {
architecture "x86_64"
operatingSystem "linux"
}
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
win32 {
architecture "x86"
operatingSystem "windows"
}
win64 {
architecture "x86_64"
operatingSystem "windows"
}
}
}

toolChains {
gcc(Gcc) {
if (Os.isFamily(Os.FAMILY_UNIX)) {
target("linux32")
target("linux64")
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
target("win32")
target("win64")
}
}
}


components {
fmi(NativeLibrarySpec) {

if (Os.isFamily(Os.FAMILY_UNIX)) {
targetPlatform "linux32"
targetPlatform "linux64"
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
targetPlatform "win32"
targetPlatform "win64"
}

binaries.all {

if (Os.isFamily(Os.FAMILY_UNIX)) {
cCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cCompiler.args '-I', "${org.gradle.internal.jvm.Jvm.current().javaHome}/include/linux"
} else if (Os.isFamily(Os.FAMILY_WINDOWS)) {
cCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include"
cCompiler.args "-I${org.gradle.internal.jvm.Jvm.current().javaHome}/include/win32"
}

}

}

}

buildTypes {
release
}

tasks {
buildAllExecutables(Task) {
dependsOn $.binaries.findAll { it.buildable }
}
copyNativeLibs(Copy) {
from "$buildDir/libs/fmi/shared"
into "$projectDir/src/main/resources/native/fmi"
dependsOn buildAllExecutables
}
}
}

//task generateJNI(type: Exec) {
// if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// commandLine 'cmd', '/c', 'javac'
// } else if (Os.isFamily(Os.FAMILY_UNIX)) {
// commandLine 'javac', "${workingDir}/src/main/java/no/mechatronics/sfi/fmi4j/jni/FmiLibrary.java", "-h", "src/fmi/c"
// } else {
// }
//}
//
//generateJNI.dependsOn(compileJava)
Loading

0 comments on commit 0063126

Please sign in to comment.