You are not logged in.

#1 2009-11-22 23:47:00

kazuo
Member
From: São Paulo/Brazil
Registered: 2008-03-18
Posts: 413
Website

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?

Offline

#2 2009-11-23 00:29:10

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Parallelized for loop. Searching for a one-line solution

Offline

Board footer

Powered by FluxBB