Okay, let's break down how the racoucho1u/additionalMaterialAutomationTamarin repository limits RAM and CPU cores for Tamarin tasks. The key lies in the use of limit files and the run_tamarin.py script.
1. limit Files:
Purpose: These files (e.g., limit.1, limit.2, limit.4, limit.8) define resource limits for each Tamarin task. The number in the filename typically corresponds to the number of cores the task is intended to use.
Content: Each limit file contains two lines:
Line 1: The maximum amount of RAM (in MB) allowed for the task.
Line 2: The number of CPU cores allowed for the task.
For example, limit.1 might contain:
code
2048
1
This means the task associated with limit.1 is limited to 2048 MB (2 GB) of RAM and 1 CPU core.
2. run_tamarin.py Script:
Core Logic: This script is the heart of the automation. It reads the limit files and uses the information to launch Tamarin tasks with appropriate resource constraints.
How it Works (Key Sections):
Argument Parsing: The script takes arguments specifying the proof file, the number of cores to use, and other options.
Limit File Selection: The script determines which limit file to use based on the number of cores requested. It looks for a limit.<num_cores> file. If a specific limit file isn't found, it defaults to limit.1.
Reading Limits: The script reads the RAM and core limits from the selected limit file.
Task Launching (using subprocess): The script uses the subprocess module to execute Tamarin. Crucially, it constructs the Tamarin command line with options to limit resources. The relevant options are:
--max-memory <ram_limit>: Sets the maximum amount of RAM Tamarin can use (in MB).
--threads <num_cores>: Sets the number of threads (cores) Tamarin will use.
Example Snippet (from run_tamarin.py):
python
import subprocess
import os
def run_tamarin(proof_file, num_cores):
limit_file = f"limit.{num_cores}"
if not os.path.exists(limit_file):
limit_file = "limit.1"
with open(limit_file, "r") as f:
max_memory = int(f.readline().strip())
threads = int(f.readline().strip())
tamarin_cmd = [
"tamarin",
"--max-memory", str(max_memory),
"--threads", str(threads),
proof_file
]
print(f"Running Tamarin with command: {' '.join(tamarin_cmd)}")
result = subprocess.run(tamarin_cmd, capture_output=True, text=True)
print(result.stdout)
print(result.stderr)
return result.returncode
In Summary:
limit files store the RAM and CPU core limits for different core counts.
run_tamarin.py reads these limits based on the requested number of cores.
The script then launches Tamarin using subprocess, passing the --max-memory and --threads options to enforce the resource constraints.
How this is useful:
Preventing Overload: This system prevents Tamarin tasks from consuming all available resources on a machine, which could lead to system instability or slowdowns.
Fair Resource Allocation: It allows you to run multiple Tamarin tasks concurrently, each with a defined resource budget, ensuring fair allocation of resources.
Experimentation: You can easily adjust the limit files to experiment with different resource configurations and find the optimal balance between performance and resource usage.
Automation: The script automates the process of launching Tamarin with the correct resource limits, making it easier to run large-scale experiments.
To modify the limits:
You would edit the limit.1, limit.2, limit.4, limit.8 (or create new ones) files to change the RAM and core limits as needed. Remember to restart the script after making changes.