Parallelized for loop. Searching for a one-line solution

Hi.
In an usual day I do a lot of for loops inside of command line. But I noted that my loops don't use the full power of my dual core processor, they only use one processor.
A lot of the loops I do have independent interactions in the sense that a interaction code don't need the results of another interaction. This is the simplest problem in multiprocessing, I only need to execute N process in parallel.
I'm searching for a one-line solution that I can use in place of a 'for i in *.txt; do echo $i;done'. With one-line I means that can be used as one-line but the implementation can be longer. And can be in any programming language.
For now I'm using the following small python solution (the smallest I could get)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
from glob import glob
from subprocess import call
def f(x):
call(['asy', '-f', 'png', '-render=0', x])
pool = Pool(processes=4)
pool.map(f, glob('*.asy'))
But I like something that can be integrated in my "shell life". Anyone know a solution for my problem?

http://stackoverflow.com/questions/3816 … ash-script
http://www.mail-archive.com/bug-bash@gn … 05820.html
Last edited by karol (2009-11-23 00:30:34)

Similar Messages

  • According to material num,for every new material num  one line space.

    Hi,
    please give suggestion how to get vertical lines without breaking as shown below.
    I want according to material number(AT1),for every new material number  one line space have to be there.
    I used 'skip' so the verical line is breaking for every new material.
    Material Number  |   Material Description
    _____________ |______________________________________________
    |    AT1                  |   Catalyst - 18165-RNA-A013-Y2
    |    AT2                  |   Catalyst - 18165-RNA-A013-Y2
    |    AT3                  |   Catalyst - 18165-RNA-A013-Y2 (COPY)
    |    AT4                  |   Catalyst - 18165-RNA-A013-Y2
    |    AT5                  |   Catalyst - 18165-RNA-A013-Y2
    |   CGW0001             SUBSTRATE 148 X 84 X 67 - 400/6/S/0.699L
    |  CGW0001              SUBSTRATE 148 X 84 X 67 - 400/6/S/0.699L
    |  CGW0001              SUBSTRATE 148 X 84 X 67 - 400/6/S/0.699L
    CGW0001             SUBSTRATE 148 X 84 X 67 - 400/6/S/0.699L
    |   CGW0001             SUBSTRATE 148 X 84 X 67 - 400/6/S/0.699L
    |   CGW0001             SUBSTRATE 148 X 84 X 67 - 400/6/S/0.699L
    |   CGW0001             SUBSTRATE 148 X 84 X 67 - 400/6/S/0.699L
    I need line continous but for every new material to material gap.
    Thanks,
    sree.

    Hi,
    write code like this.
    write : /1 sy-vline,120 sy-vline.
    give the line size for ex 120
    reward if usefull

  • Logon script for looping - searching - deleting - copy

    I was trying to do multiple functions within a logon script.  If nobody wants to write the script, can you please point me to the right resource to find how to code it.  I am completely new to this and need help.
    The logic is to have a list of files on the server which were recently updated(this list changes all the time), using these files you would loop and search for these same files on the end user's machine upon logging in.  When it finds that same file
    on the end user's machine you would delete the file from the end user's machine, then copy the new updated file from the server onto the end user's machine in the same location the previous one was deleted from.  If file not found on end user's machine
    then just copy new one without deleting anything in highest level directory.  When done, you would loop again until you went thru every file that was updated on the server.  The source directory will always be the same and the copy to directory on
    end user's machine will always be the same, but end user's machines have subdirectories and the files that will be getting updated are in both.  Any help in any fashion would be appreciated.
    We are in the process of migrating from XP to Windows 7.  While in XP, we only had to do a copy function in the logon script and it would copy over the old file and replace it.  But Windows 7 doesn't delete the old file, it appends the new one
    to the old one, making it hard for the software looking for these files to work properly when it sees two files instead of one current one.  Hopefully this makes sense, I can elaborate more if anyone wants to help and needs more details.  Thanks.

    I would definitely not recommend copying files to end user machines from a logon script.
    But you are right that this isn't a script-on-demand forum.
    You can post a script request here:
    https://gallery.technet.microsoft.com/scriptcenter/site/requests
    I would point out that, as with this forum, there is no service-level agreement that guarantees that someone will have the time do this work for you. You will need to provide a very detailed specification; your post here is very vague.
    However: It sounds to me like you don't have a scripting question but some kind of application architecture question.
    -- Bill Stewart [Bill_Stewart]

  • For-Loops: The question no one asks.

    Why don't For-Loops have a premature exit capability --- i.e. why didn't
    NI include the exit capability that exists in other languages? Is it a dataflow
    thing? I don't see how. Just curious.

    Jay,
    I have to say I`m no programming Guru, but isn`t a State Maschine based on a
    case (Switch) statement? This statement does allow the user to hop to and
    fro within a certian pre-defined space, but the use of a GOTO is, as far as
    I am aware, not limited to a particular region of the code. At least with a
    switch statement (Case) the beginning point of each "choice" is well defined
    and fixed, therefore reducing the change of mistakes.
    just my 2 cents
    Shane
    Jay schrieb in Nachricht <[email protected]>...
    >
    >Hey, Tim. You say:
    >
    >>I believe that the loop exit capability wasn't included because it was
    considered
    >bad programming practice, like using goto's.
    >
    > That's funny. How can it be any worse (or different) than putt
    ing exit
    >logic into a While-Loop? As for Goto's, they're the basic logic behind the
    >much revered State Machine, and no one seems to mind that. If you're not
    >careful, State Machines can wind up producing some pretty good spaghetti
    >code, just like any text-based code can do.
    >
    >Jay
    >
    >>> Original message: Why don't For-Loops have a premature exit capability
    >--- i.e. why didn't NI include the exit capability that exists in other
    languages?
    > Is it a dataflow thing? I don't see how. Just curious.
    Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)

  • Using a For Loop Index for Array Element Number?

    Hi.  Thanks in advance for the help.  I can't seem to find what I want to do here using the search function... probably because I don't know how to frame the question appropriately.  Ignore the title to this post cause it's probably wrong vocabulary for what I want to do.
    Here's the situation:
    I have a 2D array where the first column is the X data and each subsequent column is Y data (call it Y1...Yn).  The n-value varies from run to run (some runs have 4 columns of data, some have 20), but that is easily gathered when reading the data file.  I need to perform a number of operations on each set of data, the least of which is smoothing the data and graphing it, so I'm limiting my discussion to these 2 operations.
    What I want is a for loop structure where the indexing of the loop tracks the Y1...Yn columns, grabs each column for the iteration, performs the relevant analysis, and spits out the result, but in a stackable manner.  Thus the title; I want to use the for loop's index to mark the array element for building a new array.
    See the image attached.  A 2D array of 9 columns (X, Y1...Y8) is analyzed such that each data set, (X, Y1), (X, Y2)...(X, Y8) is bundled, graphed, run through a B-spline Fit, of which is also graphed.  I need to replace this with something that looks like the for loop structure shown.  
    I just don't know how to get those two data bundles [(X, Yi) and it's smoothed pair] out of the for loop in a stacked set from every iteration of the for loop.
    Again the title, I think I want to build a new array where i use the index of the for loop to control the entries of the new array.  But I can't see how to do that.
    Any help would be appreciated.
    Attachments:
    NeedForLoopForThis.PNG ‏30 KB

    Hello H.R. Dunham, and welcome to the forum!
    It seems that you may be looking for Auto-Indexing, a basic feature of loops in LabVIEW.  You'll need to transpose your array before wiring it into the for loop, as elements are auto-indexed by row before column, but at that point you should be able to operate on each column and output an array of n cluster elements corresponding to your input columns.  Auto-indexing tunnels look like brackets to indicate each element will be indexed automatically- this should be the default when wiring an array into a for loop or when wiring anything out of a for loop.
    As for how to build your pairs, I suggest removing the X column and creating a "starter" cluster containing your X data and placeholder Y data before entering your "Y" processing loop.  Use the bundle by name function in the for loop to insert your processed column data into the cluster and auto-index the cluster output. Flow would be something like this:
    1) Gather data
    2) Split X and Y using standard array operations
    3) Create "template" cluster with shared X data
    4) Pass template cluster and Y-column array into an auto-indexed for loop.
    5) Insert processed Y data into cluster inside loop.
    6) Auto-index cluster data out of loop.
    This tutorial is probably also a good place to get started:
    Getting Started with NI LabVIEW Module 3: Loops
    http://www.ni.com/white-paper/7528/en/
    Hope that helps!
    Regards,
    Tom L.

  • How do u create a 2-dim. vector with a for loop(two for's) ?

    JTable is such a pain in the ass sometimes... you see i don't have a predifined number of elements to be stored in the JTable... so i have to pass a Vector[][] but i don't know how to create one in two for loops...
    Vector v[][] = new Vector[][];
    for(int i = 0; i< v.size(); i++){
    for (int j=0; j<v.size(); j++){
    v[i][j] = { "" + (u+1) , ((Team)c.get(array[u])).getName()),
    intoString(((Team)c.get(array.getPlayed()))),
    intoString(((Team)c.get(array[u].getHomeWins()))),
    intoString(((Team)c.get(array[u])).getHomeDraws()),
    intoString(((Team)c.get(array[u])).getHomeLosses()),
    intoString(((Team)c.get(array[u])).getHomeFor()),
    intoString(((Team)c.get(array[u])).getHomeAgainst()),
    intoString(((Team)c.get(array[u])).getAwayWins()),
    intoString(((Team)c.get(array[u])).getAwayDraws()),
    intoString(((Team)c.get(array[u])).getAwayLosses()),
    intoString(((Team)c.get(array[u])).getAwayFor()),
    intoString(((Team)c.get(array[u])).getAwayAgainst()) ,
    intoString(((Team)c.get(array[u])).getPoints()) } ;
    It doesnt work this way because my layout in JTable later needs to be like this....
    uuuuuu uuuuuuuuuuuuuu uuuuuuuuuuuu uuuuuuuuuu
    666666 66666666666666 666666666666 6666666666
    777777 77777777777777 77777777777 7777777
    .. and so and so... do u follow me ??
    Please help me if you can ....

    I might still be mising the point but here goes.
    According to the API ( http://java.sun.com/j2se/1.3/docs/api/index.html ) for JTable, the appropriate constructor is:
    public JTable(Vector rowData, Vector columnNames)
    I'm assuming that the JTable should have one column for each of the items - Name, Played, HomeWins etc. I'll also assume there is an array of Team objects containing the data (if I'm wrong the code should be easy to adjust).
    The columnnames Vector is self-explanatory - add a String object for each column.
    For rowData, you need a Vector of Vectors.
    e.g
    Vector rowData = new Vector[teamArray.length];
    for (int k = 0; k < teamArray.length; k ++) {
      Vector oneRow = new Vector();
      Team team = teamArray[k];
      oneRow.add(team.getName());
      oneRow.add(team.getPlayed());
      oneRow.add(team.getPoints());
      rowData[k] = oneRow;
    JTable table = new JTable(rowData, columnNames);

  • Indexing product data for embedded search for my shopping cart fiori app

    Hello Experts
    I'm doing indexing of product data records for SRM embedded search for My Shopping Cart Fiori app.
    however the job being created by the system to accomplish the task is, as error message displayed, not defined properly.
    any idea how to resolve this?
    i have no idea what program is this, and job details cannot be displayed/changed because of incomplete job definition.
    Appreciate any assistance pls.

    Hi Dex,
    Please check if there was a dump recorded in ST22. Also perform an authorization check SU53 for the background user that submits the job.
    Thanks,
    Vipin

  • How to index a array to give it to for loop for one value at a time sequence to be ensured

    I need to give one number from a array at a time to a for loop. means the for loop have to execute one number at a time  from a array of numbers. How to do it

    Ranjeet,
    Ranjeet_Singh wrote:
    But question is same only. is in it ?
    With all due respect, NO.
    Please make sure you know what you are talking about before blatantly countering someone else's comment. Can you prove that your vi and TiTou's snippet will do the same thing?
    Beginner? Try LabVIEW Basics
    Sharing bits of code? Try Snippets or LAVA Code Capture Tool
    Have you tried Quick Drop?, Visit QD Community.

  • Parallel for-loop for FPGA

    The new parallel for-loop feature for multi-core CPU is great, but does it support FPGA as well?  Since everything runs in parallel onthe FPGA, it would seem natural to do parrallel for-loop there.  I'm doing some time-critical vector multiplications that can be done quickly with parralel process, and I know I can MANUALLY put several parallel loops to speedup the process.  However as the length of the vector change, so would the number of parralel loops.  I'm wondering if there is a automatic process that does this for me.

    Will this help?

  • Search for Pattern using Java

    hello friends,
    I am trying to read a 'C' file and trying to look for all the lines in the 'C' cod, wherever a function call has happened. How could I do that ??
    Thanks
    ashu

    import java.io.*;
    import java.util.Scanner;
    import java.util.regex.Matcher;
    import java.util.regex.*;
    class FileParser{
        Scanner sc;
        FileParser(String fileName)throws FileNotFoundException{
         sc = new Scanner(new File(fileName));
        void getFunctions(){
         //sc.findInLine("([a-zA-Z]+) (\p{Punct})");
         sc.findInLine("");
         MatchResult result = sc.match();
         //for (int i=1; i<=result.groupCount(); i++)
            // System.out.println(result.group(i));//typo in API
         //System.out.println(result.group(1));
         //System.out.println(result.group(2));
        void getLoops(){
         //Search for patterns FOR, WHILE, DO-WHILE
         sc.findInLine("void");
         MatchResult result = sc.match();
         for (int i=0; i<=result.groupCount(); i++)
             System.out.println(result.group(i));
         /*     sc.findInLine("main");
         result = sc.match();
         for (int i=0; i<=result.groupCount(); i++)
             System.out.println(result.group(i));
         sc.findInLine("void");
         result = sc.match();
         for (int i=0; i<=result.groupCount(); i++)
             System.out.println(result.group(i));
        //Search for pattern FOR
        void getForLoops(){
        //Search for pattern WHILE
        void getWhileLoops(){
        //Search for pattern DO-WHILE
        void getDoWhileLoops(){
        //Search for Union
        //Search for Struct
    }I have added/deleted stuff to try all the different combinations. This class basically will have methods to ....
    1) Get a List of Function Calls with Line# in 'C' code
    2) Get a List of Loops with Line# in 'C' code
    import java.io.*;
    class TestScan{
        public static void main(String[] args)throws IOException{
         FileParser fp = new FileParser("main.c");
         //     fp.getFunctions();
         fp.getLoops();
    }Message was edited by:
    ashucool83

  • Paralleliz​ed for loop progress bar

    I have a for that takes a long time to execute and enabled parallelism to speed things up. I also want a progress bar. Before enabling parallelism, I simple had an indicator wired to the iteration counter and the array size that is being processed. This gave a good percent complete indicator. With the for loop parallelized, the indicator bounces around depending on which instance of the for loop happens to update the indicator. Is there a way to have an indicator inside a parallelized for loop?
    Solved!
    Go to Solution.

    altenbach wrote:
    A better idea is probably a simple action engine that increments with each call, incrementing an integer in a feedback node, and returns the total count. Since it is not reentrant, it will be shared by all loop instances.
    Here's a very quick draft. See if it works for you. (Warning, only use it in one FOR loop overall).
    Probably needs a few tweaks....
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ParallelProgress.zip ‏14 KB

  • A tunneled Excel refnum goes from a valid value to a NULL between iterations of a For Loop?

    How would a tunneled Excel refnum go from a valid value to a NULL between iterations of a For Loop?
    For
    some reason this works find in one VI and when executed and not in
    another.  Here's screen shots of the highlighted execution with probes
    appropriately. The "Open" refnum is passed into "Performance Test -
    Write Data To Files.vi".  That's where the trouble is.  You can see
    that it goes into the For Loop.  The first iteration is okay, but the
    second and subsequent iterations have the refnum NULL.  See images
    below.
    (I don't know how to delete an accidental double post, sorry)
    Message Edited by James DiLiberto on 01-22-2008 01:48 PM
    Attachments:
    Second Iteration1.jpg ‏158 KB
    First Iteration1.jpg ‏145 KB
    Second Iteration Error Dialog1.jpg ‏20 KB

    Is there any chance that the Insert Data Into Excel VI is closing the reference or that it is closed anywhere else (e.g. through a local or by having its owner destroyed)?
    I wouldn't expect the numeric value of the reference to change to 0, but since ActiveX is an external resource, I suppose that it's possible that the probe shows the number only if the resource is actually accessible.
    Try to take over the world!

  • For Loop with parameter in application process

    Hello,
    I am working on a project for school and a loop in an application process is giving me a headache. I have an application from which I make an ajax call to an "on-demand" process. Here's a short version of the process:
    declare
    valuesList varchar2(32000) := '';
    sqlWhere varchar2(32000) := '';
    begin
    begin
    //calculations, but let's hard code sqlWhere for demonstration purposes
    sqlWhere := ' where ID = 50';
    for j in (select * from myview sqlWhere) loop
    valuesList :=valuesList || '~rowsep~' || j.id || '~colsep~' || j.beds;
    end loop;
         exception
         when no_data_found then null;
         when others then HTP.p('Error: ' || SQLERRM);
    valuesList := substr(valuesList, 9, length(valuesList));
    end;
    htp.prn(valuesList);
    end;
    I thought the for loop would contain only one record but it lists all records in the view. Interestingly, when I replace the loop condition to 'select * from myview where ID = 50' it returns what it's supposed to.
    Could someone please explain what I am doing wrong?
    Thank you!

    There are a couple of different options but using a variable in the sql statement and not the where clause needs an execute immediate. The link below gives a good overview and options to accomplish what you are trying to do.
    execute immediate with for loop
    Edited by: tread on Apr 23, 2012 1:09 PM

  • Using CONTINUE-WHEN statement in FOR loop

    I'm trying to use CONTINUE-WHEN statement inside of a FOR loop. For example;
    FOR cnt IN 1 .. securityTable.COUNT LOOP
    CONTINUE WHEN cnt = 3;
    --do the job here...
    END LOOP;
    ... but it's not working. It gives me this error;
    "PLS-00103: Encountered the symbol "WHEN" when expecting one of the following:
    := . ( @ % ;"
    What can be the problem?

    In the first link there was "CONTINUE WHEN inside of the inner for loop" link and the reference gives this example
    <<outer_loop>>
    FOR i IN 1..10 LOOP
    -- Process data here
    FOR j IN 1..10 LOOP
    FETCH c1 INTO v_employees;
    CONTINUE outer_loop WHEN c1%NOTFOUND;
    -- Process data here
    END LOOP;
    END LOOP outer_loop;
    well; I'm not trying to "continue" the outer loop: I just want to "continue" the loop where CONTINUE-WHEN statement belongs to.
    I'm using Oracle 10g.

  • Nested For Loop Trouble?

    Ok I need to have a nested for loop that asks a user to enter in a int number from 1-50. Whatever the number is, lets say 4 I need the program to count up asterisk and count down asterisks, like this.
    This is my code:
    import java.io.*;
    public class Stars {
         static int n;
         static private InputStreamReader in = new InputStreamReader(System.in);
         static private BufferedReader br = new BufferedReader(in);
         public static void main(String[] Args)throws IOException
              System.out.println("Please enter in a number to see display: ");
              String num = br.readLine();
              n=Integer.parseInt(num);
              for(int i=1;i<=n;i++)
                   for(int j=1;j<=i;j++)
                        System.out.print("*");
                   for(int j=1;j<=i;j--)
                        System.out.print("*");
                   System.out.println();
    Can someone tell me what I am doing wrong so I can figure out my mistake(s).

    Ok, well I know that the loop relies on the number entered in by the user. So if i pick 3 the three enter in the loop and counts up in a for loop and for every number it counts up to the three it does a print("*"); Now what I am getting confused about is where the other for loop comes into play. I know that I need to start from the number I have which is 3, so I need to have one less than that and then count down. The thing is that i'm not sure where or how the second for loop gets implemented into the code. Does it get nested with the first loop like this:
    for(int i=1;i<=n;i++)
                   for(int j=1;j<=i;j++)
                            for(int j=n-1;j>=i;j--)
                        System.out.print("*");
                   System.out.println();
              }Or is the second for loop on its own like this:
    for(int i=1;i<=n;i++)
                   for(int j=1;j<=i;j++)
                        System.out.print("*");
                   for(int j=n-1;j>=i;j--)
                        System.out.print("*");
                   System.out.println();
              }If someone can help me understand, for this is my first time with nested for loops.

Maybe you are looking for

  • External Back up drive disappeared

    I noticed that TIme Machine had stopped backing up, so I looked to see what was happening and I was getting an error saying that the external hard drive I am using for my back up was having problems (sorry I can't remember the specifics right now) an

  • What hard drive would my mac mini early 2009 need if i wanted to upgrade it?

    i wanted to upgrade my hard drive will any hardrive fit it or has it got to be something special? please reply many thanks

  • Single tablespace or full database in 10g

    Hi, Which is the best regarding performance...what ever it may be...when doing hot backup...which is the best in all ways.. (a) putting single tablespace in backup mode and copying or (b) Putting total database in Backup mode and copying... can anybo

  • Inactivity timeout of connection pool - Sun ONE 7 and Oracle 8i

    Friends, I have a JDBC connection configured, looked up by JNDI working fine with servlets. The question is: I have a firewall between my appserver and the database server that closes all idle connections longer than 10 minutes. The appserver assumes

  • Outlook integration with flex

    Hi , I have a scenario in which I have to open an Outlook email window (of a specified size) on a button click, and the previously selected PDF file has to be automatically attached to that mail. can anybody help in this case ?