Logo by mario837 - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Follow us on Twitter
 
*
Welcome, Guest. Please login or register. April 19, 2024, 08:28:39 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: pipelines pattern  (Read 9222 times)
0 Members and 1 Guest are viewing this topic.
ker2x
Fractal Molossus
**
Posts: 795


WWW
« on: October 19, 2017, 07:30:44 AM »

Hello hello ! I'm just wondering, anyone played with this https://msdn.microsoft.com/en-us/library/ff963548.aspx?f=255&MSPPError=-2147217396 ?

I always wanted to try something like this to generate buddhabrot.

eg :
generate random complex -> quick rejection test (cardioid and Nth order bulb) -> escape test (interation) -> draw orbit -> merge with display -> post process display (gamma/brightness/contrast)
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #1 on: October 20, 2017, 07:23:17 AM »

It's surprisingly easy to use.

Exemple of 2 stage pipeline :

Code:
            var buffer1 = new BlockingCollection<double>(512);
            var f = new TaskFactory(TaskCreationOptions.LongRunning,
                                                     TaskContinuationOptions.None);
            var stage1 = f.StartNew(() => Buddhapipeline.RandomGenerator(buffer1, 32));
            var stage2 = f.StartNew(() => Buddhapipeline.PointGenerator(buffer1, pBackBuffer));


Then you create a bunch of static method that produce/consume using "add" to add item in a queue.
And "take" or a "foreach(var item in intput.GetConsumingEnumerable()) {...}" loop to consume.
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #2 on: October 20, 2017, 11:36:16 AM »

a more useful sample :

Code:
            //Pipeline are magic <3
            var bufferRandom = new BlockingCollection<double>(4096);
            var bufferComplex = new BlockingCollection<Complex>(4096);
            var bufferFiltered = new BlockingCollection<Complex>(4096);
            var bufferFiltered2 = new BlockingCollection<Complex>(4096);
            var bufferBmp = new BlockingCollection<Tuple<int, int>>(4096);

            var f = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None);
            var stage1 = f.StartNew(() => Buddhapipeline.RandomGenerator(bufferRandom, 32));
            var stage2 = f.StartNew(() => Buddhapipeline.ComplexGenerator(bufferRandom, bufferComplex, -2, 1.0, -1.5, 1.5));
            var stage3 = f.StartNew(() => Buddhapipeline.quickRejectionFilter(bufferComplex, bufferFiltered));
            var stage4 = f.StartNew(() => Buddhapipeline.iterativeRejectionFilter(bufferFiltered, bufferFiltered2));
            var stage5 = f.StartNew(() => Buddhapipeline.complexToBmp(bufferFiltered2, bufferBmp, -2, 1.0, -1.5, 1.5, imageWidth, imageHeight));
            var stage6 = f.StartNew(() => Buddhapipeline.pointToScreen(bufferBmp, pBackBuffer));

And 2 sample consumer/producer :

Code:
        /*
         * quick rejection filter
         */
         public static void quickRejectionFilter(BlockingCollection<Complex> input, BlockingCollection<Complex> output)
        {
            foreach(var item in input.GetConsumingEnumerable())
            {
                if (Complex.Abs(item) > 2.0) continue;
                if (((Complex.Abs(item - new Complex(-1, 0))) < 0.25)) continue;
                if ((Complex.Abs(1.0 - Complex.Sqrt(Complex.One - (4 * item))) < 1.0)) continue; //may be wrong
                if ((((item.Real + 1.309) * (item.Real + 1.309)) + item.Imaginary * item.Imaginary) < 0.00345) continue;
                if ((((item.Real + 0.125) * (item.Real + 0.125)) + (item.Imaginary - 0.744) * (item.Imaginary - 0.744)) < 0.0088) continue;
                if ((((item.Real + 0.125) * (item.Real + 0.125)) + (item.Imaginary + 0.744) * (item.Imaginary + 0.744)) < 0.0088) continue;
 
                //We tried every known quick filter and didn't reject the item, adding it to next queue.
                output.Add(item);
            }
        }

        /* iterative rejection filter */
        public static void iterativeRejectionFilter(BlockingCollection<Complex> input, BlockingCollection<Complex> output)
        {
            foreach (var item in input.GetConsumingEnumerable())
            {
                int iter = 0;
                Complex z = Complex.Zero;
                while ((Complex.Abs(z) < 4.0) && (iter < 2000))
                {
                    iter++;
                    z = z * z + item;
                }
                if (iter == 2000) continue;

                //We tried, couldn't reject it, adding it to next queue
                output.Add(item);
            }
        }
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #3 on: October 20, 2017, 12:52:33 PM »

i finished most of the code before i knew it shocked

Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #4 on: October 21, 2017, 07:21:15 AM »

tadaaaa ! superheavily multithreaded, very reactive, only the luminosity and  contrast works and no zoom yet.

BUT

IT

WORKS!

Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
ker2x
Fractal Molossus
**
Posts: 795


WWW
« Reply #5 on: October 21, 2017, 02:48:21 PM »

in action. I added nice bar to the bottom left to monitor thread starvation / empty pipeline

<a href="https://www.youtube.com/v/-T6wy7xLxmE&rel=1&fs=1&hd=1" target="_blank">https://www.youtube.com/v/-T6wy7xLxmE&rel=1&fs=1&hd=1</a>
Logged

often times... there are other approaches which are kinda crappy until you put them in the context of parallel machines
(en) http://www.blog-gpgpu.com/ , (fr) http://www.keru.org/ ,
Sysadmin & DBA @ http://www.over-blog.com/
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Supraterranean Pipelines Images Showcase (Rate My Fractal) JoeFRAQ 5 753 Last post October 15, 2013, 03:36:38 AM
by mclarekin
Supraterranean Pipelines II Images Showcase (Rate My Fractal) JoeFRAQ 5 832 Last post October 18, 2013, 12:39:57 PM
by Nahee_Enterprises
Supraterranean Pipelines III Images Showcase (Rate My Fractal) JoeFRAQ 1 763 Last post October 18, 2013, 12:49:17 PM
by Nahee_Enterprises
Supraterranean Pipelines IV Images Showcase (Rate My Fractal) JoeFRAQ 0 1070 Last post November 09, 2013, 02:12:50 PM
by JoeFRAQ
Supraterranean Pipelines V Images Showcase (Rate My Fractal) JoeFRAQ 0 1156 Last post March 30, 2014, 02:34:16 PM
by JoeFRAQ

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.185 seconds with 27 queries. (Pretty URLs adds 0.009s, 2q)