Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » U++ community news and announcements » New parallelization pattern with CoWork
New parallelization pattern with CoWork [message #49143] Tue, 26 December 2017 11:44 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
While trying to parallelize Painter, I have found that there is a set of algorithms that are 'too short' to parallelize with CoWork operator& and 'too unstable' to parallelize with CoPartition. 'too short', because the cost of creating Event (which is about 80ns) is too large compared to the work done by job in parallel. 'too unstable' means that the time taken by single job highly unpredictable, so assigning regularly sized chunks of work to threads tends to some threads ending early and one thread going for long time.

Thinking about the issue, I have found a new parallelization pattern (and implemented it with CoWork):

CONSOLE_APP_MAIN
{
	SeedRandom(0);
	Vector<String> data;
	for(int i = 0; i < 1000; i++) {
		int n = Random(7);
		data.Add();
		for(int j = 0; j < n; j++)
			data.Top() << Random() << ' ';
	}
	
	double sum = 0;
	CoWork co;
	co * [&] {
		double m = 0;
		int i;
		while((i = co.Next()) < data.GetCount()) {
			CParser p(data[i]);
			while(!p.IsEof())
				m += p.ReadDouble();
		}
		CoWork::FinLock();
		sum += m;
	};

	RDUMP(sum);
}


operator* schedules all CoWork threads to run a single routine. 'co.Next' then atomically returns increasing numbers (from 0), which are used to distribute the work.

So in this 'outside-in' approach, just a single lambda is created and only a handful of jobs have to be started for things to work and management overhead is thus greatly reduced...
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Happy new year 2018 for all U++ users
Next Topic: BufferPainter now MT optimized
Goto Forum:
  


Current Time: Sat Apr 20 05:30:56 CEST 2024

Total time taken to generate the page: 0.05238 seconds