Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 19204
1
r"""
2
Classification in parallel using MPI
3
====================================
4
5
The ``classify_in_mpi_parallel`` module defines functions that
6
use MPI to save Cayley graph classifications or partial classifications in parallel.
7
8
AUTHORS:
9
10
- Paul Leopardi (2017-10-13)
11
12
"""
13
#*****************************************************************************
14
# Copyright (C) 2016 Paul Leopardi [email protected]
15
#
16
# Distributed under the terms of the GNU General Public License (GPL)
17
# as published by the Free Software Foundation; either version 2 of
18
# the License, or (at your option) any later version.
19
# http://www.gnu.org/licenses/
20
#*****************************************************************************
21
22
from math import log
23
from sage.crypto.boolean_function import BooleanFunction
24
from sage.functions.other import Function_ceil
25
26
from boolean_cayley_graphs.bent_function import BentFunction
27
from boolean_cayley_graphs.classify_in_parallel import save_one_classification
28
from boolean_cayley_graphs.classify_in_parallel import save_one_class_part
29
30
31
def save_classifications_in_parallel(
32
comm,
33
name_prefix,
34
list_of_f,
35
start=0,
36
stop=None,
37
directory=None):
38
r"""
39
Using MPI, construct and save a number of Cayley graph classifications
40
corresponding to a list of bent functions.
41
42
INPUT:
43
44
- ``comm`` -- MPI communicator.
45
- ``name_prefix`` -- String. Name prefix to use with ``save_mangled`` to save each classification.
46
- ``list_of_f`` -- List of forms or bent functions.
47
- ``start`` -- Integer. Default=0. Index of start position in the list.
48
- ``stop`` -- Integer. Default=None. Index after end position, or ``None`` if whole remaining list.
49
- ``directory`` -- string, optional. The directory where the object
50
is to be saved. Default is None, meaning the current directory.
51
52
OUTPUT: None.
53
54
EFFECT: Uses ``name`` to save the classifications corresponding to ``list_of_f``.
55
"""
56
rank = comm.Get_rank()
57
size = comm.Get_size()
58
59
if stop == None:
60
stop = len(list_of_f)
61
for n in range(start + rank, stop, size):
62
name = name_prefix + '_' + str(n)
63
form = BooleanFunction(list_of_f[n]).truth_table(format='hex')
64
save_one_classification(
65
name,
66
form,
67
directory=directory)
68
69
70
def save_class_parts_in_parallel(
71
comm,
72
name_prefix,
73
form,
74
c_len=1,
75
directory=None):
76
r"""
77
Using MPI, construct a complete list of the partial Cayley graph classifications
78
corresponding to a given bent function or algebraic normal form.
79
80
INPUT:
81
82
- ``comm`` -- MPI communicator.
83
- ``name_prefix`` -- String. Name prefix to use with ``save_mangled`` to save each class part.
84
- ``form`` -- A bent function or an algebraic normal form.
85
- ``c_len`` -- Integer. Default=1. The number of values of `c` to use in each class part.
86
- ``directory`` -- string, optional. The directory where the object
87
is to be saved. Default is None, meaning the current directory.
88
89
OUTPUT: None.
90
91
EFFECT: Uses ``name_prefix`` to save all partial classifications corresponding to ``bentf``.
92
"""
93
rank = comm.Get_rank()
94
size = comm.Get_size()
95
96
bentf = BentFunction(form)
97
dim = bentf.nvariables()
98
v = 2 ** dim
99
ceil = Function_ceil()
100
nbr_parts = ceil(v * 1.0 / c_len)
101
102
# Include the case where size > nbr_parts and therefore
103
# this function is being applied to many bent functions in parallel.
104
if size > nbr_parts:
105
beg_n = rank % nbr_parts
106
end_n = beg_n + 1
107
else:
108
beg_n = rank
109
end_n = nbr_parts
110
111
nbr_digits = ceil(log(nbr_parts, 10))
112
for n in range(beg_n, end_n, size):
113
n_str = '{0:0={width}}'.format(n, width=nbr_digits)
114
save_one_class_part(
115
name=name_prefix + '_' + n_str,
116
bentf=bentf,
117
c_start=c_len * n,
118
c_stop=c_len * (n + 1),
119
directory=directory)
120
121