Skip to content
Snippets Groups Projects
Unverified Commit c78485aa authored by Jayesh Badwaik's avatar Jayesh Badwaik
Browse files

+ initial commit

parents
Branches
No related tags found
No related merge requests found
data_*
experiment
#include <cmath>
#include <fstream>
#include <mpi.h>
#include <stdio.h>
#include <vector>
double index_to_x(std::size_t i, double xl, double dx)
{
return xl + i * dx;
}
int main(int argc, char** argv)
{
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
std::size_t ncell = 10'000;
std::size_t nhalo = ncell / 2;
double xl = -2.0;
double xr = 2.0;
double dx = (xr - xl) / (2 * ncell);
double lxl = -2.0;
double lxr = 0.0;
double lxc = -1.0;
double rxl = 0.0;
double rxr = 2.0;
double rxc = 1.0;
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
std::vector<double> data(ncell);
std::vector<double> halo(nhalo);
if (world_rank == 0) {
for (std::size_t i = 0; i < ncell; ++i) {
auto x = index_to_x(i, lxl, dx);
data[i] = 1 + std::exp(-10 * (x - lxc) * (x - lxc));
}
} else {
for (std::size_t i = 0; i < ncell; ++i) {
auto x = index_to_x(i, rxl, dx);
data[i] = 1 + std::exp(-10 * (x - rxc) * (x - rxc));
}
}
auto const filename = "data_" + std::to_string(world_rank) + ".txt";
std::ofstream file(filename);
for (std::size_t i = 0; i < ncell; ++i) {
file << index_to_x(i, xl, dx) << " " << data[i] << "\n";
}
// Finalize the MPI environment.
MPI_Finalize();
}
experiment: experiment.cpp
mpicxx -std=c++20 -o experiment experiment.cpp
plot.py 0 → 100755
#!/usr/bin/env python3
import argparse
import matplotlib.pyplot as plt
import csv
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--input', help='input file')
parser.add_argument('-o', '--output', help='output file')
args = parser.parse_args()
input_file = args.input
output_file = args.output
with open(input_file, 'r') as f:
plots = csv.reader(f, delimiter=' ')
x = []
y = []
for row in plots:
x.append(float(row[0]))
y.append(float(row[1]))
plt.plot(x, y, label=input_file)
plt.xlabel('x')
plt.ylabel('y')
plt.yscale("linear")
#plt.tick_params(bottom = False)
#plt.tick_params(left= False)
#plt.tick_params(labelbottom=False)
#plt.tick_params(labelleft=False)
ax = plt.gca()
ax.set_aspect('equal', adjustable='box')
print('Saving plot to {}'.format(output_file))
plt.savefig(output_file)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment