MeshLevelData.cc 2.55 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


Thomas Witkowski's avatar
Thomas Witkowski committed
13
#include <boost/lexical_cast.hpp>
14
15
16
17
18
19
20
21
#include "parallel/MeshLevelData.h"
#include "Global.h"

namespace AMDiS {

  using namespace std;


22
23
24
25
26
27
28
  MeshLevelData::MeshLevelData()
  {
    std::set<int> neighbours;
    init(neighbours);
  }


29
30
31
32
33
34
  void MeshLevelData::init(std::set<int> &neighbourRanks)
  {
    levelRanks.resize(1);
    levelRanks[0].insert(-1);
    nLevel = 1;
    
Thomas Witkowski's avatar
Thomas Witkowski committed
35
36
    levelNeighbours.resize(1);
    levelNeighbours[0] = neighbourRanks;
37
38
39

    mpiComms.resize(1);
    mpiComms[0] = MPI::COMM_WORLD;
40
41
42

    mpiGroups.resize(1);
    mpiGroups[0] = mpiComms[0].Get_group();
43
44
45
  }


46
  void MeshLevelData::addLevel(std::set<int> &ranksInDomain, int domainId)
47
48
49
50
51
52
  {
    FUNCNAME("MeshLevelData()::addLevel()");

    TEST_EXIT(nLevel >= 1)("Mesh level structure is not initialized()");
    TEST_EXIT(nLevel == 1)("Only 2 level are supported yet!\n");

53
    levelRanks.push_back(ranksInDomain);
54
55
    nLevel++;

Thomas Witkowski's avatar
Thomas Witkowski committed
56
    levelNeighbours.resize(2);    
57
58
59
60
61
62
63
64
    levelNeighbours[1].clear();
    for (std::set<int>::iterator it = levelNeighbours[0].begin(); 
	 it != levelNeighbours[0].end(); ++it)
      if (levelRanks[1].count(*it) == 0)
	levelNeighbours[1].insert(*it);

    mpiComms.resize(2);
    mpiComms[1] = mpiComms[0].Split(domainId, mpiComms[0].Get_rank());
65
66
67
    
    mpiGroups.resize(2);
    mpiGroups[1] = mpiComms[1].Get_group();
68
69
70
71
72
73
74
75
76
77
78
79
  }


  void MeshLevelData::serialize(ostream &out)
  {
  }

  
  void MeshLevelData::deserialize(istream &in)
  {
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
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

  void MeshLevelData::print()
  {
    FUNCNAME("MeshLevelData::print()");

    using boost::lexical_cast;

    MSG("Print mesh level structure with %d levels: \n", nLevel);

    for (int i = 0; i < nLevel; i++) {
      string ranks = "ranks in level " + lexical_cast<string>(i) + ":";
      for (std::set<int>::iterator it = levelRanks[i].begin(); 
	   it != levelRanks[i].end(); ++it)
	ranks += " " + lexical_cast<string>(*it);

      string neighbours = "neighbours in level " + lexical_cast<string>(i) + ": ";
      for (std::set<int>::iterator it = levelNeighbours[i].begin(); 
	   it != levelNeighbours[i].end(); ++it)
	neighbours += " " + lexical_cast<string>(*it);

      if (ranks.length() < 250)
	MSG("  %s\n", ranks.c_str());
      else
	MSG("  ranks string to long!\n");

      if (neighbours.length() < 250)
	MSG("%s\n", neighbours.c_str());
      else
	MSG("  neighbours string to long!\n");
    }
  }
111
}