Parallelization issues

ixid nuaccount at gmail.com
Thu Mar 8 06:11:25 PST 2012


This is a simple merge sorting implementation, a[0] and a[1] are 
the two halves of the array to be sorted, split into an int[][2] 
a array. This was done because I wanted to try parallel but that 
gives these errors:

	foreach(ref i;parallel(a))
		mergeSort(i);

Error: template std.array.popFront(A) if (!isNarrowString!(A) && 
isDynamicArray!(A) && isMutable!(A) && !is(A == void[])) does not 
match any function template declaration

Error	2	Error: template std.array.popFront(A) if 
(!isNarrowString!(A) && isDynamicArray!(A) && isMutable!(A) && 
!is(A == void[])) cannot deduce template function from argument 
types !()(int[][2u])

Without parallel it works as intended in a single threaded way. 
The same error is given using sort(i).

So I tried (and have probably misunderstood the correct 
syntax/steps required) using task as so:

	auto task1 = task!(mergeSort)(a[0]);
	task1.executeInNewThread();
	//taskPool.put(task1);
	mergeSort(a[1]);
	a[0] = task1.yieldForce();

I tried both the taskPool.put and executeInNewThread() versions, 
they both sort the numbers correctly but it's 3-4 times slower 
than doing it single-threaded. My processor is a Core 2 Duo and 
reports 2 with totalCPUs. I've also used multi-threading 
successfully with C++ before. What am I doing wrong?



More information about the Digitalmars-d-learn mailing list