{"id":31363812,"url":"https://github.com/proxy-pylon/monte-carlo-volume-approximation","last_synced_at":"2025-09-27T05:22:06.518Z","repository":{"id":315923623,"uuid":"1061277295","full_name":"proxy-pylon/Monte-Carlo-Volume-Approximation","owner":"proxy-pylon","description":"Implementation of monte carlo simulations for approximation of volumes of high-dimensional spheres. Uses C++ and OpenMP for parallelized simulations. A detailed latex report is provided","archived":false,"fork":false,"pushed_at":"2025-09-21T15:47:35.000Z","size":1859,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-21T17:43:01.959Z","etag":null,"topics":["cpp","monte-carlo","numerical-simulations","openmp","parallel-computing"],"latest_commit_sha":null,"homepage":"","language":"TeX","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/proxy-pylon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-21T15:45:59.000Z","updated_at":"2025-09-21T15:48:40.000Z","dependencies_parsed_at":"2025-09-21T17:58:30.827Z","dependency_job_id":null,"html_url":"https://github.com/proxy-pylon/Monte-Carlo-Volume-Approximation","commit_stats":null,"previous_names":["proxy-pylon/monte-carlo-volume-approximation"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/proxy-pylon/Monte-Carlo-Volume-Approximation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proxy-pylon%2FMonte-Carlo-Volume-Approximation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proxy-pylon%2FMonte-Carlo-Volume-Approximation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proxy-pylon%2FMonte-Carlo-Volume-Approximation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proxy-pylon%2FMonte-Carlo-Volume-Approximation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/proxy-pylon","download_url":"https://codeload.github.com/proxy-pylon/Monte-Carlo-Volume-Approximation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/proxy-pylon%2FMonte-Carlo-Volume-Approximation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277184144,"owners_count":25775286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-27T02:00:08.978Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","monte-carlo","numerical-simulations","openmp","parallel-computing"],"created_at":"2025-09-27T05:22:03.589Z","updated_at":"2025-09-27T05:22:06.504Z","avatar_url":"https://github.com/proxy-pylon.png","language":"TeX","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHYS 421 Assignment 2: Monte Carlo Volume Estimation\n\n## Overview\nThis project implements a parallel Monte Carlo method using OpenMP to estimate the volume of n-dimensional p-spheres. The implementation includes both serial and parallel versions with comprehensive performance analysis.\n\n## Files Structure\n```\n├── monte_carlo_sphere.c    # Main C implementation\n├── Makefile               # Build configuration\n├── run_experiments.sh     # Automated experiment runner\n├── plot_results.py       # Python plotting script\n├── README.md             # This file\n├── results/              # Generated results directory\n└── plots/                # Generated plots directory\n```\n\n## Building the Project\n\n### Prerequisites\n- GCC compiler with OpenMP support\n- Python 3 with matplotlib, pandas, numpy (for plotting)\n- bc calculator (for shell script calculations)\n\n### Compilation\n```bash\nmake clean\nmake\n```\n\nThis creates the executable `monte_carlo_sphere`.\n\n## Usage\n\n### Basic Usage\n```bash\n./monte_carlo_sphere [options]\n```\n\n### Options\n- `-n \u003cint\u003e`: Number of dimensions (default: 10)\n- `-p \u003cfloat\u003e`: p-norm value (default: 4.0)\n- `-R \u003cfloat\u003e`: Radius (default: 1.0)\n- `-N \u003clong\u003e`: Number of samples (default: 1000000)\n- `-seed \u003cint\u003e`: Random seed (default: 42)\n- `-parallel`: Enable parallel mode\n- `-threads \u003cint\u003e`: Number of threads (default: 1)\n- `-schedule \u003cstring\u003e`: OpenMP scheduling (static/dynamic)\n- `-chunk \u003cint\u003e`: Chunk size for scheduling\n\n### Example Commands\n\n**Serial execution:**\n```bash\n./monte_carlo_sphere -n 10 -p 4 -R 1 -N 1000000\n```\n\n**Parallel execution:**\n```bash\n./monte_carlo_sphere -n 10 -p 4 -R 1 -N 1000000 -parallel -threads 4\n```\n\n**With custom scheduling:**\n```bash\n./monte_carlo_sphere -n 10 -p 4 -R 1 -N 1000000 -parallel -threads 4 -schedule dynamic -chunk 1000\n```\n\n## Running Experiments\n\n### Automated Full Analysis\n```bash\nchmod +x run_experiments.sh\n./run_experiments.sh\n```\n\nThis runs all required experiments and saves results to CSV files in the `results/` directory.\n\n### Individual Experiments\n```bash\n# Quick tests\nmake test_serial\nmake test_parallel\n\n# Specific experiment types\nmake accuracy_test\nmake scaling_test\nmake validation_test\nmake schedule_test\n```\n\n## Generating Plots and Analysis\n\nAfter running experiments:\n```bash\npython3 plot_results.py\n```\n\nThis generates:\n- `plots/accuracy_vs_n.png`: Error vs sample size\n- `plots/scaling_analysis.png`: Speedup and efficiency analysis\n- `plots/validation_comparison.png`: Monte Carlo vs exact values\n- `plots/schedule_comparison.png`: Static vs dynamic scheduling\n- `plots/high_dimensional_behavior.png`: High-dimensional analysis\n- `results/summary.txt`: Key findings summary\n\n## Implementation Details\n\n### Thread Safety\n- Uses `rand_r()` with per-thread seeds for thread-safe random number generation\n- Each thread gets seed = base_seed + 1337 * thread_id\n- Atomic reduction for hit counting\n\n### Performance Optimizations\n- Compiler optimizations: `-O3`\n- Efficient power calculations using `pow()`\n- Minimal memory allocation per thread\n- Cache-friendly data access patterns\n\n### Scheduling Options\n- **Static**: Work divided equally among threads at compile time\n- **Dynamic**: Work distributed dynamically at runtime\n- Chunk sizes can be specified for load balancing\n\n## Expected Results\n\n### Part C.1: Accuracy vs N\n- Error should decrease as ~1/√N\n- Larger N gives more accurate estimates\n- Log-log plot should show -1/2 slope\n\n### Part C.2: Thread Scaling\n- Near-linear speedup for low thread counts\n- Efficiency typically 70-90% depending on system\n- Diminishing returns beyond number of physical cores\n\n### Part C.3: Validation (p=2 case)\n- Monte Carlo estimates should match exact values within error bounds\n- Relative errors typically \u003c 1% for reasonable N\n- Higher dimensions show larger volumes initially, then rapid decay\n\n### Part C.4: Scheduling Comparison\n- Static scheduling typically faster for balanced workloads\n- Dynamic scheduling helps with load imbalances\n- Chunk size affects cache performance\n\n## Troubleshooting\n\n### Common Issues\n1. **Compilation errors**: Ensure OpenMP support (`gcc -fopenmp`)\n2. **Permission denied**: Make scripts executable (`chmod +x run_experiments.sh`)\n3. **Missing dependencies**: Install required Python packages\n4. **Memory issues**: Reduce N for high-dimensional cases\n\n### Performance Tips\n- Use N ≥ 1M for stable timing measurements\n- Test with different thread counts up to your CPU core count\n- Monitor system load during experiments\n- Use consistent seeds for reproducible results\n\n## Mathematical Background\n\nThe n-dimensional p-sphere volume formula:\n```\nV_n^p(R) = [2Γ(1+1/p)]^n / Γ(1+n/p) * R^n\n```\n\nMonte Carlo estimation:\n```\nV ≈ (hits/N) * (2R)^n\n```\n\nStandard error: O(1/√N)\n\n## Assignment Requirements Met\n\n- ✅ **Part A**: Serial baseline implementation\n- ✅ **Part B**: OpenMP parallelization with thread-safe RNG\n- ✅ **Part C.1**: Accuracy vs N analysis\n- ✅ **Part C.2**: Thread scaling analysis\n- ✅ **Part C.3**: Validation against exact formula\n- ✅ **Part C.4**: Scheduling comparison\n- ✅ **Part D**: High-dimensional behavior analysis\n\n## Notes\n\n- All timing uses `omp_get_wtime()` for high precision\n- Results are deterministic with fixed seeds\n- Error estimates assume normal distribution (Central Limit Theorem)\n- High-dimensional cases may require larger N for stability\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproxy-pylon%2Fmonte-carlo-volume-approximation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fproxy-pylon%2Fmonte-carlo-volume-approximation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fproxy-pylon%2Fmonte-carlo-volume-approximation/lists"}