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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#include <assert.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <time.h>
#include <cstdlib>
#include <stdio.h>
#include <mpi.h>
#include <vector>
#include<iterator>
#include<sstream>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include "includes.h"
#include "typedefs.h"
#include "mesh.h"
#include "node.h"
#include "element.h"
#include "mpi_call.h"
typedef std::vector<Node> VecNode_t; /*vector of number of Nodes*/
typedef std::vector<Element> VecElm_t; /*vector of number of Elements*/
int main(int argc, char *argv[])
{
int num_procs, myrank;
MPI_Init(&argc, &argv);
MPI_Status status;
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
if (myrank== 0) {
Mesh* Local_Mesh;
/*********************start reading mesh************************/
/***************************************************************/
size_t Nnodes;
size_t Nelms;
VecVecDbl_t Coordinates;
VecVecIdx_t Connectivities;
Mesh Global_Mesh;
Global_Mesh.Mesh_Connectivity("mesh.txt");
Global_Mesh.Mesh_Coordinate("mesh.txt");
size_t Nelms_ = Global_Mesh.Nelms_;
size_t Nnodes_ = Global_Mesh.Nnodes_;
VecVecIdx_t Connectivities_ = Global_Mesh.Connectivities_;
VecVecDbl_t Coordinates_ = Global_Mesh.Coordinates_;
std::cout << "Printing Coordinates" << std::endl;
std::cout << std::endl;
for (size_t i = 0; i < Coordinates_.size(); i++) {
for (size_t j = 0; j < Coordinates_[i].size(); j++) {
std::cout << Coordinates_[i][j] << " ";
}
std::cout << std::endl;
}
std::cout << "Printing Connectivities" << std::endl;
std::cout << std::endl;
for (size_t i = 0; i < Connectivities_.size(); i++) {
for (size_t j = 0; j < Connectivities_[i].size(); j++) {
std::cout << Connectivities_[i][j] << " ";
}
std::cout << std::endl;
}
/************************end reading mesh*************************/
/*****************************************************************/
VecVecIdx_t MPI_Elms;
{
size_t Nelm = Global_Mesh.Connectivities_.size();
//size_t res = Nelm % num_procs;
size_t size = Nelm / num_procs;
size_t res = Nelm - size * num_procs;
MPI_Elms.resize(num_procs);
size_t n_aux = 0;
for (int i_proc = 0; i_proc < num_procs; i_proc++) {
if (i_proc < res) {
MPI_Elms[i_proc].resize(size + 1);
for (int j = 0; j < size + 1; j++) {
MPI_Elms[i_proc][j] = n_aux + j;
}
n_aux += size + 1;
}
else {
MPI_Elms[i_proc].resize(size);
for (int j = 0; j < size; j++) {
MPI_Elms[i_proc][j] = n_aux + j;
}
n_aux += size;
}
}
}
VecVecVecIdx_t Local_Connectivities;
VecVecIdx_t connect;
for (int i_proc = 0; i_proc < num_procs; i_proc++) {
for (int i_elm = 0; i_elm < MPI_Elms[i_proc].size(); i_elm++) {
VecIdx_t elm_connect = Global_Mesh.Connectivities_[i_elm];
connect.push_back(elm_connect);
}
Local_Connectivities.push_back(connect);
}
for (int i_proc = 0; i_proc < num_procs; i_proc++) {
VecVecDbl_t Coordinates = Global_Mesh.Coordinates_;
VecVecIdx_t Connectivities = Local_Connectivities[i_proc];
size_t Nnodes = Coordinates.size();
size_t Nelms = Connectivities.size();
(*Local_Mesh).Mesh_build(Nnodes, Nelms, Coordinates, Connectivities);
MPI_CALL call_mpisend;
if (i_proc == 0) {
call_mpisend.Send_to(i_proc, Coordinates[i_proc]);
//call_mpisend.Send_to(i_proc, Connectivities[i_proc]);
}
else
{
size_t Nnodes;
size_t Nelms;
VecVecDbl_t Coordinates;
VecVecIdx_t Connectivities;
MPI_CALL call_mpireceive;
//call_mpireceive.Receive_from(0, Connectivities[i_proc]);
call_mpireceive.Receive_from(0, Coordinates[i_proc]);
}
}
VecNode_t Nodes;
for (size_t i_node = 0; i_node < (*Local_Mesh).Nnodes_; i_node++) {
VecDbl_t coord = (*Local_Mesh).Coordinates_[i_node];
Node node(&coord);
Nodes.push_back(node);
}
VecElm_t Elements;
for (size_t i_elm = 0; i_elm < (*Local_Mesh).Nelms_; i_elm++) {
VecIdx_t connect = (*Local_Mesh).Connectivities_[i_elm];
Element elm(&connect, Nodes);
Elements.push_back(elm);
}
MPI_Finalize();
return 0;
}
}
| |