Parallel foreach over AliasSec?

Bastiaan Veelo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 26 16:35:06 PST 2017


Hi,

Is it possible to parallelise the iteration over an AliasSec? 
Ordinary parallel foreach does not work. I have tried submitting 
tasks to taskPool in an ordinary foreach, but I can't because i 
cannot be read at compile time.

int one(int) {return 1;}
int two(int) {return 2;}
int three(int) {return 3;}
int four(int) {return 4;}
int five(int) {return 5;}
int six(int) {return 6;}
int seven(int) {return 7;}
int eight(int) {return 8;}

int[8] values;

template eval_all(funcs...)
{
	void eval_all(int val)
	{
		import std.parallelism;
		//foreach (i, f; parallel(funcs))	// Tries to evaluate f(void)
		foreach (i, f; funcs)	// How do I parallelise this?
			values[i] = f(val);
	}
}

void main()
{
	eval_all!(one, two, three, four, five, six, seven, eight)(42);
	foreach(i, val; values)
		assert(val == i + 1);
}

Thanks!


More information about the Digitalmars-d-learn mailing list