0

I am going to be using C to parallelise a giant task in python. The python script is available here. The attached script is the working prototype for a single density (dens) column. The next step is to turn this into a Monte Carlo simulation by calling 1000 new dens columns (sequentially) which are already created in files named 0001.txt - 1000.txt (each with one single column of dens values corresponding to the nodes).

Obviously the first step is to strip dens from the following line…

x1, x2, y1, y2, z1, z2, dens = np.loadtxt('nodes.txt', delimiter=' ', usecols=(0, 1, 2, 3, 4, 5, 6), unpack=True)

…which is easy enough. The following lines were created to solve the initial problem within the script itself, which give an idea of what I am trying to do…

x1, x2, y1, y2, z1, z2 = np.loadtxt('nodes.txt', delimiter=' ', usecols=(0, 1, 2, 3, 4, 5), unpack=True)
for i in range (1,1001):
    dens, = np.loadtxt('{:0>4}.txt'.format(i), delimiter=' ', usecols=(0), unpack=True

…but I have been informed that this will not allow for parallelisation on our cluster and I need to use something in the command line like…

python myscript.py 000.txt

My question is how would I code dens into the script so that the above command prompt would work?

I found this page which displays options like…

from subprocess import call
call([])

and

os.system

…but I am not entirely sure how to adapt it so that it is calling the correct variable to the correct place. Apologies if this is a simple solution, but I have been thrown into the deep end with python and I am still struggling to get my feet.

Community
  • 1
  • 1
Vlad
  • 135
  • 2
  • 13

1 Answers1

0

This answer shows you how to get the command line inputs from python:

import sys
print sys.argv

So you might use

filename = sys.argv[1]
dens, = np.loadtxt(filename, delimiter=' ', usecols=(0), unpack=True)

Of course, you should add your own error checking.

Community
  • 1
  • 1
Brian L
  • 3,201
  • 1
  • 15
  • 15