Libraryless. Click here for Pure Java version (9223L/51K).
// Main function that user can call static long stupidFib_collab(ICollab collab, int n) { ret collab_computeLong2(collab, continuation -> stupidFib_collab(collab, n, continuation)); } // Work function used internally svoid stupidFib_collab(ICollab collab, int n, LongConsumer continuation) { // switch to serial if no coworkers, OR if small enough work unit if (collab.singleCore() || n < 24) ret with continuation.accept(stupidFib(n)); // recursion base if (n < 3) ret with continuation.accept(1); // recursion step var collector = longPairCollector((a, b) -> continuation.accept(a+b)); collab.addWork(-> stupidFib_collab(collab, n-1, collector.a)); collab.addWork(-> stupidFib_collab(collab, n-2, collector.b)); } /* // Both functions in one using the "parallel" modifier static parallel long stupidFib_collab(int n) { // switch to serial if no coworkers, OR if small enough work unit if (collab.singleCore() || n < 24) ret stupidFib(n); // recursion base if (n < 3) ret 1; // recursion step var collector = longPairCollector((a, b) -> ret a+b); collab.addWork(-> stupidFib_collab(collab, n-1, collector.setA())); collab.addWork(-> stupidFib_collab(collab, n-2, collector.setB())); } */
Began life as a copy of #1035566
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035569 |
Snippet name: | stupidFib_collab - stupidFib as a massively parallel function! |
Eternal ID of this version: | #1035569/26 |
Text MD5: | e8869546fb889c61bbcbb648ca2feb06 |
Transpilation MD5: | 965b76052e4273e340432f54d9edc74e |
Author: | stefan |
Category: | javax / maths |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-06-19 04:22:48 |
Source code size: | 1273 bytes / 36 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 173 / 325 |
Version history: | 25 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |