Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

45
LINES

< > BotCompany Repo | #1030547 // parallelMap2 [backup]

JavaX fragment (include)

1  
sbool parallelMap2_debug;
2  
3  
static <A, B> L<B> parallelMap2(ThreadPoolExecutor e defaultThreadPoolExecutor(), Collection<A> l, F1<A, B> f) {
4  
  if (l(l) <= 1)
5  
    ret map(f, l);
6  
  ret parallelMap2(iterator(l), l(l), f);
7  
}
8  
9  
static <A, B> L<B> parallelMap2(ThreadPoolExecutor e defaultThreadPoolExecutor(), Iterator<A> it, final int count, final F1<A, B> f) ctex {
10  
  if (e.getPoolSize() == 1)
11  
    ret map(f, iterable(it));
12  
    
13  
  new LPair<B, Int> out;
14  
  if (parallelMap2_debug)
15  
    print("parallelMap2: " + count + " elements, " + poolSize + " threads");
16  
    
17  
  long time = sysNow();
18  
  try {
19  
    int i = 0;
20  
    for (final A o : iterable(it)) {
21  
      ++i;
22  
      final int _i = i;
23  
      e.execute(r { pcall {
24  
        B x = callF(f, o);
25  
        synchronized(out) {
26  
          out.add(pair(x, _i));
27  
        }
28  
      }});
29  
    }
30  
    /*if (parallelMap2_debug)
31  
      print("parallelMap2: scheduling done after " + (sysNow()-time));*/
32  
    e.shutdown();
33  
    e.awaitTermination(1, TimeUnit.DAYS);
34  
  } finally {
35  
    e.shutdown();
36  
  }
37  
  if (parallelMap2_debug)
38  
    print("parallelMap2: main done after " + (sysNow()-time));
39  
    
40  
  ret firstOfPairs(sortBySecondOfPairs_inPlace(out));
41  
}
42  
43  
static <A, B> L<B> lambdaMapLike parallelMap2(IF1<A, B> f, Cl<A> l) {
44  
  ret parallelMap2(l, if1ToF1(f));
45  
}

Author comment

Began life as a copy of #1015446

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030547
Snippet name: parallelMap2 [backup]
Eternal ID of this version: #1030547/1
Text MD5: e5ae61b394a262fa889e3953489c82b4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-01-07 02:30:09
Source code size: 1322 bytes / 45 lines
Pitched / IR pitched: No / No
Views / Downloads: 182 / 205
Referenced in: [show references]