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

45
LINES

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

JavaX fragment (include)

sbool parallelMap2_debug;

static <A, B> L<B> parallelMap2(ThreadPoolExecutor e defaultThreadPoolExecutor(), Collection<A> l, F1<A, B> f) {
  if (l(l) <= 1)
    ret map(f, l);
  ret parallelMap2(iterator(l), l(l), f);
}

static <A, B> L<B> parallelMap2(ThreadPoolExecutor e defaultThreadPoolExecutor(), Iterator<A> it, final int count, final F1<A, B> f) ctex {
  if (e.getPoolSize() == 1)
    ret map(f, iterable(it));
    
  new LPair<B, Int> out;
  if (parallelMap2_debug)
    print("parallelMap2: " + count + " elements, " + poolSize + " threads");
    
  long time = sysNow();
  try {
    int i = 0;
    for (final A o : iterable(it)) {
      ++i;
      final int _i = i;
      e.execute(r { pcall {
        B x = callF(f, o);
        synchronized(out) {
          out.add(pair(x, _i));
        }
      }});
    }
    /*if (parallelMap2_debug)
      print("parallelMap2: scheduling done after " + (sysNow()-time));*/
    e.shutdown();
    e.awaitTermination(1, TimeUnit.DAYS);
  } finally {
    e.shutdown();
  }
  if (parallelMap2_debug)
    print("parallelMap2: main done after " + (sysNow()-time));
    
  ret firstOfPairs(sortBySecondOfPairs_inPlace(out));
}

static <A, B> L<B> lambdaMapLike parallelMap2(IF1<A, B> f, Cl<A> l) {
  ret parallelMap2(l, if1ToF1(f));
}

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: 109 / 136
Referenced in: [show references]