Skip to content

Commit 80fbda1

Browse files
Merge pull request #281 from coding-for-reproducible-research/280-update-parallel-computing
Update parallel computing material
2 parents 23d3455 + 7b0054c commit 80fbda1

27 files changed

+811
-216
lines changed

_toc.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,13 @@ parts:
251251
- file: individual_modules/introduction_to_hpc/exploiting_slurm
252252
- file: individual_modules/section_landing_pages/parallel_computing
253253
sections:
254-
- file: individual_modules/parallel_computing/hello_world
255-
- file: individual_modules/parallel_computing/simple_communication
256-
- file: individual_modules/parallel_computing/collective_comms
257-
- file: individual_modules/parallel_computing/parallel_fractal
254+
- file: individual_modules/parallel_computing/architecture_and_concurrency
255+
- file: individual_modules/parallel_computing/multithreading_io
256+
- file: individual_modules/parallel_computing/multiprocessing_fractal
257+
- file: individual_modules/parallel_computing/mpi_hello_world
258+
- file: individual_modules/parallel_computing/mpi_simple_communication
259+
- file: individual_modules/parallel_computing/mpi_collective_comms
260+
- file: individual_modules/parallel_computing/mpi_parallel_fractal
258261
- file: course_homepages/software_development
259262
sections:
260263
- file: individual_modules/section_landing_pages/software_development_best_practice

course_homepages/high_performance_computing.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"\n",
5050
"[Clickable Link to Self Study Notes](../individual_modules/section_landing_pages/parallel_computing.md)\n",
5151
"\n",
52-
"The course offers an in-depth understanding of distributed and shared-memory parallelism, enabling participants to explain these concepts clearly. Students will learn to write software that runs across multiple processes using MPI and develop code that utilizes multithreading for parallel execution. Additionally, the course focuses on effectively dividing and parallelizing problems, providing hands-on experience in writing and optimizing parallel code."
52+
"The course offers an introductory understanding of shared memory and distributed-memory parallelism, enabling participants to explain these concepts clearly. Students will learn to write software that runs across multiple threads and processes using Python's multithreading annd multiprocessing modules. They will also learn how to use message passing on distributed memory systems with MPI. Additionally, the course focuses on effectively dividing and parallelizing problems, providing hands-on experience in writing and optimizing parallel code."
5353
]
5454
}
5555
],

individual_modules/parallel_computing/architecture_and_concurrency.ipynb

Lines changed: 187 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
import requests
3+
4+
5+
def download_all_sites(sites):
6+
with requests.Session() as session:
7+
for url in sites:
8+
download_single_site(url, session)
9+
10+
11+
def download_single_site(url, session):
12+
with session.get(url) as response:
13+
print(f"Read {len(response.content)} bytes from {url}")
14+
15+
16+
# Create list of site to download
17+
sites = [
18+
"https://www.exeter.ac.uk/research/research-software-and-analytics/",
19+
"https://coding-for-reproducible-research.github.io/CfRR_Courses/home_page.html",
20+
] * 100
21+
22+
23+
# Report time for downloading all sites
24+
start_time = time.perf_counter()
25+
download_all_sites(sites)
26+
run_time = time.perf_counter() - start_time
27+
print(f"Downloaded {len(sites)} sites in {run_time} seconds")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import threading
2+
import time
3+
from concurrent.futures import ThreadPoolExecutor
4+
import requests
5+
6+
thread_local = threading.local()
7+
8+
9+
def download_all_sites(sites):
10+
with ThreadPoolExecutor(max_workers=5) as executor:
11+
executor.map(download_single_site, sites)
12+
13+
14+
def download_single_site(url):
15+
session = get_session_for_thread()
16+
with session.get(url) as response:
17+
print(f"Read {len(response.content)} bytes from {url}")
18+
19+
20+
def get_session_for_thread():
21+
if not hasattr(thread_local, "session"):
22+
thread_local.session = requests.Session()
23+
return thread_local.session
24+
25+
26+
# Create list of site to download
27+
sites = [
28+
"https://www.exeter.ac.uk/research/research-software-and-analytics/",
29+
"https://coding-for-reproducible-research.github.io/CfRR_Courses/home_page.html",
30+
] * 100
31+
32+
# Report time for downloading all sites
33+
start_time = time.perf_counter()
34+
download_all_sites(sites)
35+
run_time = time.perf_counter() - start_time
36+
print(f"Downloaded {len(sites)} sites in {run_time} seconds")
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import psutil
2+
3+
def get_cpu_info():
4+
"""Retrieves CPU specifications and usage."""
5+
6+
try:
7+
# Get CPU count
8+
cpu_count = psutil.cpu_count(logical=False) # Get physical cores
9+
cores = psutil.cpu_count(logical=True) # Get logical cores
10+
cpu_usage = psutil.cpu_percent() # Get overall CPU usage
11+
12+
return f"CPU: {cpu_count} physical cores, {cores} logical cores\nCPU Usage: {cpu_usage}%"
13+
14+
except Exception as e:
15+
print(f"Error getting CPU info: {e}")
16+
return None
17+
18+
def get_ram_info():
19+
"""Retrieves memory information."""
20+
21+
try:
22+
memory_info = psutil.virtual_memory() # Get virtual memory usage
23+
total_memory_gb = memory_info.total / (1024**3) # Convert to GB
24+
available_memory_gb = memory_info.available / (1024**3) # Convert to GB
25+
used_memory_gb = memory_info.used / (1024**3) # Convert to GB
26+
27+
return f"RAM: Total {total_memory_gb:.2f} GB, Available {available_memory_gb:.2f} GB, Used {used_memory_gb:.2f} GB"
28+
29+
except Exception as e:
30+
print(f"Error getting RAM info: {e}")
31+
return None
32+
33+
print(get_cpu_info())
34+
print(get_ram_info())
35+

0 commit comments

Comments
 (0)