Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
"I cannot make any connection between this post and the earlier 2 in the series"

Sorry BrowserUK for being imprecise, i'll try to give some more information:

Short time ago i wrote a script for learning purposes and fun that renders a huge image (20 MP) in ~13m on my box

I'd like to write a multithreaded version of this script.

The basic idea is to do it "row by row".

Enqueue some rows of the image and process them...

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x

...next step...

x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x

...proceed until finished.

The snippet in my OP calculates the coordinates for the rows.

For $width = 4; $height = 4; $qsize  = 4; the output is:

[ [[0, 0], [0, 1], [0, 2], [0, 3]], [[1, 0], [1, 1], [1, 2], [1, 3]], [[2, 0], [2, 1], [2, 2], [2, 3]], [[3, 0], [3, 1], [3, 2], [3, 3]], ]

@queue should perhaps better been named @rows.

Then:

my $queue = Thread::Queue->new(); $queue->enqueue(\@rows); my @threads = map { threads->create( \&process, $queue ); } 1 .. 4; ...

Somewhere in the code:

if ( $div == 0 ) { $image->setpixel( x => $x, y => $y, color => $black ); } else { $image->setpixel( x => $x, y => $y, color => $palette[$color] ); }

OK, busted. It's a Mandelbrot. My first try.

I hope very much that i could clarify the connection of my OP to the series.

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»


In reply to Re^2: Threads From Hell #3: Missing Some Basic Prerequisites by karlgoethebier
in thread Threads From Hell #3: Missing Some Basic Prerequisites [Solved] by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-16 22:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found