Scientific computing and parallel computing C++23/C++26

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 13 20:58:25 UTC 2022


On Thu, Jan 13, 2022 at 08:07:51PM +0000, forkit via Digitalmars-d wrote:
[...]
> // ----
> module test;
> 
> import std;
> 
> @safe
> void main()
> {
>     //int[5] arr = [1, 2, 3, 4, 5]; // nope. won't work with .parallel
>     int[] arr = [1, 2, 3, 4, 5];// has to by dynamic to work with .parallel
> ??

Just write instead:

	int[5] arr = [1, 2, 3, 4, 5];
	foreach (n; arr[].parallel) ...

In general, whenever something rejects static arrays, inserting `[]`
usually fixes it. :-D

I'm not 100% sure why .parallel is @system, but I suspect it's because
of potential issues with race conditions, since it does not prevent you
from writing to the same local variable from multiple threads. If
pointers are updated this way, it could lead to memory corruption
problems.


T

-- 
Long, long ago, the ancient Chinese invented a device that lets them see through walls. It was called the "window".


More information about the Digitalmars-d mailing list