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

42
LINES

< > BotCompany Repo | #1011722 // websMadeByProgram_parallel - use them cores!!

JavaX fragment (include)

static L<Web> websMadeByProgram_parallel(S progID) {
  ret websMadeByProgram_parallel(progID, null);
}

static L<Web> websMadeByProgram_parallel(S progID, final Map<Web, SoftwareMadeWeb> furtherInfoMap) ctex {
  // TODO: clean up file handle in case of error
  IterableIterator<S> l = scanLog_iterator(progID, "webs-made.txt");
  fS src = progID;
  final new L<Pair<Web, Int>> webs;
  
  int poolSize = numberOfCores(), queueSize = 20;
  NotifyingBlockingThreadPoolExecutor e = new(poolSize, queueSize, 15, TimeUnit.SECONDS);
  
  try {
    int i = 0;
    for (fS s : l) {
      ++i;
      final int _i = i;
      e.execute(r { pcall {
        SoftwareMadeWeb o = cast unstructure(s);
        Web web = o.web;
        if (web == null)
          web = (Web) unstructure(o.structure);
        if (web != null) synchronized(webs) {
          webs.add(pair(web_intern(web_setSourceIfEmpty(web, src)), _i));
          mapPut(furtherInfoMap, web, o);
        }
      }});
    }
    //e.await(); // ConcurrentModificationException sometimes??
    e.shutdown();
    e.awaitTermination(1, TimeUnit.DAYS);
  } finally {
    e.shutdown();
  }
  
  time "Sort" {
    sortBySecondOfPairs_inPlace(webs);
  }
  
  ret concatLists(ai_triplesMadeByProgram(progID), firstOfPairs(webs));
}

Author comment

Began life as a copy of #1011177

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1011722
Snippet name: websMadeByProgram_parallel - use them cores!!
Eternal ID of this version: #1011722/15
Text MD5: ce81be32ae31b0ba9398a101c7b192c0
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-11-05 03:42:56
Source code size: 1311 bytes / 42 lines
Pitched / IR pitched: No / No
Views / Downloads: 431 / 451
Version history: 14 change(s)
Referenced in: [show references]