.net Core Parallel.ForEach issues

Why Parallel.ForEach is not good for this task is explained in comments: it’s designed for CPU-bound (CPU-intensive) tasks. If you use it for IO-bound operations (like making web requests) – you will waste thread pool thread blocked while waiting for response, for nothing good. It’s possible to use it still, but it’s not best for … Read more

MPI_Type_create_subarray and MPI_Gather

So this is a little more subtle, and requires some understanding of how the Gather collective places complex types. If you look at most examples of MPI_Gather, they’re of 1-d arrays, and it’s fairly easy to interpret what should happen; you’re getting (say) 10 ints from each process, and Gather is smart enough to put … Read more

OpenMP: What is the benefit of nesting parallelizations?

(1) Nested parallelism in OpenMP: http://docs.oracle.com/cd/E19205-01/819-5270/aewbc/index.html You need to turn on nested parallelism by setting OMP_NESTED or omp_set_nested because many implementations turn off this feature by default, even some implementations didn’t support nested parallelism fully. If turned on, whenever you meet parallel for, OpenMP will create the number of threads as defined in OMP_NUM_THREADS. So, … Read more

How to pause/resume all threads in an ExecutorService in Java?

To answer my own question, I found an example of a PausableThreadPoolExecutor in the javadocs of ThreadPoolExecutor itself. Here is my version using Guava’s Monitors: import com.google.common.util.concurrent.Monitor; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; public class PausableExecutor extends ScheduledThreadPoolExecutor { private boolean isPaused; private final Monitor monitor = new Monitor(); private final Monitor.Guard paused = new Monitor.Guard(monitor) { … Read more

Should thread-safe class have a memory barrier at the end of its constructor?

Lazy<T> is a very good choice for Thread-Safe Initialization. I think it should be left to the consumer to provide that: var queue = new Lazy<ThreadSafeQueue<int>>(() => new ThreadSafeQueue<int>()); Parallel.For(0, 10000, i => { else if (i % 2 == 0) queue.Value.Enqueue(i); else { int item = -1; if (queue.Value.TryDequeue(out item) == true) Console.WriteLine(item); } … Read more

Does Java have support for multicore processors/parallel processing?

Does Java have support for multicore processors/parallel processing? Yes. It also has been a platform for other programming languages where the implementation added a “true multithreading” or “real threading” selling point. The G1 Garbage Collector introduced in newer releases also makes use of multi-core hardware. Java Concurrency in Practice Try to get a copy of … Read more