CoCalc Public FilesBoolean-Cayley-graphs / sage-code / save_psf_in_mpi_parallel.pyOpen with one click!
Author: Paul Leopardi
Compute Environment: Ubuntu 18.04 (Deprecated)
1
r"""
2
"""
3
#*****************************************************************************
4
# Copyright (C) 2017 Paul Leopardi [email protected]
5
#
6
# Distributed under the terms of the GNU General Public License (GPL)
7
# as published by the Free Software Foundation; either version 2 of
8
# the License, or (at your option) any later version.
9
# http://www.gnu.org/licenses/
10
#*****************************************************************************
11
12
import sys
13
14
from mpi4py import MPI
15
from sage.all_cmdline import *
16
17
from boolean_cayley_graphs.bent_function import BentFunction
18
from boolean_cayley_graphs.classify_in_mpi_parallel import save_class_parts_in_parallel
19
20
r"""
21
"""
22
# Check that the correct number of arguments exist.
23
if len(sys.argv) < 4:
24
print("Usage: save_psf_in_mpi_parallel psf_seq bnbr fnbr c_len [dir]")
25
sys.exit(1)
26
27
# Convert the arguments to int.
28
seq_nbr = int(sys.argv[1]) # Number of the partial spread function sequence
29
fnbr0 = int(sys.argv[2]) # First function number within partial spread function sequence
30
c_len = int(sys.argv[3]) # Number of c values per class part.
31
d = None
32
if len(sys.argv) > 4:
33
d = sys.argv[4] # Directory to save to
34
35
# Get our MPI rank.
36
comm = MPI.COMM_WORLD
37
rank = comm.Get_rank()
38
size = comm.Get_size()
39
40
# Load the required bent function.
41
load("langevin_hou_partial_spreads.sage")
42
psf_seq_name = "../psf/psf-"+str(seq_nbr)+".txt"
43
psf_seq_file = open(psf_seq_name)
44
anf_list = read_langevin_hou_anf_list(psf_seq_file)
45
46
# Obtain the first bent function to determine the dimension.
47
bentf0 = BentFunction(anf_list[fnbr0])
48
dim = bentf0.nvariables()
49
v = 2 ** dim
50
51
# This script assumes that the number of parts per bent function is
52
# the Integer v // c_len, and the remainder v % c_len must be 0.
53
nbr_parts_per_bentf, remainder_v = divmod(v, c_len)
54
if remainder_v != 0:
55
print("c_len is not a factor of 2 ** dim. Remainder is", remainder_v)
56
exit(1)
57
58
# This script also assumes that size is an integer multiple of
59
# the number of parts per bent function.
60
remainder_s = size % nbr_parts_per_bentf
61
if remainder_s != 0:
62
print("nbr_parts_per_bentf is not a factor of size. Remainder is", remainder_s)
63
exit(1)
64
65
# Obtain the correct bent function for this rank
66
fnbr = fnbr0 + (rank // nbr_parts_per_bentf)
67
bentf = BentFunction(anf_list[fnbr])
68
69
# Save the classification in parts with c_len matrix rows each.
70
save_class_parts_in_parallel(
71
comm,
72
"psf"+str(seq_nbr)+"_"+str(fnbr),
73
bentf,
74
c_len=c_len,
75
dir=d)
76
sys.exit(0)
77