Newer
Older
#include "datastructures/Body.hpp"
int main(int argc, char** argv) {
using namespace nbody;
using namespace std;
MPI::Init(argc, argv);
MPI::Datatype Btype;
MPI::Datatype type[3] = {MPI::DOUBLE, MPI::DOUBLE, MPI::DOUBLE};
int blocks[3] = {3, 3, 1};
MPI::Aint disp[3];
if (MPI::COMM_WORLD.Get_rank() == 0) {
for (int i = 0; i < 16; i++) {
if (MPI::COMM_WORLD.Get_rank() == 0) {
for (int i = 0; i < 16; i++) {
cout << MPI::COMM_WORLD.Get_rank() << " " << data[i].position[0] << endl;
}
}
for (int i = 0; i < 16; i++) {
Body b((double) 0, (double) 0, (double) 0);
data[i] = b;
}
if (MPI::COMM_WORLD.Get_rank() != 0) {
for (int i = 0; i < 16; i++) {
cout << MPI::COMM_WORLD.Get_rank() << " " << data[i].position[0] << endl;
}
}
disp[0] = MPI::Get_address(data[0].position);
disp[1] = MPI::Get_address(data[0].velocity);
disp[2] = MPI::Get_address(&data[0].mass);
*/
disp[0] = MPI::Get_address(data[0].position) - MPI::Get_address(&data[0]);
disp[1] = MPI::Get_address(data[0].velocity) - MPI::Get_address(&data[0]);
disp[2] = MPI::Get_address(&data[0].mass) - MPI::Get_address(&data[0]);
Btype = Btype.Create_struct(3, blocks, disp, type);
Btype.Commit();
MPI::COMM_WORLD.Bcast(MPI::BOTTOM, 16, Btype, 0);
if (MPI::COMM_WORLD.Get_rank() != 0) {
for (int i = 0; i < 16; i++) {
cout << MPI::COMM_WORLD.Get_rank() << " " << data[i].position[0] << endl;
}
}
/*
MPI::Datatype Btype;
MPI::Datatype type[3] = {MPI::DOUBLE, MPI::DOUBLE, MPI::DOUBLE};
int blocks[3] = {3, 3, 1};
MPI::Aint disp[3];
//Body data[16];
vector<Body> data;
MPI::Init(argc, argv);
if (MPI::COMM_WORLD.Get_rank() == 0) {
for (int i = 0; i < 16; i++) {
Body b;
data.push_back(b);
}
} else {
data.reserve(16);
}
*/
MPI::Init(argc, argv);
MPI::Datatype Btype;
MPI::Datatype type[3] = {MPI::DOUBLE, MPI::DOUBLE, MPI::DOUBLE};
int blocks[3] = {3, 3, 1};
MPI::Aint disp[3];
Body data[16];
disp[0] = MPI::Get_address(data[0].position);
disp[1] = MPI::Get_address(data[0].velocity);
disp[2] = MPI::Get_address(&data[0].mass);
Btype = Btype.Create_struct(3, blocks, disp, type);
Btype.Commit();
MPI::COMM_WORLD.Bcast(MPI::BOTTOM, 16, Btype, 0);
Btype.Free();
MPI::Finalize();