Java in High-Performance Computing

N/A
N/A
Protected

Share "Java in High-Performance Computing"

Copied!
117
0
0

Full text

(1)

Dawid Weiss

Carrot Search

Institute of Computing Science, Poznan University of Technology

(2)
(3)
(4)

(5)
(6)

(7)

(8)

style algorithm

for (Example e : examples) {

e.hasQuiz() ? e.showQuiz() : e.showCode(); e.explain();

e.deriveConclusions(); }

(9)
(10)

(11)

(12)

(13)

(14)

(15)

(16)

(17)

(18)

(19)

Example 1

public void testSum1() { int sum = 0;

for (int i = 0; i < COUNT; i++) sum += sum1(i, i);

result = sum; }

public void testSum2() { int sum = 0;

for (int i = 0; i < COUNT; i++) sum += sum2(i, i);

result = sum; }

(20)

Example 1

public void testSum1() { int sum = 0;

for (int i = 0; i < COUNT; i++) sum += sum1(i, i);

result = sum; }

public void testSum2() { int sum = 0;

for (int i = 0; i < COUNT; i++) sum += sum2(i, i);

result = sum; }

(21)

(22)

(23)

(24)

(25)

(26)

(27)

(28)

(29)

22.49

(30)

int sum1(int a, int b) { return a + b;

}

Integer sum2(Integer a, Integer b) { return a + b;

}

↓

Integer sum2(Integer a, Integer b) { return Integer.valueOf(

a.intValue() + b.intValue()); }

(31)

int sum3(int... args) { int sum = 0;

for (int i = 0; i < args.length; i++) sum += args[i];

return sum; }

Integer sum4(Integer... args) { int sum = 0;

for (int i = 0; i < args.length; i++) { sum += args[i];

}

return sum; }

↓

Integer sum4(Integer [] args) {

// ...

(32)

(33)
(34)

Example 2

(35)
(36)
(37)
(38)
(39)
(40)

public void run() { try {

sleep(2000);

} catch (Exception e) { /* ignore */ } System.out.println("Marking loop exit."); ready = true;

} }.start(); }

public static void main(String[] args) { startThread();

System.out.println("Entering the loop..."); while (!ready) {

// Do nothing.

}

System.out.println("Done, I left the loop!"); }

(41)

while (!ready) { // Do nothing. }

?

boolean r = ready; while (!r) { // Do nothing. }

(42)

while (!ready) { // Do nothing. }

?

boolean r = ready; while (!r) { // Do nothing. }

(43)
(44)
(45)
(46)
(47)

(48)

(49)
(50)

(51)

(52)
(53)
(54)
(55)

(56)
(57)

(58)
(59)

(60)
(61)

(62)
(63)

Example 3

public void testSum1() { int sum = 0;

for (int i = 0; i < COUNT; i++) sum += sum1(i, i);

result = sum; }

public void testSum1_2() { int sum = 0;

for (int i = 0; i < COUNT; i++) sum += sum1(i, i);

(64)

(65)

(66)

(67)

0.11

(68)
(69)

java -server -XX:+PrintOptoAssembly -XX:+PrintCompilation ...

- method holder: ’com/dawidweiss/geecon2010/Example03’ - access: 0xc1000001 public

- name: ’testSum1_2’ ...

010 pushq rbp

subq rsp, #16 # Create frame

nop # nop for patch_verified_entry 016 addq rsp, 16 # Destroy frame

popq rbp

testl rax, [rip + #offset_to_poll_page] # Safepoint: poll for GC 021 ret

(70)

java -server -XX:+PrintOptoAssembly -XX:+PrintCompilation ...

- method holder: ’com/dawidweiss/geecon2010/Example03’ - access: 0xc1000001 public

- name: ’testSum1_2’ ...

010 pushq rbp

subq rsp, #16 # Create frame

nop # nop for patch_verified_entry 016 addq rsp, 16 # Destroy frame

popq rbp

testl rax, [rip + #offset_to_poll_page] # Safepoint: poll for GC 021 ret

(71)

(72)

Example 4

@Test

public void testAdd1() { int sum = 0;

for (int i = 0; i < COUNT; i++) { sum += add1(i);

}

guard = sum; }

public int add1(int i) { return i + 1; }

(73)

(74)

(75)

(76)

(77)

Example 5

abstract class Superclass { abstract int call(); }

class Sub1 extends Superclass { int call() { return 1; } } class Sub2 extends Superclass

{ int call() { return 2; } } class Sub3 extends Superclass

{ int call() { return 3; } } Superclass[] mixed =

initWithRandomInstances(10000); Superclass[] solid =

initWithSub1Instances(10000);

@Test

public void testMonomorphic() { int sum = 0;

int m = solid.length;

for (int i = 0; i < COUNT; i++) sum += solid[i % m].call(); guard = sum;

}

@Test

public void testMegamorphic() { int sum = 0;

int m = mixed.length;

for (int i = 0; i < COUNT; i++) sum += mixed[i % m].call(); guard = sum;

(78)

(79)

Example 6

@Test

public void testBitCount1() { int sum = 0;

for (int i = 0; i < COUNT; i++) sum += Integer.bitCount(i); guard = sum;

}

@Test

public void testBitCount2() { int sum = 0;

for (int i = 0; i < COUNT; i++) sum += bitCount(i); guard = sum; } /* Copied from * {@link Integer#bitCount} */

static int bitCount(int i) {

// HD, Figure 5-2 i = i - ((i >>> 1) & 0x55555555); i = (i & 0x33333333) + ((i >>> 2) & 0x33333333); i = (i + (i >>> 4)) & 0x0f0f0f0f; i = i + (i >>> 8); i = i + (i >>> 16); return i & 0x3f; }

(80)

0.43

(averages in sec., 10 measured rounds, 5 warmup, 64-bit Ubuntu, dual-core AMD Athlon 5200).

(81)

0.43

(averages in sec., 10 measured rounds, 5 warmup, 64-bit Ubuntu, dual-core AMD Athlon 5200).

0.32

(82)

... -XX:+PrintInlining ...

...

Inlining intrinsic _bitCount_i at bci:9 in ..Example06::testBitCount1 Inlining intrinsic _bitCount_i at bci:9 in ..Example06::testBitCount1 Inlining intrinsic _bitCount_i at bci:9 in ..Example06::testBitCount1 Example06.testBitCount1: [measured 10 out of 15 rounds]

round: 0.07 [+- 0.00], round.gc: 0.00 [+- 0.00] ...

@ 9 com.dawidweiss.geecon2010.Example06::bitCount inline (hot) @ 9 com.dawidweiss.geecon2010.Example06::bitCount inline (hot) @ 9 com.dawidweiss.geecon2010.Example06::bitCount inline (hot) Example06.testBitCount2: [measured 10 out of 15 rounds]

(83)

... -XX:+PrintInlining ...

...

Inlining intrinsic _bitCount_i at bci:9 in ..Example06::testBitCount1 Inlining intrinsic _bitCount_i at bci:9 in ..Example06::testBitCount1 Inlining intrinsic _bitCount_i at bci:9 in ..Example06::testBitCount1 Example06.testBitCount1: [measured 10 out of 15 rounds]

round: 0.07 [+- 0.00], round.gc: 0.00 [+- 0.00] ...

@ 9 com.dawidweiss.geecon2010.Example06::bitCount inline (hot) @ 9 com.dawidweiss.geecon2010.Example06::bitCount inline (hot) @ 9 com.dawidweiss.geecon2010.Example06::bitCount inline (hot) Example06.testBitCount2: [measured 10 out of 15 rounds]

(84)

... -XX:+PrintOptoAssembly ...

{method}

- klass: {other class}

- method holder: com/dawidweiss/geecon2010/Example06 - name: testBitCount1

...

0c2 B13: # B12 B14 &lt;- B8 B12 Loop: B13-B12 inner stride: ... 0c2 movl R10, RDX # spill

...

0e1 movl [rsp + #40], R11 # spill 0e6 popcnt R8, R8

...

0f5 addl R9, #7 # int 0f9 popcnt R11, R11 0fe popcnt RCX, R9

(85)

... -XX:+PrintOptoAssembly ...

{method}

- klass: {other class}

- method holder: com/dawidweiss/geecon2010/Example06 - name: testBitCount1

...

0c2 B13: # B12 B14 &lt;- B8 B12 Loop: B13-B12 inner stride: ... 0c2 movl R10, RDX # spill

...

0e1 movl [rsp + #40], R11 # spill 0e6 popcnt R8, R8

...

0f5 addl R9, #7 # int 0f9 popcnt R11, R11 0fe popcnt RCX, R9

(86)
(87)
(88)

→

averages, variance, min, max, warm-up phase

test-on-target

(89)

(90)

(91)

Why not JCF?

public interface List<E> extends Collection<E> {

boolean contains(Object o); // [-] contract-enforced methods

Iterator<E> iterator(); // [-] iterators over primitive types?

Object[] toArray(); // [-] troublesome covariants

(92)

(93)

PCJ

interface IntIterator extends Iterator<Integer> {

// Primitive-specific method

int nextInt(); }

(94)

HPPC

public final class IntCursor { public int index;

public int value; }

public class IntArrayList extends Iterable<IntCursor> { Iterator<IntCursor> iterator() { ... }

(95)

Iterating over list elements in HPPC

for (IntCursor c : list) {

System.out.println(c.index + ": " + c.value); }

...or

list.forEach(new IntProcedure() { public void apply(int value) {

System.out.println(value); }

});

...or

final int[] buffer = list.buffer; final intsize = list.size();

for (int i = 0; i < size; i++) {

System.out.println(i + ": " + buffer[i]); }

(96)

Iterating over list elements in HPPC

for (IntCursor c : list) {

System.out.println(c.index + ": " + c.value); }

...or

list.forEach(new IntProcedure() { public void apply(int value) {

System.out.println(value); }

});

...or

final int[] buffer = list.buffer; final intsize = list.size();

for (int i = 0; i < size; i++) {

System.out.println(i + ": " + buffer[i]); }

(97)

Iterating over list elements in HPPC

for (IntCursor c : list) {

System.out.println(c.index + ": " + c.value); }

...or

list.forEach(new IntProcedure() { public void apply(int value) {

System.out.println(value); }

});

...or

final int[] buffer = list.buffer; final intsize = list.size();

for (int i = 0; i < size; i++) {

System.out.println(i + ": " + buffer[i]); }

(98)
(99)
(100)
(101)
(102)
(103)

good.

(104)

/**

* Applies a supplemental hash function to a given * hashCode, which defends against poor quality * hash functions. [...]

*/

static int hash(int h) {

// This function ensures that hashCodes that differ only by // constant multiples at each bit position have a bounded

// number of collisions (approximately 8 at default load factor).

h ^= (h >>> 20) ^ (h >>> 12); return h ^ (h >>> 7) ^ (h >>> 4); }

(105)

HPPC approach (example):

public class LongIntOpenHashMap implements LongIntMap {

// ...

public LongIntOpenHashMap(int initialCapacity, float loadFactor, LongHashFunction keyHashFunction, IntHashFunction valueHashFunction) {

// ...

}

(106)

(107)

HPPC:

final char [] CHARS = DATA;

final IntIntOpenHashMap counts = new IntIntOpenHashMap(); for (int i = 0; i < CHARS.length - 1; i++) {

counts.putOrAdd((CHARS[i] << 16 | CHARS[i + 1]), 1, 1); }

JCF, boxed integer types.

final Integer currentCount = map.get(bigram);

map.put(bigram, currentCount == null ? 1 : currentCount + 1);

•

map.put(bigram, map.get(bigram) + 1);

(108)
(109)
(110)

(111)

(112)

(113)

(114)

(115)
(116)

(117)

HPPC and junit-benchmarks are at:

References

Related documents

Looking at the estimations for cross-border trade, we can highlight one service sectors with evident complementary effects which stands out because most of regulations show

( 2014 ) case-based ( n  = 1) Exploring the effects of Hr practices in the implementation of lean production Hallgren and olhager ( 2009 ) Secondary data ( n  = 211) testing the

Understanding the factors and dynamics behind the regional wage differentials is crucial from the policy perspective, as it provides with valuable information about the performance

However, in addition to investigating the extent to which leader image persuaded voting behaviour, this research provided deeper understanding as was demonstrated

In the context of Indigenous self-determination in Canada, antagonisms exist in the paramountcy of state sovereignty premised on a colonial history, which in turn is met by

A new method to collect suspended particles in air using cloth samplers as atmospheric fine dust catch - ers for monitoring air pollution was introduced known as “Textile

Analyzing the short-term merits of externally conducted TCL projects Anecdotal evidence indicates that open innovation intermediaries, possessing relevant project

This tends to show that access in any form appears to be the source of vulnera- bility rather than incident specifics due to a fundamental trade-off between usability and security

Finally, ESOPs are classified as a pure employee benefit if they are not defensive, wage concession, or leveraged ESOPs and we could surmise from reading the Wall Street Journal,

If a team forfeits three (3) league games due to lack of players at the start of a regularly scheduled game, the team will be dropped from the league with no refund of entry fee

To withdraw, students must contact East Central College Community Education no less than 48 hours prior to the start of the class. Students that withdraw less than 48 hours prior to

divestment movement, which included over 700 independent divestment pledges, including that of the Rockefeller fund, in the span of one day (Divest-Invest, 2014). Thus

If the insurer accepts your application, your existing amount of death/TPD cover (subject to maximum limits) as at the transfer date under your former super fund will be added

Orienteering Australia does have a major role in the management of national teams and squads at junior and elite level, and in coordinating the National Orienteering League, which

year round Lafayette Farmers & Artisans Market Horse Farm, 2913 Johnston St.. New Orleans Crescent City Farmers Market #2 Uptown Square, 200

Valtra Smart Farming is a set of technologies that work seamlessly together – Valtra Guide, ISOBUS, Section Control, Variable Rate Control and..

AIA Prime Critical Cover offers you critical illness coverage up to age 100, with additional 50% coverage during your later years.. • Receive 100% of the insured amount when you

For my thesis project, I decided to build a website that allows  users to input their zip code in order to receive information on which types of native  pollinator-friendly plants

Keywords: project scatter factor, resource dedication pro®le, human resources, R&amp;D organisation, project portfolio, business plan, project planning, project management,

 “ “ The Mongol leaders were unusually The Mongol leaders were unusually cruel in their conquests and rule. cruel in their conquests

For further help or support, please contact your pouako, Awhi Tauira or the eWānanga Helpdesk (see &#34;eWānanga Helpdesk&#34; on page 8 of this booklet).... 16 Managing Your

You can sort them into primary, secondary or tertiary industries: take it, make it or sell or service

In April 2015, the Central Research Laboratory, Hitachi Research Laboratory, Yokohama Research Laboratory, Design Division, and the overseas research centers were realigned