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
Re: New parallelization pattern with CoWork [message #49148 is a reply to message #49143] Wed, 27 December 2017 00:36 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1226
Registered: August 2007
Senior Contributor
Hello Mirek,

This is good news. Thanks for your efforts!
U++ MT is really improved over time.

My initial impression: It looks and works good.

Here's another example (a visually more pleasing, and more concrete one I hope) Smile
This is to give some basic idea about it's possible usage to our fellow U++ users and newcomers.

void Mandelbrot::DrawFractal(const Rectf& r, int ix, int wcount)
{
	// This method draws the famous Mandelbrot fractal, using the escape time algorithm (slow).
	// Important note: Imagebuffer is accessed without using any locking mechansim.
	// While it is OK here, do not do this in real life unless you know what you're doing!
	
	auto sz = GetSize();
	Vector<Rect> regions;
	Sizef scale = iscale(sz, Sizef(1.0, 1.0), r.GetSize());
	
	for(int i = 0, cx = sz.cx / wcount, mod = sz.cx % wcount; i < wcount; i++) {
		auto x = i * cx;
		regions.Add(Rect(x, 0, x + cx + (i == wcount - 1 ? mod : 0), sz.cy));
	}
	ImageBuffer canvas(sz);
	
	if(CoWork::GetPoolSize() < wcount)
		CoWork::SetPoolSize(wcount);
	CoWork co;
	{
		RTIMING("Mandelbrot calculation with CoWork");
		co * [&] {
			int j = 0;
			while((j = co.Next()) < regions.GetCount()) {
				const auto& rr = regions[j];
				for(auto y = rr.top; y < rr.bottom; y++) {
					RGBA *pixel = canvas[y];
					for(auto x = rr.left; x < rr.right; x++) {
						Complex c(r.left + x / scale.cx, r.top + y / scale.cy);
						auto z = c;
						auto i = 0;
						while(abs(z) < 2 && i < ix) {
							z = z * z + c;
							i++;
						}
						if(i < ix) {
							 double jj = i + 1 - log(log2(abs(z)));
							 *(pixel + x) = HsvColorf(jj / double(ix),  1.0, (double(ix) / 256.0) * 1.888);
						}
						else *(pixel + x) = Black();
					}
				}
			}
		};
	}
	img = canvas;
	Refresh();
}





index.php?t=getfile&id=5468&private=0

Best regards,
Oblivion


[Updated on: Wed, 27 December 2017 00:51]

Report message to a moderator

 
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: Sun Aug 24 15:22:30 CEST 2025

Total time taken to generate the page: 0.00685 seconds