test/parallel.cpp

00001 #include "DAPTA.hpp"
00002 
00003 #include <set>
00004 #include <fstream>
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <sstream>
00008 #undef SEEK_SET
00009 #undef SEEK_CUR
00010 #undef SEEK_END
00011 #include "mpi.h"
00012 using namespace DAPTA;
00013 
00014 typedef Mesh<Tri3MeshTraits> TriMesh;
00015 typedef MeshParalleliser<Tri3MeshTraits> TriMeshParalleliser;
00016 
00017 int main(int argc, char **argv) {
00018    // Initialize MPI
00019    MPI_Init(&argc, &argv);
00020    MPI_Status status;
00021    
00022    // Load in the complete mesh
00023    TriMesh *mesh = new TriMesh();
00024    mesh->ClearMesh();
00025    std::ifstream meshfile;
00026    meshfile.open(argv[1]);
00027    if(!meshfile) {
00028       std::cout << "ERROR READING FILE!" << std::endl;
00029       exit(1);
00030    }
00031    mesh->ReadFile(meshfile);
00032    meshfile.close();
00033    
00034    TriMeshParalleliser *mesh_paralleliser = new TriMeshParalleliser(MPI_COMM_WORLD, mesh);
00035    mesh_paralleliser->initialiseCommunication();
00036    
00037    // ********************
00038    // * BEGIN FEM CODE
00039    // ********************
00040    
00041    int myRank, numProcs;
00042    MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
00043    MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
00044    
00045    int DebugWait=1;
00046    //while(DebugWait);
00047    
00048    //if(myRank == 0) {
00049    // mesh->FractureFace(mesh->FindElementFromIndex(2),1);
00050    //}
00051    
00052    MPI_Barrier(MPI_COMM_WORLD);
00053    mesh_paralleliser->exchange();
00054    MPI_Barrier(MPI_COMM_WORLD);
00055    
00056    sleep(myRank*2);
00057    std::cout << "==============================================" << std::endl;
00058    std::cout << " client(" << myRank << ")" << std::endl;
00059    std::cout << "==============================================" << std::endl;
00060    TriMesh::EdgeMapIterator e_iter;
00061    for(e_iter=mesh->EdgeMapBegin(); e_iter!=mesh->EdgeMapEnd(); ++e_iter) {
00062       std::cout << " " << e_iter->first.vertices.at(0)->globalID << "\t";
00063       std::cout << e_iter->second->isClosed() << "\t";
00064       std::cout << e_iter->second->needSplit() << "\t";
00065       for(TriMesh::ElementConListType::iterator list_iter=e_iter->second->begin(); list_iter!=e_iter->second->end(); ++list_iter) {
00066          std::cout << (*list_iter).elem_globalID << "(" << (*list_iter).link_state << ")" << "->";
00067       }
00068       std::cout << std::endl;
00069    }
00070    std::cout << "==============================================" << std::endl;
00071    
00072    MPI_Barrier(MPI_COMM_WORLD);
00073    mesh->UpdateEdges();
00074    MPI_Barrier(MPI_COMM_WORLD);
00075    
00076    sleep(myRank*2);
00077    std::cout << "==============================================" << std::endl;
00078    std::cout << " client(" << myRank << ")" << std::endl;
00079    std::cout << "==============================================" << std::endl;
00080    std::cout << mesh->ExportFile() << std::endl;
00081    std::cout << "==============================================" << std::endl;
00082    
00083    std::stringstream filename_ss;
00084    filename_ss << "export-parallel-" << myRank << ".txt";
00085    
00086    std::string filename = filename_ss.str();
00087    
00088    std::ofstream outfile(filename.c_str(), std::ios::out);
00089    outfile << mesh->ExportFile();
00090    outfile.close();
00091    
00092    // ********************
00093    // * END FEM CODE
00094    // ********************
00095    
00096    // Shut Down MPI
00097    MPI_Finalize();
00098    
00099    return 0;
00100 }

Generated on Tue May 29 17:13:49 2007 for DAPTA by  doxygen 1.5.1