|
| 1 | +# Python Installation |
| 2 | + |
| 3 | +## From PyPI (once published) |
| 4 | + |
| 5 | +```bash |
| 6 | +pip install sharedmap |
| 7 | +``` |
| 8 | + |
| 9 | +## From source |
| 10 | + |
| 11 | +```bash |
| 12 | +# Clone the repository |
| 13 | +git clone https://github.com/HenningWoydt/SharedMap.git |
| 14 | +cd SharedMap |
| 15 | + |
| 16 | +# Build dependencies first |
| 17 | +./build.sh |
| 18 | + |
| 19 | +# Install Python package |
| 20 | +pip install . |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +```python |
| 26 | +import sharedmap as sm |
| 27 | + |
| 28 | +# Define your graph in CSR format |
| 29 | +v_weights = [1, 1, 1, 1, 1, 1, 1, 1] |
| 30 | +adj_ptrs = [0, 3, 6, 8, 12, 16, 19, 21, 22] |
| 31 | +adj_weights = [1] * 22 |
| 32 | +adj = [1, 2, 3, 0, 3, 4, 0, 3, 0, 1, 2, 5, 1, 5, 6, 7, 3, 4, 6, 4, 5, 4] |
| 33 | + |
| 34 | +# Define hardware hierarchy and distances |
| 35 | +hierarchy = [2, 2] # 2 nodes, 2 cores per node |
| 36 | +distance = [1, 10] # distance within node: 1, between nodes: 10 |
| 37 | + |
| 38 | +# Partition the graph |
| 39 | +comm_cost, partition = sm.partition_graph( |
| 40 | + v_weights, adj_ptrs, adj_weights, adj, |
| 41 | + hierarchy, distance, |
| 42 | + imbalance=0.03, |
| 43 | + n_threads=1, |
| 44 | + seed=0 |
| 45 | +) |
| 46 | + |
| 47 | +print(f"Communication Cost: {comm_cost}") |
| 48 | +print(f"Partition: {partition}") |
| 49 | +``` |
| 50 | + |
| 51 | +## API Reference |
| 52 | + |
| 53 | +### `partition_graph()` |
| 54 | + |
| 55 | +Main function for graph partitioning. |
| 56 | + |
| 57 | +**Parameters:** |
| 58 | +- `v_weights`: Vertex weights (array of integers >= 1) |
| 59 | +- `adj_ptrs`: CSR adjacency pointers (n+1 integers) |
| 60 | +- `adj_weights`: Edge weights (array of integers >= 1) |
| 61 | +- `adj`: CSR adjacency list |
| 62 | +- `hierarchy`: Hierarchy levels (e.g., [4, 8, 6]) |
| 63 | +- `distance`: Communication distances (e.g., [1, 10, 100]) |
| 64 | +- `imbalance`: Maximum allowed imbalance (default: 0.03) |
| 65 | +- `n_threads`: Number of threads (default: 1) |
| 66 | +- `seed`: Random seed (default: 0) |
| 67 | +- `strategy`: Thread distribution strategy (default: `Strategy.NB_LAYER`) |
| 68 | +- `parallel_alg`: Parallel algorithm (default: `Algorithm.MTKAHYPAR_QUALITY`) |
| 69 | +- `serial_alg`: Serial algorithm (default: `Algorithm.KAFFPA_STRONG`) |
| 70 | +- `verbose`: Print statistics (default: False) |
| 71 | + |
| 72 | +**Returns:** |
| 73 | +- `comm_cost`: Communication cost J(C, D, PI) |
| 74 | +- `partition`: Partition assignment for each vertex (numpy array) |
| 75 | + |
| 76 | +### Enums |
| 77 | + |
| 78 | +**Strategy:** |
| 79 | +- `Strategy.NAIVE` |
| 80 | +- `Strategy.LAYER` |
| 81 | +- `Strategy.QUEUE` |
| 82 | +- `Strategy.NB_LAYER` |
| 83 | + |
| 84 | +**Algorithm:** |
| 85 | +- `Algorithm.KAFFPA_FAST` |
| 86 | +- `Algorithm.KAFFPA_ECO` |
| 87 | +- `Algorithm.KAFFPA_STRONG` |
| 88 | +- `Algorithm.MTKAHYPAR_DEFAULT` |
| 89 | +- `Algorithm.MTKAHYPAR_QUALITY` |
| 90 | +- `Algorithm.MTKAHYPAR_HIGHEST_QUALITY` |
| 91 | + |
| 92 | +### `validate_input()` |
| 93 | + |
| 94 | +Validates input parameters before partitioning. |
| 95 | + |
| 96 | +**Returns:** `bool` - True if input is valid, False otherwise. |
0 commit comments