Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F104822800
poisson.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Mar 12, 16:45
Size
1 KB
Mime Type
text/x-c
Expires
Fri, Mar 14, 16:45 (2 d)
Engine
blob
Format
Raw Data
Handle
24860551
Attached To
R12662 PHPC-graded_hw_1
poisson.cc
View Options
/* -------------------------------------------------------------------------- */
#include "simulation.hh"
/* -------------------------------------------------------------------------- */
#include <chrono>
#include <iostream>
#include <sstream>
#include <tuple>
#include <chrono>
/* -------------------------------------------------------------------------- */
#include <mpi.h>
/* -------------------------------------------------------------------------- */
typedef std::chrono::high_resolution_clock clk;
typedef std::chrono::duration<double> second;
static void usage(const std::string & prog_name) {
std::cerr << prog_name << " <grid_size> <n_iter>" << std::endl;
exit(0);
}
int main(int argc, char * argv[]) {
MPI_Init(&argc, &argv);
int prank, psize;
MPI_Comm_rank(MPI_COMM_WORLD, &prank);
MPI_Comm_size(MPI_COMM_WORLD, &psize);
if (argc != 3) usage(argv[0]);
std::stringstream arg_0(argv[1]), arg_1(argv[2]);
int N;
int n_iter;
arg_0 >> N;
arg_1 >> n_iter;
if(arg_0.fail() || arg_1.fail()) usage(argv[0]);
// Compute slice parameters
int n_loc=N;
if (prank == 0) {
n_loc = (int)(N/psize) + 1;
} else if (prank < psize-1){
n_loc = (int)(N/psize) + 2;
} else {
n_loc = N - (psize-1)*(int)(N/psize) + 1;
}
Simulation simu(n_loc, N, n_iter, prank, psize);
simu.set_initial_conditions();
float l2;
int k;
auto start = clk::now();
std::tie(l2, k) = simu.compute();
auto end = clk::now();
second time = end - start;
if(prank == 0)
std::cout << psize << " " << N << " "
<< k << " " << std::scientific << l2 << " "
<< time.count() << std::endl;
MPI_Finalize();
return 0;
}
Event Timeline
Log In to Comment