LoAdSG
LocalStiffnessMatricesMemoryDistribution.h
1//
2// Created by to35jepo on 6/26/24.
3//
4
5#ifndef RUN_LOCALSTIFFNESSMATRICESMEMORYDISTRIBUTION_H
6#define RUN_LOCALSTIFFNESSMATRICESMEMORYDISTRIBUTION_H
7
8
9#include <utility>
10
11#include "LocalStiffnessMatrices.h"
12#include <sys/time.h>
13
14class LocalStiffnessMatricesMemoryDistribution: public LocalStiffnessMatrices{
15
16public:
17 LocalStiffnessMatricesMemoryDistribution(AdaptiveSparseGrid &sg, StencilTemplate& stencilClass, int number_processes_)
18 :LocalStiffnessMatrices(sg, stencilClass, number_processes_){
19
20
21
22 int num_tasks = 1;
23 int rank = 0;
24
25#ifdef MY_MPI_ON
26 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
27 MPI_Comm_size(MPI_COMM_WORLD, &num_tasks);
28#else
29 cout << "USE LOCALSTIFFNESSMATRICES ONLY WITH MPI" << endl;
30 //exit(1);
31#endif
32 struct timeval begin_time, end_time;
33 long seconds;
34 long microseconds;
35 gettimeofday(&begin_time, 0);
36
37 Container container[number_processes];
38 distribute_LocalStiffnessMatrices(number_processes, sg, container);
39
40 distributedDepthsHashtable = DistributedDepthsHashtable(container, number_processes);
41
42
43 gettimeofday(&end_time, 0);
44 seconds = end_time.tv_sec - begin_time.tv_sec;
45 microseconds = end_time.tv_usec - begin_time.tv_usec;
46 double t2 = seconds + microseconds * 1e-6;
47 if(rank==0)cout <<"time generate hashtable " << t2 << endl;
48
49 /* // Step 1: Collect keys
50 std::vector<Depth> keys;
51 keys.reserve(distributedDepthsHashtable.getMap()->size());
52 for (const auto& entry : *distributedDepthsHashtable.getMap()) {
53 keys.push_back(entry.first);
54 }
55 //printEstimatedStorage();
56 int desiredValue = rank;
57
58
59#pragma omp parallel for schedule(dynamic)
60 for(std::size_t i = 0; i < keys.size(); ++i){
61 Depth T = keys[i];
62 int value = distributedDepthsHashtable.getNodeForDepth(T);
63 if(value == desiredValue)
64 {
65
66
67 stencilClass.initialize(T);
68
69 Depth Tcell = T;
70 ++Tcell;
71
72
73 std::vector<LocalStiffnessMatrixFixedDepthSymmetric> vector;
74
75 const SingleDepthHashCellStructure &depthGrid = cellData.getGridForDepth(Tcell);
76 const auto &map = depthGrid._map;
77 const auto end = depthGrid.getNumberOfEntries();
78
79
80
81 for (size_t i = 0; i < end; i++) {
82 CellDimension cellDimension = map.getIndexOfTable(i);
83 LocalStiffnessMatrixFixedDepthSymmetric localStiffnessMatrixFixedDepthSymmetric(cellDimension, sg, stencilClass);
84 numbercells++;
85
86
87
88 vector.push_back(localStiffnessMatrixFixedDepthSymmetric);
89 }
90 #pragma omp critical
91 pairedDepthsLocalStiffnessMatrices.push_back(std::make_pair(T, vector));
92 }
93 }*/
94
95 int j=0;
96 for (auto it = depthList.begin_all(); it != depthList.end_all(); ++it){
97 Depth T = *it;
98
99 int node = distributedDepthsHashtable.getNodeForDepth(T);
100
101 if (rank == node) {
102
103 struct timeval begin_time, end_time, end_time2;
104 long seconds;
105 long microseconds;
106 gettimeofday(&begin_time, 0);
107
108 stencilClass.initialize(T);
109
110 Depth Tcell = T;
111 ++Tcell;
112
113
114
115
116 const SingleDepthHashCellStructure &depthGrid = cellData.getGridForDepth(Tcell);
117 const auto &map = depthGrid._map;
118 const auto end = depthGrid.getNumberOfEntries();
119
120 //LocalStiffnessMatrixFixedDepthSymmetric ls_dummy(grid,stencilClass);
121
122 //std::vector<LocalStiffnessMatrixFixedDepthSymmetric> vector(end,ls_dummy);
123 std::vector<LocalStiffnessMatrixFixedDepthSymmetric> vector;
124 gettimeofday(&begin_time, 0);
125#pragma omp parallel for schedule(dynamic)
126 for (size_t i = 0; i < end; i++) {
127 CellDimension cellDimension = map.getIndexOfTable(i);
128 LocalStiffnessMatrixFixedDepthSymmetric localStiffnessMatrixFixedDepthSymmetric(cellDimension, sg, stencilClass);
129 numbercells++;
130
131//vector[i]=localStiffnessMatrixFixedDepthSymmetric;
132#pragma omp critical
133 vector.push_back(localStiffnessMatrixFixedDepthSymmetric);
134 }
135 gettimeofday(&end_time2, 0);
136 pairedDepthsLocalStiffnessMatrices.push_back(std::make_pair(T, vector));
137
138 seconds = end_time2.tv_sec - begin_time.tv_sec;
139 microseconds = end_time2.tv_usec - begin_time.tv_usec;
140 double t = seconds + microseconds * 1e-6;
141 if(t>time ) {
142 time = t;
143 numbercells_max=end;
144 Tmax=T;
145 }
146 if(t<time_min ){
147 time_min=t;
148 numbercells_min=end;
149
150 }
151
152 }
153 j++;
154 }
155
156 if(rank==0)cout << " number of depths " << j << endl;
157
158 };
159};
160
161
162#endif //RUN_LOCALSTIFFNESSMATRICESMEMORYDISTRIBUTION_H
Definition sparseGrid.h:277