Difference between revisions of "Rocky Python Prime"

From NIMBioS
m
 
(One intermediate revision by the same user not shown)
Line 26: Line 26:


'''python-prime.run'''
'''python-prime.run'''
<pre>
#!/bin/bash
#!/bin/bash
<pre>
#SBATCH --job-name=PYTHON_PRIME
#SBATCH --job-name=PYTHON_PRIME
#SBATCH --output=python_prime_%j.out
#SBATCH --output=python_prime_%j.out
Line 42: Line 42:
[test_user@rocky7 prime]$ pwd
[test_user@rocky7 prime]$ pwd
/home/test_user/projects/python/prime
/home/test_user/projects/python/prime
</pre>
 
<pre>
[test_user@rocky7 prime]$ ls
[test_user@rocky7 prime]$ ls
prime.py  python-prime.run
prime.py  python-prime.run
</pre>
 
<pre>
[test_user@rocky7 prime]$ sbatch python-prime.run  
[test_user@rocky7 prime]$ sbatch python-prime.run  
Submitted batch job 3877
Submitted batch job 3877

Latest revision as of 02:15, 29 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