Difference between revisions of "Programming/Python"

From HPC
Jump to: navigation , search
m
m
Line 1: Line 1:
 
== Programming Details ==
 
== Programming Details ==
  
Python is a widely used high-level programming language used for general-purpose programming.
 
  
 
An interpreted language, Python has a design philosophy which emphasizes code readability (notably using whitespace indentation to delimit code blocks rather than curly braces or keywords), and a syntax which allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java. scale.
 
An interpreted language, Python has a design philosophy which emphasizes code readability (notably using whitespace indentation to delimit code blocks rather than curly braces or keywords), and a syntax which allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java. scale.

Revision as of 14:25, 30 January 2017

Programming Details

An interpreted language, Python has a design philosophy which emphasizes code readability (notably using whitespace indentation to delimit code blocks rather than curly braces or keywords), and a syntax which allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java. scale.

When programming with Python in a HPC environment you will need to change the first line from:

 #!/usr/bin/python

To

 #!/usr/bin/env python

Note due to the limited of the Python interpreter (GIL) there is no point to use threads for CPU intensive tasks in Python. You need either multiprocessing or use C extensions that release GIL during computations e.g., some of numpy functions, example.


Usage Examples

Batch example

 
#!/bin/bash
#SBATCH -J compute-single-node
#SBATCH -N 1
#SBATCH --ntasks-per-node 20
#SBATCH -D /home/pysdlb/PYTHON
#SBATCH -o %N.%j.%a.out
#SBATCH -e %N.%j.%a.err
#SBATCH -p compute
#SBATCH --exclusive

echo $SLURM_JOB_NODELIST

module purge
module load anaconda/4.0
module load openmpi/gcc/1.10.2

export I_MPI_DEBUG=5
export I_MPI_FABRICS=shm:tmi
export I_MPI_FALLBACK=no

mpirun python broadcast.py


[username@login01 ~]$ sbatch python-demo.job
Submitted batch job 289572