My first job

Examples

Submit a simple MPI job

  • On this example we run a small MPI application doing the following steps:

    • Create a submission file
    • Submit the job to the default queue
    • Load the correct software
    • Execute a simple MPI code
    • Check the status of the job
    • Read the output
  • Create a submission file

vi my_first_job_submit.sh
  • Edit the file

#!/bin/bash

# Call the MPI environment, selecting two cores 
#$ -pe mpi 2

# Choose the queue hpc (OPTIONAL). If you leave this option empty system will assume the default queue
#$ -q hpc

# Load software modules (Open MPI 2.1.0 and GCC compiler 7.3). Please check session software for the details
source /etc/profile.d/modules.sh
module load openmpi-2.1.0 
module load gcc-7.3


# Compile application 
echo "=== Compiling ===" 
mpicc -o cpi cpi.c

# Run application. Please note that the number of cores used by MPI must be same as the ones requested.
echo "=== Running ==="
mpirun -np $NSLOTS cpi

  • Submit the job
qsub my_first_job_submit.sh

Your job 75463 ("my_first_job_submit.sh") has been submitted
  • Check status of the job
 
 [jpina@hpc7 ~]$ qstat 
job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID 
-----------------------------------------------------------------------------------------------------------------
  75463 0.15016 my_first_j jpina        qw    04/30/2019 11:55:55                                    2        
[jpina@hpc7 ~]$ 


State qw means jobs waiting

  • Check further details about your job (very long output)
qstat -j 75463 
[jpina@hpc7 ~]$ qstat 
job-ID  prior   name       user         state submit/start at     queue                          slots ja-task-ID 
-----------------------------------------------------------------------------------------------------------------
  76877 0.68130 my_first_j jpina        r     04/30/2019 12:03:38 hpc@hpc046.ncg.ingrid.pt           2        

State r means job running

[jpina@hpc7 ~]$ qstat 

empty no jobs running under your user (all finished)

  • Read the output of the job:

For each job you will have an output and error file produced (if you use parallel environment you will receive an additional pair of files) at thte directory where you submited you job:

rw-r-----+  1 jpina csys        0 Apr 30 13:48 my_first_job_submit.sh.e77285
-rw-r-----+  1 jpina csys      186 Apr 30 13:48 my_first_job_submit.sh.o77285
-rw-r-----+  1 jpina csys        0 Apr 30 13:48 my_first_job_submit.sh.pe77285
-rw-r-----+  1 jpina csys        0 Apr 30 13:48 my_first_job_submit.sh.po77285

Reading the output of the job:

[jpina@hpc7 jpina]$ cat my_first_job_submit.sh.o77285
=== Compiling ===
=== Running ===
Hello world from processor hpc046.ncg.ingrid.pt, rank 0 out of 2 processors
Hello world from processor hpc046.ncg.ingrid.pt, rank 1 out of 2 processors

Other usefull commands

  • Delete you job (in case of issue)
[jpina@hpc7 ~]$ qdel 75463
jpina has deleted job 75463 
  • Check all jobs running in cluster
qstat -u '*' 
  • Check all queues even those user not allowed to run:
qstat -g c

My MPI example:

[jpina@hpc7 jpina]$ cat cpi.c
#include <mpi.h>
#include <stdio.h>

int main(int argc, char** argv) {
    // Initialize the MPI environment
    MPI_Init(NULL, NULL);

    // Get the number of processes
    int world_size;
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);
    
    // Get the rank of the process
    int world_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);

    // Get the name of the processor
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    int name_len;
    MPI_Get_processor_name(processor_name, &name_len);
    
    // Print off a hello world message
    printf("Hello world from processor %s, rank %d out of %d processors\n",
    processor_name, world_rank, world_size);
    
    // Finalize the MPI environment.
    MPI_Finalize();
    }