Student: Alexandros Papafragkakis - CSD5084
Implementation of a distributed library management system using MPI (Message Passing Interface). The system consists of library processes (servers) and borrower processes (clients) that communicate through message passing.
Total Processes: 1 + N² + N³/2
├── Coordinator (Rank 0)
├── Libraries (Ranks 1 to N²) - N×N Grid
└── Clients (Ranks N²+1 to N²+N³/2) - Tree Topology
- Libraries: N×N grid with 4-connectivity neighborhood
- Clients: Tree determined by CONNECT commands
- "Constructing a DFS Spanning Tree without a Specified Root" algorithm
- EXPLORE/PARENT/ACK message handling
- Tree merging with highest tree_id selection
- Leadership announcement to all libraries
- Complete convergecast algorithm from tree leaves
- ELECT message propagation with collision detection
- Two completion cases: convergence or edge collision
- Highest rank wins in collision scenarios
- Broadcast + convergecast through client spanning tree
- O(log n) message complexity instead of O(n) direct polling
- Cost-based tie-breaking for popular book selection
- Parent-child relationship utilization
- Systematic grid traversal:
<0,0>, <1,0>, ..., <N-1,0>, <N-1,1>, <N-2,1>, ..., <0,1>, <0,2>, ... - Message forwarding through specified grid pattern
- Accumulative loan counting during traversal
- Random Cost Generation: Books assigned cost between 5-100
- Tie-Breaking: Higher cost wins in popular book ties
- Assignment Formula: Library i manages books
i*Nto(i+1)*N-1
- Configuration Validation: Automatic process count verification
- Range Checking: All rank validations for safety
- Graceful Degradation: Proper error messages and fallbacks
# Standard build
make
# Clean build artifacts
make clean
# Debug build
make debugmpirun -np 9 ./library_system 2mpirun -np 23 ./library_system 3mpirun -np 49 ./library_system 4mpirun -np 88 ./library_system 5CONNECT <client_id1> <client_id2>
TAKE_BOOK <client_id> <book_id>
DONATE_BOOK <client_id> <book_id> <n_copies>
GET_MOST_POPULAR_BOOK
CHECK_NUM_BOOKS_LOANED
├── main.c # Main logic and system startup
├── coordinator.c # Coordinator process
├── lib.c # Library processes
├── client.c # Client processes
├── Makefile # Build system
├── testfile.txt # Input file with events
└── README.md # Documentation
- DFS Election: O(E) where E is edges in grid
- STtoLeader: O(V) where V is vertices in tree
- Tree Aggregation: O(log n) for clients
- Grid Traversal: O(N²) with spatial locality
- Tested Configurations: N=2 through N=5
- Maximum Tested: 88 parallel processes
- Memory Usage: Efficient with fixed-size arrays
- Network Load: Optimized message patterns
- MPI Implementation: OpenMPI or MPICH
- Compiler: mpicc (GCC-based)
- OS: Linux/Unix
- Memory: ~100MB for N=5
- Multiple concurrent tree initiation
- Proper tree merging based on tree_id comparison
- Parent-child relationship establishment
- Leadership announcement propagation
- Leaf node identification and initiation
- Convergecast message flow control
- Collision detection on tree edges
- Rank-based collision resolution
- Tree-based popular book finding with cost tie-breaking
- Grid traversal pattern compliance for libraries
- Consistency checking between both methods
- Message complexity optimization
- Memory Leak Detection: Optional checks with valgrind
- Static Analysis: Code quality checks
- Performance Profiling: Timing and message metrics
- Algorithm Tracing: Step-by-step execution logging
- Consistency Checks: Automatic loan count verification
- Error Detection: Invalid operation identification
- Performance Metrics: Message count and timing information
-
Compilation:
make
-
Execution:
mpirun -np <total_processes> ./library_system <N>
where
total_processes = 1 + N² + N³/2 -
Example for N=3:
mpirun -np 23 ./library_system 3
The system has been tested and works on:
- Ubuntu 20.04/22.04
- OpenMPI 4.0+
- MPICH 3.3+
- GCC 9.0+
- Connection establishment (CONNECT, NEIGHBOR, ACK)
- Leader election (START_LE, EXPLORE, PARENT, ELECT)
- Book operations (TAKE_BOOK, LEND_BOOK, DONATE_BOOK)
- Aggregation (GET_MOST_POPULAR_BOOK, CHECK_NUM_BOOKS_LOAN)
- System control (SHUTDOWN)
- LibraryNode: Grid position, neighbors, election state
- ClientNode: Tree connections, aggregation state
- BookInfo: ID, cost, loan count for tie-breaking
- Coordinator-driven event processing
- Barrier synchronization for phase transitions
- Acknowledgment-based completion detection
Alexandros Papafragkakis
CSD5084
Computer Science Department
University of Crete