Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Parallelization of multiple nested loops

by QM (Parson)
on Feb 07, 2018 at 11:53 UTC ( #1208624=note: print w/replies, xml ) Need Help??


in reply to Parallelization of multiple nested loops

You could also rework the nested loops into permutations or globs, and just have a single loop with an iterator.

I would naively suggest glob, but for your example, it eats up memory, and probably doesn't finish:

#!/usr/bin/env perl use strict; use warnings; # dummy values for @p, to get the last values not in a loop my @p = 0..12; # a single value # (this can be generalized, as parameters to a function to generate th +is string) my $glob_token = '{0.0,0.2,0.4,0.6,0.8,1.0}'; # join into multiple value string # (must use non-whitespace, as the builtin glob treats whitespace spec +ial) my $glob_parm = join(",", ($glob_token) x 11); # Loop fork for my $parm_list (glob($glob_parm)) { # now fix the commas $parm_list =~ s/,/\t/g; my $temp_out = "$parm_list\t$p[11]\t$p[12]\n"; print $temp_out; }

A similar solution using permutations a combination iterator would work. I'll have to see if I can find my array-of-arrays permutation iterator.

Update: This node on this thread should help.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208624]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2018-06-21 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (117 votes). Check out past polls.

    Notices?