CoolFace
Apppublic

sheralisaleem/parallel-compute-benchmark

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

๐Ÿš€ PDC Inventory Engine

Parallel Data Computing Engine โ€” A high-performance C-based HTTP server demonstrating scalable parallel computing paradigms with a modern React dashboard.

![C Standard](https://en.wikipedia.org/wiki/C99) ![Platform Support](#-requirements) ![HuggingFace Space](https://huggingface.co/spaces/sheralisaleem/parallel-compute-benchmark)


๐Ÿ“‹ Overview

The PDC Inventory Engine is a sophisticated benchmarking platform that compares three parallel computing paradigms in real-time:

  • โ€”Sequential (Single-threaded) โ€” Baseline performance metric
  • โ€”POSIX Threads (Pthreads) โ€” Multi-threaded parallelism with 4 worker threads
  • โ€”OpenMP โ€” Compiler-directive-based auto-parallelization

The project includes a REST API backend (C with HTTP server) and an interactive React dashboard that visualizes performance metrics across different data workload sizes.

๐ŸŽฏ Key Features

โœจ Three Parallel Computing Approaches

  • โ€”Linear sequential processing for baseline comparison
  • โ€”POSIX Threads implementation with dynamic thread pool
  • โ€”OpenMP pragmatic parallel directives

๐Ÿ”„ Dynamic Memory Management

  • โ€”Automatic reallocation based on workload size
  • โ€”Configurable data set ranging from 10M to 250M items
  • โ€”Efficient memory cleanup after computation

๐Ÿ“Š Real-time Performance Dashboard

  • โ€”Beautiful dark/light mode interface
  • โ€”Live execution logging with colored output
  • โ€”Performance metrics visualization with Recharts
  • โ€”Speedup calculation (relative to sequential baseline)

๐ŸŒ RESTful HTTP API

  • โ€”Clean endpoint-based architecture
  • โ€”JSON response format with execution timing
  • โ€”CORS support for cross-origin requests
  • โ€”Configurable item count via query parameters

๐Ÿ“ธ Demo

[image]

Interactive dashboard showing real-time performance metrics across parallel computing paradigms


๐Ÿค— Live Demo (Hugging Face)

Try it live without any local setup:

[โ–ถ Open on Hugging Face Spaces](https://huggingface.co/spaces/sheralisaleem/parallel-compute-benchmark)

Note: The hosted demo runs on shared HuggingFace infrastructure. Results reflect server-side performance, not your local machine. For accurate benchmarks on your hardware, run locally (see Quick Start).

๐Ÿ—๏ธ Architecture

Project Structure

parallel-compute-benchmark/
โ”œโ”€โ”€ server.c              # HTTP server & routing layer
โ”œโ”€โ”€ compute.h             # Public interface definitions
โ”œโ”€โ”€ compute.c             # Computation implementations (linear, pthreads, openmp)
โ”œโ”€โ”€ index.html            # React dashboard (single-file app)
โ”œโ”€โ”€ Dockerfile            # Docker config for HuggingFace deployment
โ”œโ”€โ”€ requirements.txt      # System dependencies
โ””โ”€โ”€ README.md             # This file

Component Breakdown

`server.c` (HTTP Server)

  • โ€”Manages socket communication on port 7860 (HuggingFace) / 8080 (local)
  • โ€”Parses HTTP requests and routes to computation endpoints
  • โ€”Measures execution time with nanosecond precision
  • โ€”Sends JSON responses with performance metrics

`compute.c/compute.h` (Computation Layer)

  • โ€”process_linear() โ€” Sequential loop processing
  • โ€”process_pthreads() โ€” POSIX Threads with work chunking
  • โ€”process_openmp() โ€” Compiler-parallel with #pragma omp
  • โ€”Global inventory array (dynamically allocated)

`index.html` (Dashboard)

  • โ€”React 18 + Tailwind CSS frontend
  • โ€”Real-time performance charts with Recharts
  • โ€”Configuration panel for workload sizing
  • โ€”Live console output simulation

`Dockerfile` (Deployment)

  • โ€”Based on gcc:13 image
  • โ€”Installs OpenMP, compiles the server, exposes port 7860

๐Ÿ”ง Requirements

System Requirements

  • โ€”OS: Linux, macOS, or BSD (POSIX-compliant)
  • โ€”Compiler: GCC 9+ or Clang 10+ with C99 support
  • โ€”Build Tools: GNU Make
  • โ€”Libraries:
  • โ€”POSIX Threads (pthreads)
  • โ€”OpenMP runtime (libomp)
  • โ€”Standard C library (libc)

Optional Tools

  • โ€”gdb โ€” Debugging
  • โ€”valgrind โ€” Memory profiling
  • โ€”cmake โ€” Advanced build configuration
  • โ€”Docker โ€” For containerized/HuggingFace deployment

Installation on Ubuntu/Debian

bash
sudo apt-get update
sudo apt-get install build-essential libpthread-stubs0-dev libomp-dev

Installation on macOS

bash
brew install gcc libomp

๐Ÿš€ Quick Start

1. Clone & Navigate

bash
git clone https://github.com/sheralisaleem/parallel-compute-benchmark.git
cd parallel-compute-benchmark

2. Compile

bash
gcc -O2 -o pdc_server server.c compute.c -lm -lpthread -fopenmp

Compile Flags Explained:

  • โ€”-O2 โ€” Level 2 optimization (balance speed & compile time)
  • โ€”-lm โ€” Link math library
  • โ€”-lpthread โ€” Link POSIX Threads
  • โ€”-fopenmp โ€” Enable OpenMP support

3. Run Server

bash
./pdc_server

Expected Output:

========================================================
 PDC Backend Server is Running! (Modular Architecture)
 View the Dashboard at: http://localhost:8080
========================================================

4. Open Dashboard

Navigate to http://localhost:8080 in your web browser.


๐Ÿณ Docker Deployment

Run Locally with Docker

bash
docker build -t pdc-server .
docker run -p 7860:7860 pdc-server

Then open http://localhost:7860.

Deploy to Hugging Face Spaces

  1. 1.Create a new Space at huggingface.co/new-space, select Docker as the SDK.
  2. 2.Clone your Space and push the repo files:
bash
git clone https://huggingface.co/spaces/YOUR_USERNAME/parallel-compute-benchmark
cd parallel-compute-benchmark
# copy your project files in
git add .
git commit -m "Deploy PDC server"
git push
  1. 1.HuggingFace will auto-build and serve at: https://YOUR_USERNAME-parallel-compute-benchmark.hf.space

The Dockerfile in the repo handles everything โ€” no manual build steps needed.


๐Ÿ“ก API Endpoints

Base URL

http://localhost:8080    # local
https://YOUR_USERNAME-parallel-compute-benchmark.hf.space    # HuggingFace

Endpoints

1. Dashboard (GET /)

Serves the interactive React dashboard.

bash
curl http://localhost:8080/
2. Sequential Computation (GET /run/linear)

Executes single-threaded baseline processing.

bash
curl "http://localhost:8080/run/linear?items=50000000"

Response:

json
{ "status": "success", "time": 2.145 }
3. POSIX Threads (GET /run/pthreads)

Executes parallel processing with 4 threads.

bash
curl "http://localhost:8080/run/pthreads?items=50000000"

Response:

json
{ "status": "success", "time": 0.589 }
4. OpenMP (GET /run/openmp)

Executes compiler-parallelized processing.

bash
curl "http://localhost:8080/run/openmp?items=50000000"

Response:

json
{ "status": "success", "time": 0.512 }

Query Parameters

  • โ€”items (int) โ€” Number of items to process (default: 50,000,000)
  • โ€”Range: 10M โ€“ 250M recommended
  • โ€”Example: ?items=100000000

Response Headers

Access-Control-Allow-Origin: *
Content-Type: application/json

๐Ÿ“Š Dashboard Features

Configuration Panel

  • โ€”Workload Size โ€” Input custom item count or select presets
  • โ€”Presets: 10M, 50M, 100M, 250M (marked with โšก)
  • โ€”Operation Type โ€” Select computation operation
  • โ€”"Apply 5% Inflation + 18% GST"
  • โ€”"Apply 10% Clearance Discount"

Execution Nodes

Three action buttons to trigger computations:

  • โ€”๐Ÿ–ฅ๏ธ Sequential (1 Core)
  • โ€”๐ŸŒฟ POSIX Threads (4 Cores)
  • โ€”โšก OpenMP (Auto-Parallel)

Performance Metrics Chart

  • โ€”Bar chart comparing execution times
  • โ€”Automatic scaling based on selected workload
  • โ€”Real-time updates with color-coded bars

Speedup Badge

  • โ€”Displays Xfold speedup (parallel vs sequential)
  • โ€”Appears only after multiple runs complete
  • โ€”Example: 3.62x Faster!

Live Console Logs

  • โ€”Numbered output with severity levels:
  • โ€”๐ŸŸข INFO โ€” General messages
  • โ€”๐ŸŸก WARN โ€” System initialization
  • โ€”๐Ÿ”ด ERROR โ€” Error conditions
  • โ€”๐ŸŸ  SUCCESS โ€” Successful completions
  • โ€”Auto-scrolling to latest entries

๐Ÿงฎ Computation Details

The Core Operation

Each paradigm executes the same mathematical operation on every inventory item:

c
inventory[i] = (inventory[i] * 1.05) + (inventory[i] * 0.18);

Breakdown:

  • โ€”Multiply by 1.05 (5% inflation)
  • โ€”Add 18% of result (GST/tax)
  • โ€”Applied to 50M items by default

Performance Characteristics

ParadigmThreadsOverheadIdeal Use
Sequential1NoneBaseline comparison
Pthreads4Manual schedulingFine-grained control
OpenMP4Compiler directivesRapid parallelization

Typical Speedup (4 cores, 50M items):

  • โ€”Pthreads: ~3.5โ€“4.0x faster
  • โ€”OpenMP: ~4.2โ€“4.8x faster

๐Ÿ“ˆ Performance Benchmarks

Expected Results (Intel i7, 4 cores, 50M items)

Sequential:  ~2.50 seconds (baseline)
Pthreads:    ~0.60 seconds (4.2x speedup)
OpenMP:      ~0.52 seconds (4.8x speedup)

Scalability

  • โ€”Linear to 100M items โ€” Time roughly doubles
  • โ€”Beyond 250M items โ€” Diminishing returns due to cache effects
  • โ€”Single-core systems โ€” Pthreads/OpenMP may be slower than sequential

๐Ÿ”จ Advanced Usage

Customization

Change thread count: Edit #define NUM_THREADS in compute.c (line 5)

Change server port: Edit #define PORT in server.c (line 8)

Enable debugging:

bash
gcc -g -O0 -o pdc_server_debug server.c compute.c -lm -lpthread -fopenmp

๐Ÿ› ๏ธ Troubleshooting

Compilation Error: undefined reference to omp_get_num_threads

OpenMP not linked. Ensure -fopenmp flag is present:

bash
gcc -O2 -o pdc_server server.c compute.c -lm -lpthread -fopenmp

Port Already in Use

bash
# Kill the occupying process
lsof -i :8080 | grep LISTEN | awk '{print $2}' | xargs kill
# Or change PORT in server.c and recompile

Dashboard Not Loading

  1. 1.Verify server is running: curl http://localhost:8080
  2. 2.Check firewall: sudo ufw allow 8080
  3. 3.Try a different port (see Advanced Usage)

Slow Performance on Expected Fast Machine

  • โ€”Ensure compilation optimization: -O2 or -O3
  • โ€”Check CPU throttling: cat /proc/cpuinfo | grep MHz
  • โ€”Close background processes consuming CPU

๐Ÿค Contributing

Contributions are welcome! Here's how:

  1. 1.Fork the repository
  2. 2.Create a feature branch: git checkout -b feature/amazing-feature
  3. 3.Commit your changes: git commit -m 'Add amazing feature'
  4. 4.Push to branch: git push origin feature/amazing-feature
  5. 5.Open a Pull Request

Author

Sher Ali Saleem โ€” GitHub ยท HuggingFace


โญ Star this repo if you find it useful!