java - Possible to pause main or OS thread to increase paralell computing speedup? -


i new multithreading , wanted know if offer core working on main thread used threadpool or happen automatically if use executorservice while calling invokeall?

i came qestion because performance tests showed speedup of maximum of 2.7 when using 3 or 4 threads in fixed thread pool.

but runtime says have 4 available processors (due hyperthreading on corei3) like speedup near 4.

or os need @ least 1 core occupied?

mwe:

private void doparallel() {    list<callable<object>> jobs = new arraylist<callable<object>>(threadcount);   (int = 0; < threadcount; i++) {     jobs.add(new callable<object>() {        @override        public object call() {          // compute heavy          return null;        }     });         }   // possible pause main thread here make 1   // additional core available threadpool?   threadpool.invokeall(jobs); // todo exception } 

assuming "main thread" refers os, , not java main(string[] args) method:

because it isn't possible assign threads cores, can't tell executor use "main" core. in addition, threads typically aren't bound 1 core specifically, phrase "core working on main thread" doesn't mean whole lot. java doesn't know "cores" -- that's jvm's job. thing can control java code number of threads use.

i guess means second guess correct 1 -- thread assignment/scheduling happens more or less automagically.

in addition, os entity handling threads (and other system resources), halting os means halting thread handling, lead bad things (tm) happening.

the best alternative minimize other load on computer -- closing other programs, not running anything, etc. let os/cpu scheduler take care of rest.

also, iirc hyperthreading doesn't provide quite same speedup having claimed number of cores, wouldn't expecting 4-core performance in first place. depends on workload, though; loads cause more stalled pipelines (e.g. i/o, cache misses, etc.) hyperthread better loads cpu-bound.

if main thread refers thread running main():

pausing java main thread wouldn't have of speedup either. if you're doing work on worker threads, , waiting on main thread, isn't doing work in first place, there isn't gain stopping it. , if it's blocked on worker pool finishing, it's sleeping anyways.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -