Course: Parallel proceesing and high computing
Institution: Faculty of Computers and Artificial Intelligence, Helwan University
Academic Year: 2025-2026
- Salma Mohammed Abd-ElAziz
- Ahmed Alaa Abd-ElReheem
- Rawan Essam-ElDin Fahmy
- Mahmoud Hossam-ElDin Mahmoud
- Mohammed Saied Ahmed
- Nour Hatem Mohammed
- Yassin Yasser Zakaria
- Project Overview
- Features
- Technical Implementation
- System Architecture
- Installation & Setup
- Usage Guide
- Experimental Results
- Bonus Features
- File Structure
- Technologies Used
This project implements a Monte Carlo simulation to estimate the value of Ο (pi) using both sequential and parallel approaches. The Monte Carlo method generates random points within a unit square and determines what fraction falls within an inscribed quarter circle. The ratio of points inside the circle to total points, multiplied by 4, approximates Ο.
The Monte Carlo method for Ο estimation:
- Generate random points (x, y) where 0 β€ x, y β€ 1
- Check if point lies inside quarter circle: xΒ² + yΒ² β€ 1
- Estimate: Ο β 4 Γ (points inside circle) / (total points)
β
Sequential Ο Estimator - Single-threaded baseline implementation
β
Parallel Ο Estimator - Multi-threaded using ExecutorService and Futures
β
Configurable Simulations - Adjustable points, threads, and tasks
β
Performance Benchmarking - Compare sequential vs parallel execution
β
Thread Scalability Analysis - Test performance across different thread counts
π¨ Interactive GUI Dashboard with:
- Real-time visualization of random point generation
- Live convergence graph showing Ο estimate approaching true value
- Thread workload distribution pie chart
- Multiple simulation modes (Visual, Batch, Comparison, Benchmark)
π Advanced Analysis Tools:
- Batch experiments with averaged results
- Sequential vs Parallel comparison with speedup calculation
- Thread scalability benchmarking (1, 2, 4, 8, 16 threads)
The project follows clean OOP principles with clear separation of concerns:
SimulationConfig
- Encapsulates simulation parameters
- Stores: totalPoints, numTasks, numThreads
- Provides getters for configuration access
PiEstimator (Interface)
- Defines contract:
double estimatePi(SimulationConfig config) - Enables polymorphic behavior for different estimation strategies
SequentialPiEstimator
- Implements single-threaded Monte Carlo simulation
- Uses
java.util.Randomfor point generation - Serves as baseline for performance comparison
ParallelPiEstimator
- Implements multi-threaded estimation using:
ExecutorServicewith fixed thread poolCallable<Long>tasks for parallel computationFuture<Long>for result aggregation
- Uses
ThreadLocalRandomfor thread-safe randomness - Divides workload into configurable number of tasks
PiExperimentRunner
- Orchestrates experiments across different configurations
- Measures execution time and estimation accuracy
- Supports batch experiments with averaged results
- Outputs formatted performance reports
PiDashboard (GUI)
- Swing-based interactive dashboard
- Real-time visualization and monitoring
- Multiple operation modes
- Custom panels for different visualizations
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Interface Layer β
β ββββββββββββββββββββ ββββββββββββββββββββββββββββ β
β β PiDashboard β β PiExperimentRunner β β
β β (GUI) β β (Console) β β
β ββββββββββββββββββββ ββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Business Logic Layer β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β PiEstimator (Interface) β β
β β ββββββββββββββββββββ ββββββββββββββββββββββ β β
β β β Sequential β β Parallel β β β
β β β PiEstimator β β PiEstimator β β β
β β ββββββββββββββββββββ ββββββββββββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Configuration Layer β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β SimulationConfig β β
β β (totalPoints, numTasks, numThreads) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ExecutorService
β
βββ> Task 1 (Callable) ββ> Future<Long> βββ
βββ> Task 2 (Callable) ββ> Future<Long> βββ€
βββ> Task 3 (Callable) ββ> Future<Long> βββ€ββ> Aggregate
βββ> Task 4 (Callable) ββ> Future<Long> βββ€ Results
βββ> Task N (Callable) ββ> Future<Long> βββ
β
βΌ
Calculate Ο
- Java Development Kit (JDK): Version 11 or higher
- IDE (Optional): IntelliJ IDEA, Eclipse, or VS Code with Java extensions
# Navigate to project directory
cd monte-carlo-pi-estimation
# Compile all Java files
javac *.java
# Or compile individually
javac SimulationConfig.java
javac PiEstimator.java
javac SequentialPiEstimator.java
javac ParallelPiEstimator.java
javac PiExperimentRunner.java
javac PiDashboard.javaRun comprehensive benchmarking experiments:
java PiExperimentRunnerOutput Example:
Type Threads Points Time(ms) Estimate Error
-------------------------------------------------------------------------------------
Sequential 1 100000 45 3.14280000 0.00120734
Sequential 1 1000000 420 3.14172800 0.00013474
Sequential 1 10000000 4150 3.14158540 0.00000725
-------------------------------------------------------------------------------------
Parallel 2 100000 28 3.14276000 0.00116734
Parallel 4 100000 18 3.14164000 0.00004734
Parallel 8 100000 15 3.14152000 0.00007265
Launch the graphical interface:
java PiDashboardConfiguration Panel:
- Total Points: Number of random points to generate
- Threads: Number of parallel threads (1-32)
- Batch Trials: Number of trials for batch mode
Operation Modes:
-
Run Visual (Single)
- Real-time visualization of point generation
- Live convergence graph
- Thread workload distribution
-
Run Batch (Fast)
- Multiple trials with averaged results
- No visualization for faster execution
- Statistical analysis
-
Compare (Seq vs Par)
- Side-by-side comparison
- Speedup calculation
- Detailed performance metrics
-
Benchmark Threads
- Test scalability across thread counts
- Performance profile generation
- Speedup analysis
-
Reset Board
- Clear all visualizations
- Reset statistics
Visualization Panels:
-
Dots Canvas: 600Γ600 pixel display showing:
- Green dots: Points inside circle
- Red dots: Points outside circle
- White circle: Unit circle boundary
-
Convergence Graph:
- Blue line: Current Ο estimate
- Red line: True Ο value (3.14159...)
- Auto-scaling Y-axis
-
Thread Load Pie Chart:
- Visual distribution of work across threads
- Color-coded thread identification
- Real-time updates
| Configuration | Points | Threads | Time (ms) | Ο Estimate | Error | Speedup |
|---|---|---|---|---|---|---|
| Sequential | 10βΆ | 1 | 420 | 3.141728 | 0.000135 | 1.00x |
| Parallel | 10βΆ | 2 | 245 | 3.141652 | 0.000059 | 1.71x |
| Parallel | 10βΆ | 4 | 138 | 3.141584 | 0.000009 | 3.04x |
| Parallel | 10βΆ | 8 | 95 | 3.141598 | 0.000005 | 4.42x |
| Parallel | 10βΆ | 16 | 78 | 3.141590 | 0.000003 | 5.38x |
- Accuracy: Error decreases as sample size increases (approximately proportional to 1/βN)
- Speedup: Near-linear speedup up to 4-8 threads, then diminishing returns due to overhead
- Optimal Configuration: 4-8 threads provide best balance of performance and efficiency
- Statistical Stability: Batch averaging significantly reduces variance in estimates
- β Real-time scatter plot visualization
- β Live convergence graph
- β Thread workload distribution
- β Interactive controls and configuration
- β Multiple visualization modes
- β Batch experiments with averaged error
- β Sequential vs Parallel comparison tool
- β Thread scalability benchmarking
- β Comprehensive performance profiling
- β Statistical analysis tools
Total Bonus Points Earned: +5
monte-carlo-pi-estimation/
βββ README.md # This file
βββ .gitignore # Git ignore patterns
βββ SimulationConfig.java # Configuration holder
βββ PiEstimator.java # Estimator interface
βββ SequentialPiEstimator.java # Sequential implementation
βββ ParallelPiEstimator.java # Parallel implementation
βββ PiExperimentRunner.java # Console experiment runner
βββ PiDashboard.java # GUI application
- java.util.concurrent: ExecutorService, Callable, Future, ThreadLocalRandom
- java.util: Random, ArrayList, List, Collections
- javax.swing: JFrame, JPanel, JButton, JSpinner, etc.
- java.awt: Graphics2D, BufferedImage, Color, Font
- java.awt.geom: Arc2D for pie chart rendering
- Strategy Pattern: PiEstimator interface with multiple implementations
- Factory Pattern: ExecutorService creation
- Observer Pattern: GUI updates and real-time visualization
- Singleton Pattern: Dashboard instance management
- ThreadLocalRandom: Eliminates contention on shared Random instance
- Task Granularity: Configurable task count for load balancing
- Fixed Thread Pool: Avoids overhead of thread creation/destruction
- Atomic Operations: AtomicLong for thread-safe counters in GUI
- Efficient point generation without storage
- Bounded history in convergence graph (max 500 points)
- Proper executor shutdown to prevent memory leaks
- Parallel Programming: Effective use of Java concurrency utilities
- Performance Analysis: Understanding speedup, efficiency, and Amdahl's Law
- GUI Development: Building responsive, multi-threaded user interfaces
- Statistical Methods: Monte Carlo simulation and error analysis
- Software Design: Clean architecture and separation of concerns
- GPU acceleration using CUDA or OpenCL
- Distributed computing across multiple machines
- Adaptive thread pool sizing based on workload
- Export results to CSV/JSON for external analysis
- Web-based interface using WebSockets for real-time updates
- Monte Carlo Methods in Statistical Physics - M.E.J. Newman and G.T. Barkema
- Java Concurrency in Practice - Brian Goetz
- Introduction to Parallel Computing - Ananth Grama et al.
This project is submitted as part of academic coursework at FCAI Helwan University.
Β© 2024-2025 Team Members. All rights reserved.
Special thanks to:
- Course Instructors: For guidance on concurrent programming concepts
- FCAI Helwan University: For providing the learning environment
- Java Documentation: For comprehensive API references
For questions or issues related to this project, please contact any team member through the university portal.
Project Completion Date: December 2024
Version: 1.0.0