-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpi.R
More file actions
38 lines (31 loc) · 2.55 KB
/
Copy pathmpi.R
File metadata and controls
38 lines (31 loc) · 2.55 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
# mpi.R — Rook vs Shrikhande with Δ¹-DRESS (MPI, CPU backend)
# Keeps multisets and compares them to guarantee distinguishability.
#
# Run:
# mpirun -np 4 Rscript mpi.R
library(dress.graph)
library(pbdMPI)
# Rook L₂(4) = K₄ □ K₄ — 16 vertices, 96 directed edges (0-based)
rook_s <- c(0L,1L,0L,4L,0L,2L,0L,8L,0L,3L,0L,12L,1L,5L,1L,2L,1L,9L,1L,3L,1L,13L,2L,6L,2L,10L,2L,3L,2L,14L,3L,7L,3L,11L,3L,15L,4L,5L,4L,6L,4L,8L,4L,7L,4L,12L,5L,6L,5L,9L,5L,7L,5L,13L,6L,10L,6L,7L,6L,14L,7L,11L,7L,15L,8L,9L,8L,10L,8L,11L,8L,12L,9L,10L,9L,11L,9L,13L,10L,11L,10L,14L,11L,15L,12L,13L,12L,14L,12L,15L,13L,14L,13L,15L,14L,15L)
rook_t <- c(1L,0L,4L,0L,2L,0L,8L,0L,3L,0L,12L,0L,5L,1L,2L,1L,9L,1L,3L,1L,13L,1L,6L,2L,10L,2L,3L,2L,14L,2L,7L,3L,11L,3L,15L,3L,5L,4L,6L,4L,8L,4L,7L,4L,12L,4L,6L,5L,9L,5L,7L,5L,13L,5L,10L,6L,7L,6L,14L,6L,11L,7L,15L,7L,9L,8L,10L,8L,11L,8L,12L,8L,10L,9L,11L,9L,13L,9L,11L,10L,14L,10L,15L,11L,13L,12L,14L,12L,15L,12L,14L,13L,15L,13L,15L,14L)
# Shrikhande — 16 vertices, 96 directed edges
shri_s <- c(0L,4L,0L,12L,0L,1L,0L,3L,0L,5L,0L,15L,1L,5L,1L,13L,1L,2L,1L,6L,1L,12L,2L,6L,2L,14L,2L,3L,2L,7L,2L,13L,3L,7L,3L,15L,3L,4L,3L,14L,4L,8L,4L,5L,4L,7L,4L,9L,5L,9L,5L,6L,5L,10L,6L,10L,6L,7L,6L,11L,7L,11L,7L,8L,8L,12L,8L,9L,8L,11L,8L,13L,9L,13L,9L,10L,9L,14L,10L,14L,10L,11L,10L,15L,11L,15L,11L,12L,12L,13L,12L,15L,13L,14L,14L,15L)
shri_t <- c(4L,0L,12L,0L,1L,0L,3L,0L,5L,0L,15L,0L,5L,1L,13L,1L,2L,1L,6L,1L,12L,1L,6L,2L,14L,2L,3L,2L,7L,2L,13L,2L,7L,3L,15L,3L,4L,3L,14L,3L,8L,4L,5L,4L,7L,4L,9L,4L,9L,5L,6L,5L,10L,5L,10L,6L,7L,6L,11L,6L,11L,7L,8L,7L,12L,8L,9L,8L,11L,8L,13L,8L,13L,9L,10L,9L,14L,9L,14L,10L,11L,10L,15L,10L,15L,11L,12L,11L,13L,12L,15L,12L,14L,13L,15L,14L)
dr <- mpi$delta_fit(16L, rook_s, rook_t, k = 1L, keep_multisets = TRUE)
ds <- mpi$delta_fit(16L, shri_s, shri_t, k = 1L, keep_multisets = TRUE)
if (comm.rank() == 0L) {
cat(sprintf("Rook: %d exact values, %d subgraphs\n", nrow(dr$histogram), dr$num_subgraphs))
cat(sprintf("Shrikhande: %d exact values, %d subgraphs\n", nrow(ds$histogram), ds$num_subgraphs))
cat("Histograms differ: ", !identical(dr$histogram, ds$histogram), "\n")
# Canonicalize: sort each row, then sort rows
canonicalize <- function(ms) {
s <- t(apply(ms, 1, sort, na.last = TRUE)) # sort within each row
s[do.call(order, as.data.frame(s)), ] # sort rows lexicographically
}
cr <- canonicalize(dr$multisets)
cs <- canonicalize(ds$multisets)
ms_same <- identical(dim(cr), dim(cs)) &&
all(cr == cs | (is.nan(cr) & is.nan(cs)), na.rm = TRUE)
cat("Multisets differ: ", !ms_same, "\n")
}
finalize()