ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
To run a parallel chemistry program, I need to build the host list. The cluster already has SGE(grid engine) installed and it generates a host list file with the following contents:
The important bits are hostname(ex compute-1-1) and number of cpus to use(ex 2). And for this program, it wants them in this form, a shell variable: HOSTLIST=hostname:cpus=X hostname:cpus=X ....
I've tried this script, but it doesn't work
Code:
#!/bin/bash
spacer=":cpus="
let count=0
cat hostfile | while read line; do
HOSTS[$count]=$line
((count++))
done
NNODES=${#HOSTS[@]}
for ((i=0;i<$NNODES;i++)); do
host=`echo ${HOSTS[$i]}|cut -f1 -d" "`
cpus=`echo ${HOSTS[$i]}|cut -f2 -d" "`
HOSTS[$i]="$host$spacer$cpus"
done
for j in ${HOSTS[@]}
do
HOSTLIST=$HOSTLIST+$HOSTS[$j]
done
No, this would have ended up part of a larger script where HOSTLIST would have been referenced. The thing was while testing this snip of code, I would put in echo statements to watch the variables and NNODES would come up as zero and I don't know why.
No, this would have ended up part of a larger script where HOSTLIST would have been referenced. The thing was while testing this snip of code, I would put in echo statements to watch the variables and NNODES would come up as zero and I don't know why.
Hmmm ... it worked here, w/ echoes strewn in.
Maybe your file had DOS line endings or something, as opposed to what you
copy & pasted here?
Code:
~/tmp$ time ./host.sh
compute-1-1.local:cpus=2 compute-2-1.local:cpus=2
real 0m0.013s
user 0m0.006s
sys 0m0.004s
Code:
~/tmp$ time export HOSTLIST=$( awk '{printf "%s:cpus=%s ",$1, $2}' hostlist )
real 0m0.005s
user 0m0.002s
sys 0m0.002s
~/tmp$ echo $HOSTLIST
compute-1-1.local:cpus=2 compute-2-1.local:cpus=2
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.