Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Pomelov authored and SergeyPomelov committed Apr 15, 2016
0 parents commit d2756ba
Show file tree
Hide file tree
Showing 63 changed files with 4,722 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gradle
.idea
/build
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Computer and algorithm interaction simulation software (CAISS).
Simulation software contains in core a representation of architecture and algorithm.
Intended for simulation their interactions and listing their results for optimization
purposes.

### Running in IDEA
Select the `benchmarks.{desired runnable}` and `Run as a console Java application`.

# License
GNU GENERAL PUBLIC LICENSE Version 3.
58 changes: 58 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Computer and algorithm interaction simulation software (CAISS).
* Copyright (C) 2016 Sergei Pomelov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

plugins {
id 'java'
id 'idea'
id 'com.github.johnrengelman.shadow' version '1.2.3'
id 'me.champeau.gradle.jmh' version '0.3.0'
id 'net.ltgt.apt' version '0.6'
}

repositories {
jcenter()
mavenCentral()
}

sourceCompatibility = JavaVersion.VERSION_1_8
//noinspection GroovyUnusedAssignment, while it works don't touch it
targetCompatibility = sourceCompatibility

tasks.withType(AbstractCompile)*.options*.encoding = "UTF-8"

jmh.jmhVersion = '1.12'
tasks.jmh.main = 'benchmarks.control.JMHBenchmarksRunner'

jmhJar {
//noinspection GroovyAssignabilityCheck, while it works don't touch it
manifest.attributes 'Main-Class': tasks.jmh.main
append 'META-INF/BenchmarkList'
append 'META-INF/CompilerHints'
}

dependencies {
apt "org.openjdk.jmh:jmh-generator-annprocess:${jmh.jmhVersion}"

compile "org.openjdk.jmh:jmh-core:${jmh.jmhVersion}"
compile "org.slf4j:slf4j-api:1.7.+"
compile "ch.qos.logback:logback-classic:1.1.+"
compile 'com.google.code.findbugs:jsr305:3.0.+'
compile 'com.google.guava:guava:19.0'

testCompile 'junit:junit:4.12'
}
39 changes: 39 additions & 0 deletions src/main/java/benchmarks/control/AntsRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Computer and algorithm interaction simulation software (CAISS).
* Copyright (C) 2016 Sergei Pomelov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package benchmarks.control;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import benchmarks.tasks.ants.AntsColony;

/**
* @author Sergey Pomelov on 13/04/2016.
*/
final class AntsRunner {

private static final Logger log = LoggerFactory.getLogger(AntsRunner.class);

private AntsRunner() { /* runnable class */ }

public static void main(String... args) {
GNUCopyright.printLicence();
log.info(AntsColony.getInstance().getLog());
}
}
39 changes: 39 additions & 0 deletions src/main/java/benchmarks/control/GNUCopyright.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Computer and algorithm interaction simulation software (CAISS).
* Copyright (C) 2016 Sergei Pomelov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package benchmarks.control;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static util.Constants.GNU_COPYRIGHT_MSG;
import static util.Constants.LS;

/**
* @author Sergey Pomelov on 15/04/2016.
*/
final class GNUCopyright {

private static final Logger log = LoggerFactory.getLogger(GNUCopyright.class);

private GNUCopyright() { /* utility class */ }

static void printLicence() {
log.info("{}{}", LS, GNU_COPYRIGHT_MSG);
}
}
87 changes: 87 additions & 0 deletions src/main/java/benchmarks/control/JMHBenchmarksRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Computer and algorithm interaction simulation software (CAISS).
* Copyright (C) 2016 Sergei Pomelov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package benchmarks.control;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Timeout;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

import javax.annotation.ParametersAreNonnullByDefault;

import benchmarks.tasks.martixes.MatrixTasks;

import static org.openjdk.jmh.annotations.Mode.AverageTime;
import static org.openjdk.jmh.annotations.Mode.Throughput;

/**
* @author Sergey Pomelov on 06.04.16. Class can't be final or not public because runtime
* instrumentation reasons.
*/
@Fork(1)
@State(Scope.Benchmark)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@Warmup(iterations = 5, time = 5)
@Measurement(iterations = 10, time = 5)
@BenchmarkMode(AverageTime)
@Timeout(time = 30, timeUnit = TimeUnit.SECONDS)
@ParametersAreNonnullByDefault
public class JMHBenchmarksRunner {

@Param({"1", "2", "4", "8"})
private int threads;
//@Param({"10", "50", "100", "1000", "2000", "5000"})
private int size;

public static void main(String... args) throws RunnerException {
GNUCopyright.printLicence();
final Options options = new OptionsBuilder()
.include(JMHBenchmarksRunner.class.getSimpleName())
.build();
new Runner(options).run();
}

@Benchmark
public void matrixPow() {
MatrixTasks.matrixPow(threads);
}

@Warmup(iterations = 3, time = 3)
@Measurement(iterations = 3, time = 3)
@OutputTimeUnit(TimeUnit.SECONDS)
@BenchmarkMode(Throughput)
@Threads(-1)
public void memoryAlloc(Blackhole blackhole) {
blackhole.consume(MatrixTasks.memoryAlloc(size));
}
}
111 changes: 111 additions & 0 deletions src/main/java/benchmarks/control/ManualBenchmarksRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Computer and algorithm interaction simulation software (CAISS).
* Copyright (C) 2016 Sergei Pomelov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package benchmarks.control;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.lang.management.ManagementFactory;

import javax.annotation.ParametersAreNonnullByDefault;

import benchmarks.control.metrics.Measurer;
import benchmarks.control.metrics.PerformanceRecord;
import benchmarks.tasks.martixes.MatrixTasks;

import static util.ConversionUtil.bytesToMb;
import static util.TimeUtil.nanoToMls;

/**
* @author Sergey Pomelov on 06.04.16.
*/
@SuppressWarnings("SameParameterValue")
@ParametersAreNonnullByDefault
final class ManualBenchmarksRunner {

private static final Logger log = LoggerFactory.getLogger(ManualBenchmarksRunner.class);

private static final int ITERATIONS = 10;
private static final int MAX_DEGREE = 4;

private ManualBenchmarksRunner() { /* runnable class */ }

public static void main(String... args) {
printStats();
waitForInput();
log.info("started");
runBenchmark();
log.info("press to quit");
waitForInput();
System.exit(0);
}

private static void printStats() {
GNUCopyright.printLicence();
log.info("Press to start. Cores: {}. Memory: {} Mb.",
Runtime.getRuntime().availableProcessors(),
bytesToMb(Runtime.getRuntime().maxMemory()));
}

private static void runBenchmark() {
ManagementFactory.getThreadMXBean().setThreadCpuTimeEnabled(true);
for (int i = 0; i <= MAX_DEGREE; i++) {
final int twoPowI = Math.toIntExact(Math.round(StrictMath.pow(2, i)));
measure(() -> MatrixTasks.matrixPow(twoPowI), ITERATIONS, twoPowI + " threads");
}
}

private static void measure(Runnable task, int iterations, String label) {
warmUp(task, iterations, label);
rampUp(task, iterations, label);
}

private static void waitForInput() {
int input = 0;
try {
input = System.in.read();
} catch (IOException e) {
log.error("{} {}", input, e.getStackTrace());
}
}

private static void warmUp(Runnable task, int iterations, String label) {
log.debug("warm up start {}", label);
runSeveralTimes(task, iterations);
log.info("warm up end {}", label);
}

private static void runSeveralTimes(Runnable task, int iterations) {
for (int i = 0; i < iterations; i++) {
task.run();
}
}

private static void rampUp(Runnable task, int iterations, String label) {
log.debug("measuring start {}", label);
final PerformanceRecord info = new Measurer().measurePerformance(() ->
runSeveralTimes(task, iterations), label);
log.info("{}. Time avg: {}ms. Cpu total: {}ms. User total: {}ms.",
label,
(nanoToMls(info.getTime()) / iterations),
(nanoToMls(info.getCpuTime())),
(nanoToMls(info.getUserTime())));
}
}
39 changes: 39 additions & 0 deletions src/main/java/benchmarks/control/SimulationControllerRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Computer and algorithm interaction simulation software (CAISS).
* Copyright (C) 2016 Sergei Pomelov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package benchmarks.control;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import simulation.control.SimulationController;

/**
* @author Sergey Pomelov on 15/04/2016.
*/
public final class SimulationControllerRunner {

private static final Logger log = LoggerFactory.getLogger(SimulationControllerRunner.class);

private SimulationControllerRunner() { /* runnable class */ }

public static void main(String... args) {
GNUCopyright.printLicence();
log.info((new SimulationController()).simulate());
}
}
Loading

0 comments on commit d2756ba

Please sign in to comment.