How it works - sagnikb/Simulati-ON GitHub Wiki

There are two data files, Data1.txt and Data2.txt. There are two OpenACC programs, seq1.c and seq2.c. The initial data is input in Data1.txt, and the number of bodies required is updated in the two program codes. The two executables are compiled with the following lines of terminal code:

pgcc -acc -o seq1.out seq1.c
pgcc -acc -o seq2.out seq1.c

The pgcc compiler is not freely available, and may be installed with a students' license or a 30 day free trial from their website. OpenACC support is also coming to gcc according to reports, so this reliance on paid compilers will get replaced by gcc later.

gcc can also compile the two codes, but then they will not be parallel computing codes any longer, and will be simple sequential codes.

The following is the bash script (script.sh) used for the project:

#!/bin/bash
rm Table.txt 
loop() {
    while [ "foo" == "foo" ] 
    do
    ./seq1.out
    ./seq2.out
    cat List.txt
    done
}
loop & 
gnuplot liveplot.gnu

The first line is there to make the script an executable. Also the following command needs to be run:

chmod +x script.sh

loop is a function. The ampersand the statement "loop" is used so that the for loop inside the function continues running while the next line is executed.

After this

./script.sh

begins running the codes.

The bash script runs "seq1.out", which takes data (corresponding to positions and velocities at time t) from "Data1.txt", writes to "Data2.txt" (data at time t + dt). "seq2.txt" does the same, except that it takes data from "Data2.txt" and writes to "Data1.txt". Every time data is written to either "Data1.txt" or "Data2.txt", the original data in these files is overwritten, and a copy is sent to the file "List.txt". Also another data file called "Table.txt" may be generated for plotting trajectories, but since this involves very large data files the code for this functionality is currently kept commented out.

The gnuplot script (liveplot.gnu) looks like this.

set term x11 size 1500, 1200
set xrange [-500:500]
set yrange [-500:500]
set zrange [-5:5]
splot "List.txt" with points ps 1 pt 7 title "N-Body Simulation"
pause 1
reread 

The first line sets the output window size and type. The next three lines set the range of the 3d plot, and all these can be changed as per requirements. The data stored in "List.txt" is 3d plotted using splot, and required point sizes. The script pauses for a second, and then rereads the data. The process continues for as long as desired.