Difference between revisions of "Rocky Python Prime"
From NIMBioS
Line 26: | Line 26: | ||
'''python-prime.run''' | '''python-prime.run''' | ||
#!/bin/bash | |||
<pre> | <pre> | ||
#SBATCH --job-name=PYTHON_PRIME | #SBATCH --job-name=PYTHON_PRIME | ||
Line 34: | Line 35: | ||
python3 prime.py | python3 prime.py | ||
</pre> | </pre> | ||
= Running Job = | = Running Job = |
Revision as of 20:36, 10 April 2023
Python Code
prime.py
MIN = 2 MAX = 100000 def is_prime(num): if num <= 1: return False else: for i in range(2, num): if (num % i) == 0: return False return True for i in range(MIN, MAX+1): if is_prime(i): print(i)
Batch Script
python-prime.run
- !/bin/bash
#SBATCH --job-name=PYTHON_PRIME #SBATCH --output=python_prime_%j.out module load Python python3 prime.py
Running Job
[test_user@rocky7 prime]$ pwd /home/test_user/projects/python/prime
[test_user@rocky7 prime]$ ls prime.py python-prime.run
[test_user@rocky7 prime]$ sbatch python-prime.run Submitted batch job 3877
Here we can see the job was assigned to moose1.
[test_user@rocky7 prime]$ squeue JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON) 3877 compute_all PYTHON_P test_user R 0:02 1 moose1
Once job is no longer listed in the queue:
[test_user@rocky7 prime]$ ls prime.py python-prime.run python_prime_3877.out
[test_user@rocky7 prime]$ cat python_prime_3877.out 2 3 5 7 11 ...<truncated>... 99881 99901 99907 99923 99929 99961 99971 99989 99991