# Parallel Computing of Edwards--Anderson Model
## 2 Algorithm
The arrows show the transmission of the values of the energy to calculate the next energy minima according to (4) and (5). Figure 1:4 The data exchange scheme between 16 threads. In each thread the memory is divided into two parts. One stays, the other is transmitted to the other thread. Meanwhile the half of the memory of the other thread is written in its place. The numbers indicate the thread number, and the shaded squares indicate the memory block. This scheme corresponds to one in Figure 1:5 The positions of the coloured squares correspond exactly to the memory locations. The transmitted data are the energy values for the fixed boundaries. Recall that Figure 4 corresponds to only 2 \(E\) per thread. Since according to the Figure 3 scheme the data within blocks (they are surrounded by a dashed line) are arranged in order, to facilitate the calculation of state numbers, the initial state numbers in the blocks can also be transmitted in the array of energy values. It can be seen that in the diagram of Figure 4 data exchange between threads can be done using two nested loops, as was done in Listing 1. Based on the diagram in Figure 4, namely by observing how groups of threads vary in size, we can construct the whole system of data exchange between all  
Figure 1:6 The data exchange scheme between 16 threads. In each thread the memory is divided into two parts. One stays, the other is transmitted to the other thread. Meanwhile the half of the memory of the other thread is written in its place. The numbers indicate the thread number, and the shaded squares indicate the memory block. This scheme corresponds to one in Figure 1:7 The positions of the coloured squares correspond exactly to the memory locations. The transmitted data are the energy values for the fixed boundaries. Figure 1:8 Splitting states of the lattice boundary spins with \(L_{x}=5\) into pairs while expanding line \(m+1\). In this scheme, the spins of each pair are written together: one below the other. The numbers correspond to the values of \(E\) with the fixed boundaries. Position of the number corresponds to location in the memory. A pair of the cells with paired \(E\) (one below the other) are located next door to each other in the memory. Obviously all pairs of variables with \(E\) of must be in adjacent cells of the memory. sponds to a subsystem with a given number of spins of the uppermost row (a view of all 5 subsystems is shown in Figure 2). For \(L_{x}=5\) we have 5 possible subsystems of different forms with spins filled from left to right (with one top spin, two, etc.). The bidirectional arrows here mean data exchange. One part takes the place of the another part, which in turn takes up the place of the first part. threads. Thus, the pseudocode calculating the energy minima for different subsystems is given in Listing 3. **Listing 3. ** Pseudocode for rows and columns enumeration, memory exchange between threads, energy calculation for cases \(col<n_{exch}\) and \(col\geq n_{exch}\). After completion of building each row, the memory locations are moved in the opposite direction. The code does not consider the calculation of the subsystem consisting of the lowest row only, because in this case there is no data exchange between threads. In the latter case, its calculation is trivial. The data exchange between threads is performed using two nested cycles on variables \(thrd\_num\_out\) and \(thrd\_num\_in\). When calculating the energy by the subprogram \(calc\_E(...)\), it is necessary to dispatch as arguments the array of energy values, the number of the column, the length of the side \(Lx\).