Configuring a New Parallel Environment of SGE

Configuring a New Parallel Environment

Since this seems to be a regular topic on the user mailing list, here’s a quick guide to setting up a parallel environment on Grid Engine:

  1. First, create/borrow/steal the startup and shutdown scripts for the parallel environment you’re using. You can find MPI and PVM scripts in the $SGE_ROOT/mpi and $SGE_ROOT/pvm directories, respectively. If you cannot find scripts for your parallel environment, you’ll have to create them. The startup script must prepare the parallel environment for being used. With most MPI implementations, that’s just a matter of creating a “machines” file that lists the machines which are to run the parallel job. The shutdown script must clean up after the parallel job’s execution. The MPI shutdown script just deletes the “machines” file.

  2. Next, you have to tell Grid Engine about your parallel environment. You can do that interactively with qmon or qconf -ap <pe_name> or you can write the data to a file and use qconf -Ap <file_name>. For an example of what such a file would look like, see $SGE_ROOT/mpi/mpi.template or $SGE_ROOT/pvm/pvm.template.

    Let’s look at what the parallel environment configuration contains.

    pe_name           template
    slots             0
    user_lists        NONE
    xuser_lists       NONE
    start_proc_args   /bin/true
    stop_proc_args    /bin/true
    allocation_rule   $pe_slots
    control_slaves    FALSE
    job_is_first_task FALSE
    urgency_slots     min
    • pe_name – the name by which the parallel environment will be known to Grid Engine

    • slots – the maximum number of job slots that the parallel environment is allowed to occupy at once

    • users_lists – an ACL specifying the users who are allowed to use the parallel environment. If set to NONE, it means any user can use it

    • xusers_list – an ACL specifying the users who are not allowed to use the parallel environment. Users in both the users_list and xusers_list are not allowed to use the parallel environment

    • start_proc_args – the path to the startup script for the parallel environment followed by any needed arguments. Grid Engine provides some inline variables that you can use as arguments:

      • $pe_hostfile – the path to a file written by Grid Engine which contains information about how and where the parallel job should be run
      • $host – the host on which the parallel environment is being started
      • $job_owner – the name of the user who owns the parallel job
      • $job_id – the id of the parellel job
      • $job_name – the name of the parallel job
      • $pe – the name of the parallel environment
      • $pe_slots – the number of job slots assigned to the job
      • $queue – the name of the queue in which the parallel job is running

      The value of this setting is the command that will be run to start the parallel environment for every parallel job.

    • stop_proc_args – the path to the shutdown script for the parallel environment followed by any needed arguments. The same inline variables are available as with start_proc_args.

    • allocation_rule – this setting controls how job slots are assigned to hosts. It can have four possible values:

      • a number – if set to a number, Grid Engine will assign that many slots to the parallel job on each host until the assigned number of job slots is met. Setting this attribute to 1, for example, would mean that the job gets a single job slot on each host where it is assigned. Grid Engine will not assign the job more job slots than the number of assigned hosts multiplied by this attribute’s value.

      • $fill_up – use all of the job slots on a given host before moving to the next host

      • $round_robin – select one slot from each host in a round-robin fashion until all job slots are assigned. This setting can result in more than one job slot per host.

      • $pe_slots – place all the job slots on a single machine. Grid Engine will only schedule such a job to a machine that can host the maximum number of slots requested by the job. (See below.)

    • control_slaves – this setting tells Grid Engine whether the parallel environment integration is “tight” or “loose”. See your parallel environment’s documentation for more details.

    • job_is_first_task – this setting tells Grid Engine whether the first task of the parallel job is actually a job task or whether it’s just there to kick off the rest of the jobs. This setting is also determined by your parallel environment integration.

    • urgency_slots – this setting affect how resource requests affect job priority for parallel jobs. The values can be “min,” “max,” “avg,” or a number. For more information about resource-based job priorities, see this white paper

    For more information about these settings, see the sge_pe man page.

  3. The next step is to enable your parallel environment for the queues where it should be available. You can add the parallel environment to a queue interactively with qmon or qconf -mq <queue> or in a single action with qconf -aattr queue pe_list <pe_name> <queue>.

  4. Now you’re ready to test your parallel environment. Run qsub -pe <pe_name> <slots>. Aside from the usual output and error files (<job_name>.o<job_id> and <job_name>.e<job_id>, respectively), you should also look for the parallel environment startup output and error files, <job_name>.po<job_id> and <job_name>.pe<job_id>.

That’s all there is to it! Just to make sure we’re clear on everything, let’s do an example. Let’s create a parallel environment that starts up an RMI registry and stores the port number in a file so that the job can find it.

First thing we have to do is write the startup and shudown scripts for the RMI parallel environment. Here’s what they look like:

rmi_startup.sh
#!/bin/sh
# $TMPDIR and $JOB_ID are set by Grid Engine automatically

# Borrowed from $SGE_ROOT/mpi/startmpi.sh
PeHostfile2MachineFile()
{
   cat $1 | while read line; do
      host=`echo $line|cut -f1 -d" "|cut -f1 -d"."`
      nslots=`echo $line|cut -f2 -d" "`
      i=1

      while [ $i -le $nslots ]; do
         echo $host
         i=`expr $i + 1`
      done
   done
}

# get arguments
pe_hostfile=$1

# ensure pe_hostfile is readable
if [ ! -r $pe_hostfile ]; then
   echo "$me: can't read $pe_hostfile" >&2
   exit 1
fi

# create machines file
machines="$TMPDIR/machines"
PeHostfile2MachineFile $pe_hostfile >> $machines

# We use ports 40000-40999
port=`expr \( $JOB_ID % 1000 \) + 40000`

# Start the registry
/usr/java/bin/rmiregistry $port &

# Save the registry's PID so that we can stop it later
echo $! > $TMPDIR/pid

# Save the port number so the job can find it
echo $port > $TMPDIR/port
rmi_shutdown.sh
#!/bin/sh
# $TMPDIR is set by Grid Engine automatically

# Get the registry's PID
pid=`cat $TMPDIR/pid`

# Kill the registry
kill $pid

# Clean up the files the startup script created
rm $TMPDIR/pid
rm $TMPDIR/port
rm $TMPDIR/machines

Next thing we have to do is add our parallel environment to Grid Engine. First we create a file, say /tmp/rmi_pe, with the following contents:

pe_name           rmi
slots             4
user_lists        NONE
xuser_lists       NONE
start_proc_args   /home/dant/rmi_startup.sh $pe_hostfile
stop_proc_args    /home/dant/rmi_shutdown.sh
allocation_rule   $round_robin
control_slaves    TRUE
job_is_first_task FALSE
urgency_slots     min

Note that control_slaves is true and job_is_first_task is false. Because we’re writing the integration scripts, the choice is somewhat arbitrary, but it affects how the job scripts must be written, as we’ll see below. It also affect whether the qmaster is able to keep accounting records on the slave tasks. If control_slaves is false, the qmaster is have no records of how much resources the slaves tasks consumed.

Now we add the parallel environment with qconf -Ap /tmp/rmi_pe. We could have skipped a step by running qconf -ap rmi and entering the data in the editor that comes up, but they way we’ve done it here is scriptable.

The next step is to add our parallel environment to our queue with qconf -aattr queue pe_list rmi all.q. Again, we could have run qconf -mq all.q and edited the pe_list attribute in the editor, but the way we’ve done it is scriptable.

Last thing to do is test out our parellel environmemt. First we need a job script:

#!/bin/sh
#$ -S /bin/sh

port=`cat $TMPDIR/port`
qrsh=$SGE_ROOT/bin/$ARC/qrsh

cat $TMPDIR/machines | while read host; do
   $qrsh -inherit $host /usr/bin/java -cp ~/rmi.jar RMIApp $port &
done

Let’s look at this job script for a moment. The first thing to notice is the use of qrsh -inherit. The -inherit switch is specifically for kicking off slave tasks. It requires that the target host name be supplied. In order to get the target host name, we read the machines file that the startup script generated from the one Grid Engine supplied.

The second thing to notice is how ugly the use of qrsh -inherit is. RMI is not really a parallel environment. It’s a communications framework. It doesn’t do the work of kicking off remote processes for you. So, instead, we have to do it ourselves in the job script. With a true parallel environment, like any of the MPI flavors, the framework also takes care of starting the remote processes, often through rsh. In the MPI scripts included with Grid Engine, an rsh wrapper script is included, which transparently replaces calls to rsh with calls to qrsh -inherit. By using that wrapper script, the parallel environment’s calls to rsh can be rerouted through the grid via qrsh without having to modify the parallel environment itself to work with Grid Engine.

The last thing to notice is how this script correlates to the control_slaves and job_is_first_task attributes of the parallel environment configuration. Let’s start with first_job_is_task. In our configuration, we set it to false. That means that this master job script is not counted as a job and does no real work. That is why our script doesn’t do anything but kick off sub-tasks. If job_is_first_task had been true, our job script would be expected to run one of the RMIApp instances itself.

Now let’s talk about the control_slaves attribute. If control_slaves is true, we are allowed to use qrsh -inherit to kick off our sub-tasks. The qmaster will not, however, allow us to kick off more subtasks than the number of slots we’ve been assigned (minus 1 if job_is_first_task is true). The advantage of using qrsh -inherit is that the sub-tasks are tracked by Grid Engine like regular jobs. If control_slaves is false, we have to use some mechanism external to Grid Engine, such as rsh or ssh, to kick off our sub-tasks, meaning that Grid Engine cannot track them and is actually fully unaware of them. That’s why job_is_first_task is meaningless when control_slaves is false.

In order to test our job we need a Java application called RMIApp. As that’s outside the scope of the example, let’s just pretend we have a parallel Java application that uses the RMI registry for intra-process communication. To submit our job we use qsub -pe rmi 2-4 rmi_job.sh. The -pe rmi 2-4 argument tells the qmaster that we’re using the rmi parallel environment and we want 4 job slots assigned to our job, but we will accept as few as 2. Because our job script starts a sub-task for every entry in to host file, it will start the right number of sub-tasks, no matter how many slots we are assigned. Had we written the job script to start exactly two sub-tasks, we would have to use -pe rmi 2 so that we could be sure we got exactly two job slots.

While the job is running, run qstat -f. You’ll see output something like this:

% qstat -f
queuename                      qtype used/tot. load_avg arch          states
----------------------------------------------------------------------------
all.q@ultra20                  BIP   4/10      0.08     sol-amd64
    253 0.55500 rmi_job.sh dant         r     03/23/2007 11:46:51     4

From this output we can see that the job has been scheduled and has been assigned four job slots. Those four job slots only account for the four sub-tasks. The master job itself is not counted because the job_is_first_task attribute is false.

After our job completes, if we look in our home directory (which is where Grid Engine will put the output files since we didn’t tell it otherwise), we will find four new files: rmi_job.sh.e253, rmi_job.sh.o253, rmi_job.sh.pe253, and rmi_job.sh.o253, assuming, of course, that our job was number 253. The *.o253 and *.e253 files should be familiar. They’re the output and error streams from the job script. The *.po253 and *.pe253 files are new. They’re the output and error streams from the parallel environment startup and shutdown scripts.

So, there you have it. A complete, top-to-bottom example of creating, configuring, and running a parallel environment.

서진우

슈퍼컴퓨팅 전문 기업 클루닉스/ 상무(기술이사)/ 정보시스템감리사/ 시스존 블로그 운영자

You may also like...

21 Responses

  1. erika 말해보세요:

    hai, i try to submit job.sge, the script is

    #!/bin/bash
    #
    # SGE queue system job script that requests some four-core nodes
    # and runs a quick program on them.
    # SGE directives begin with #$ in column 1
    # o Directive # #$ -j y
    # means put standard output and standard error in the same file.
    # o Directive #$ -cwd
    # means start the job in the directory from which it was
    # submitted.
    # o Directive #$ -pe mpich_mx 60
    # means run with exactly 60 “slots” using the parallel
    # environment defined by the keyword “mpich_mx”. This gives
    # the job 60 CPU’s with the CPU’s selected to be on the
    # minimum number of nodes.
    # To list available parallel environments use the command
    # qconf -spl
    # o Directive #$ -N sge_demo_001
    # means name this job “sge_demo_001”.
    #
    #$ -j y
    #$ -cwd
    #$ -pe mpich_mx 60
    #$ -N sge_demo_001
    #$ -o sge_demo_001.out
    #
    # Lots more SGE information can be found by reading
    # the SGE man pages – see
    # man qsub
    # man qconf
    # man sge_pe
    # However, these are very dense reading.
    #
    echo ‘*********************************************************’
    THEDATE=`date`
    echo ‘Start job ‘$THEDATE
    echo ‘NHOSTS = ‘$NHOSTS
    echo ‘NSLOTS = ‘$NSLOTS
    echo ‘======= PE_HOSTFILE =======’
    cat $PE_HOSTFILE
    echo ‘===========================’
    echo ‘======= $TMPDIR/machines ====’
    cat $TMPDIR/machines

    # Add modules (broken at the moment)
    source /etc/profile.d/modules.sh
    module load intel
    module load mpich-mx
    # export PATH=${PATH}:/opt/intel/fce/9.1.051/bin

    # Create test directory
    \rm -fr sge_job_${JOB_ID}.d
    mkdir sge_job_${JOB_ID}.d
    cd sge_job_${JOB_ID}.d

    # Compile MPI program
    cp ../mpi_hello_world.F90 .
    echo ‘Using mpi compiler script ‘`which mpif90`
    mpif90 mpi_hello_world.F90

    # Run MPI program
    echo ‘Using mpi launcher script’`which mpirun`
    mpirun -v \
    -np ${NSLOTS} -machinefile $TMPDIR/machines \
    –mx-kill 30 –mx-copy-env ./a.out

    echo ‘===========================’
    echo ‘End job ‘$THEDATE
    echo ‘*********************************************************’

    the job is submit and then its work, but itsn’t finish.The last status is 1 of my node is ‘E’. i try to use qmod -c ‘*’ to fix it and then try it again but it’s always the same thing is happen again. do you have any idea of it please?

  2. 서진우 말해보세요:

    hi! Your Job Submit Script grammar is judged that the normal.
    Rather than the other SGE is expected to set the environment.
    The following methods are recommended to check a few.

    method 1.

    $ qconf -sp mpich_mx
    —————————————————————————–

    pe_name mpich_mx
    slots 60 <--check user_lists NONE xuser_lists NONE start_proc_args $SGE_ROOT/mpi/startmpi.sh -catch_rsh $pe_hostfile <- check stop_proc_args $SGE_ROOT/mpi/stopmpi.sh <- check allocation_rule $fill_up <- check ( $fill_up or $round_robin ) control_slaves TRUE job_is_first_task FALSE urgency_slots min method 2. $ qstat -j
    .
    .
    error reason 1: ???? <- error message check .. I hope you solve the problem. bye..

  1. 2023년 6월 13일

    … [Trackback]

    […] Info to that Topic: nblog.syszone.co.kr/archives/3707 […]

  2. 2023년 8월 6일

    … [Trackback]

    […] Read More to that Topic: nblog.syszone.co.kr/archives/3707 […]

  3. 2023년 8월 30일

    … [Trackback]

    […] Information on that Topic: nblog.syszone.co.kr/archives/3707 […]

  4. 2023년 8월 30일

    … [Trackback]

    […] Read More Information here to that Topic: nblog.syszone.co.kr/archives/3707 […]

  5. 2023년 9월 10일

    … [Trackback]

    […] Info to that Topic: nblog.syszone.co.kr/archives/3707 […]

  6. 2023년 10월 22일

    … [Trackback]

    […] Read More on to that Topic: nblog.syszone.co.kr/archives/3707 […]

  7. 2023년 10월 23일

    … [Trackback]

    […] Find More on to that Topic: nblog.syszone.co.kr/archives/3707 […]

  8. 2023년 11월 13일

    … [Trackback]

    […] Find More Info here on that Topic: nblog.syszone.co.kr/archives/3707 […]

  9. 2023년 11월 23일

    … [Trackback]

    […] Read More to that Topic: nblog.syszone.co.kr/archives/3707 […]

  10. 2023년 12월 8일

    … [Trackback]

    […] Read More on that Topic: nblog.syszone.co.kr/archives/3707 […]

  11. 2023년 12월 18일

    … [Trackback]

    […] Find More to that Topic: nblog.syszone.co.kr/archives/3707 […]

  12. 2024년 1월 28일

    … [Trackback]

    […] There you will find 91682 more Information to that Topic: nblog.syszone.co.kr/archives/3707 […]

  13. 2024년 1월 29일

    … [Trackback]

    […] Find More to that Topic: nblog.syszone.co.kr/archives/3707 […]

  14. 2024년 1월 30일

    … [Trackback]

    […] Find More to that Topic: nblog.syszone.co.kr/archives/3707 […]

  15. 2024년 3월 2일

    … [Trackback]

    […] Find More Info here on that Topic: nblog.syszone.co.kr/archives/3707 […]

  16. 2024년 3월 11일

    … [Trackback]

    […] Here you will find 34329 additional Info on that Topic: nblog.syszone.co.kr/archives/3707 […]

  17. 2024년 3월 12일

    … [Trackback]

    […] Here you will find 85563 more Info on that Topic: nblog.syszone.co.kr/archives/3707 […]

  18. 2024년 3월 12일

    … [Trackback]

    […] Read More Information here to that Topic: nblog.syszone.co.kr/archives/3707 […]

  19. 2024년 3월 18일

    … [Trackback]

    […] Find More here to that Topic: nblog.syszone.co.kr/archives/3707 […]

erika 에 응답 남기기 응답 취소