Repository navigation
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·58 lines (49 loc) · 1.98 KB
/
Copy pathscript.sh
File metadata and controls
executable file
·58 lines (49 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# --------- CONFIG ---------
MAX_RANKS=$(nproc) # Detect number of logical CPU cores
SERIAL_SCRIPT="serial_federated_sim.py"
MPI_SCRIPT="mpi_federated_sim.py"
EPOCHS=100
ROUNDS=10
RESULTS_CSV="timing_results.csv"
SAMPLE_SIZES=(100000 500000 1000000 5000000 10000000)
TOTAL_DEVICES=64
RANKS_LIST=(1 2 4 8 16 32 64)
# --------- HEADER ---------
if [ -f "$RESULTS_CSV" ]; then
echo "⚠️ File $RESULTS_CSV exists. Overwriting..."
rm "$RESULTS_CSV"
fi
echo "samples,ranks,devices,time,mode" > $RESULTS_CSV
# --------- RUN EXPERIMENTS ---------
for SAMPLES in "${SAMPLE_SIZES[@]}"
do
echo "▶️ Running experiments for $SAMPLES samples..."
# --- SERIAL ---
echo "Running SERIAL with $TOTAL_DEVICES devices..."
out=$(python $SERIAL_SCRIPT --total-devices $TOTAL_DEVICES --epochs $EPOCHS --rounds $ROUNDS --samples $SAMPLES 2>/dev/null)
time=$(echo "$out" | grep -oP 'Time:\s+\K[0-9.]+')
echo "$SAMPLES,1,$TOTAL_DEVICES,$time,serial" >> $RESULTS_CSV
# --- MPI ---
for RANKS in "${RANKS_LIST[@]}"
do
if (( TOTAL_DEVICES % RANKS != 0 )); then
echo "Skipping: $TOTAL_DEVICES not divisible by $RANKS ranks"
continue
fi
if [ "$RANKS" -gt "$MAX_RANKS" ]; then
echo "Skipping: $RANKS ranks exceeds available cores ($MAX_RANKS)"
continue
fi
DEVICES_PER_RANK=$((TOTAL_DEVICES / RANKS))
echo "Running MPI with $RANKS ranks ($DEVICES_PER_RANK devices/rank)..."
out=$(mpiexec -n $RANKS -- bash -c "python $MPI_SCRIPT --devices-per-rank $DEVICES_PER_RANK --epochs $EPOCHS --rounds $ROUNDS --samples $SAMPLES" 2>/dev/null)
time=$(echo "$out" | grep -oP 'Time:\s+\K[0-9.]+')
if [ -n "$time" ]; then
echo "$SAMPLES,$RANKS,$TOTAL_DEVICES,$time,mpi" >> $RESULTS_CSV
else
echo "❌ MPI failed for $RANKS ranks, $SAMPLES samples"
fi
done
done
echo "✅ All experiments complete. Results saved to $RESULTS_CSV"