-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·99 lines (69 loc) · 2.71 KB
/
main.cpp
File metadata and controls
executable file
·99 lines (69 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// main.cpp
//
// Modified by Patrick Anderson on 07/05/2015.
// Test environment for single atom codes.
//
#include <mpi.h>
#include "./class_lib/grid_xkx.hpp"
#include "./class_lib/grid_tw.hpp"
#include "./class_lib/laser_pulse.hpp"
#include <limits>
#include "./class_lib/text.hpp"
#include "./class_lib/Schrodinger_atom_1D.hpp"
int main(int argc, char** argv){
// MPI
int this_node;
int total_nodes;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &total_nodes);
MPI_Comm_rank(MPI_COMM_WORLD, &this_node);
// Input
int atoms_per_worker = 2;
int total_atoms = atoms_per_worker * (total_nodes - 1);
// Grids
grid_xkx xkx(total_atoms, 0, 100e-6);
grid_tw tw(std::pow(2.0, 18), -100e-15, 100e-15);
// Control
if (this_node == 0) {
// Field
double ROC = std::numeric_limits<double>::max();
laser_pulse pulse(0.18, 1000, 15e-15, 795e-9, 0, 42e-6, ROC, xkx, tw);
// Send
for (int ii = 1; ii < total_nodes; ii++) {
MPI_Send(pulse.E.block(0, atoms_per_worker * (ii - 1), tw.N_t, atoms_per_worker).data(),
tw.N_t * atoms_per_worker, MPI::DOUBLE, ii, 1, MPI_COMM_WORLD);
}
// Receive
ArrayXXd dipole = ArrayXXd::Zero(tw.N_t, total_atoms);
for (int jj = 1; jj < total_nodes; jj++) {
// Request
bool send = true;
MPI_Send(&send, 1, MPI::BOOL, jj, 1, MPI_COMM_WORLD);
MPI_Recv(dipole.block(0, atoms_per_worker * (jj - 1), tw.N_t, atoms_per_worker).data(),
tw.N_t * atoms_per_worker, MPI::DOUBLE, jj, 1, MPI_COMM_WORLD, &status);
}
// Output
text output(dipole, "./output/dipole.txt");
text output2(tw.w, "./output/w.txt");
}
// Worker
if (this_node != 0) {
// Receive
ArrayXXd E = ArrayXXd::Zero(tw.N_t, atoms_per_worker);
MPI_Recv(E.data(), E.rows() * E.cols(), MPI::DOUBLE, 0, 1, MPI_COMM_WORLD, &status);
// Single atom calculations
ArrayXXd dipole = ArrayXXd::Zero(tw.N_t, atoms_per_worker);
Schrodinger_atom_1D atom(1.45);
for (int ii = 0; ii < atoms_per_worker; ii++) {
dipole.col(ii) = atom.get_dipole(tw.N_t, tw.dt, E.col(ii));
}
// Send
bool send;
MPI_Recv(&send, 1, MPI::BOOL, 0, 1, MPI_COMM_WORLD, &status);
MPI_Send(dipole.data(), tw.N_t * atoms_per_worker, MPI::DOUBLE, 0, 1, MPI_COMM_WORLD);
}
// Clean up
MPI_Finalize();
}