Rocky Python Prime

From NIMBioS
Revision as of 20:36, 10 April 2023 by Jstratt7 (talk | contribs)

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

  1. !/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