r"""1"""2#*****************************************************************************3# Copyright (C) 2017 Paul Leopardi [email protected]4#5# Distributed under the terms of the GNU General Public License (GPL)6# as published by the Free Software Foundation; either version 2 of7# the License, or (at your option) any later version.8# http://www.gnu.org/licenses/9#*****************************************************************************1011import sys1213from mpi4py import MPI14from sage.all_cmdline import *1516from boolean_cayley_graphs.bent_function import BentFunction17from boolean_cayley_graphs.classify_in_mpi_parallel import save_class_parts_in_parallel1819r"""20"""21# Check that the correct number of arguments exist.22if len(sys.argv) < 4:23print("Usage: save_psf_in_mpi_parallel psf_seq bnbr fnbr c_len [dir]")24sys.exit(1)2526# Convert the arguments to int.27seq_nbr = int(sys.argv[1]) # Number of the partial spread function sequence28fnbr0 = int(sys.argv[2]) # First function number within partial spread function sequence29c_len = int(sys.argv[3]) # Number of c values per class part.30d = None31if len(sys.argv) > 4:32d = sys.argv[4] # Directory to save to3334# Get our MPI rank.35comm = MPI.COMM_WORLD36rank = comm.Get_rank()37size = comm.Get_size()3839# Load the required bent function.40load("langevin_hou_partial_spreads.sage")41psf_seq_name = "../psf/psf-"+str(seq_nbr)+".txt"42psf_seq_file = open(psf_seq_name)43anf_list = read_langevin_hou_anf_list(psf_seq_file)4445# Obtain the first bent function to determine the dimension.46bentf0 = BentFunction(anf_list[fnbr0])47dim = bentf0.nvariables()48v = 2 ** dim4950# This script assumes that the number of parts per bent function is51# the Integer v // c_len, and the remainder v % c_len must be 0.52nbr_parts_per_bentf, remainder_v = divmod(v, c_len)53if remainder_v != 0:54print("c_len is not a factor of 2 ** dim. Remainder is", remainder_v)55exit(1)5657# This script also assumes that size is an integer multiple of58# the number of parts per bent function.59remainder_s = size % nbr_parts_per_bentf60if remainder_s != 0:61print("nbr_parts_per_bentf is not a factor of size. Remainder is", remainder_s)62exit(1)6364# Obtain the correct bent function for this rank65fnbr = fnbr0 + (rank // nbr_parts_per_bentf)66bentf = BentFunction(anf_list[fnbr])6768# Save the classification in parts with c_len matrix rows each.69save_class_parts_in_parallel(70comm,71"psf"+str(seq_nbr)+"_"+str(fnbr),72bentf,73c_len=c_len,74dir=d)75sys.exit(0)767778