Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pugs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
code
pugs
Commits
ade3d9ad
Commit
ade3d9ad
authored
6 years ago
by
Stéphane Del Pino
Browse files
Options
Downloads
Patches
Plain Diff
Attempt to write some simple mesh dispatcher
Data structure my have to be reworked
parent
3d6ca051
No related branches found
No related tags found
1 merge request
!11
Feature/mpi
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/mesh/GmshReader.cpp
+127
-60
127 additions, 60 deletions
src/mesh/GmshReader.cpp
with
127 additions
and
60 deletions
src/mesh/GmshReader.cpp
+
127
−
60
View file @
ade3d9ad
...
...
@@ -141,90 +141,151 @@ ErrorHandler(const std::string& filename,
;
}
template
<
int
Dimension
>
void
GmshReader
::
_d
ispatch
()
class
MeshD
ispatch
er
{
using
ConnectivityType
=
Connectivity
<
Dimension
>
;
using
Rd
=
TinyVector
<
Dimension
>
;
using
MeshType
=
Mesh
<
ConnectivityType
>
;
if
(
not
m_mesh
)
{
std
::
shared_ptr
<
ConnectivityType
>
connectivity
(
new
ConnectivityType
({},{},{}));
NodeValue
<
Rd
>
xr
;
m_mesh
=
std
::
shared_ptr
<
IMesh
>
(
new
MeshType
(
connectivity
,
xr
));
}
const
MeshType
&
mesh
=
static_cast
<
const
MeshType
&>
(
*
m_mesh
);
public:
using
MeshType
=
Mesh
<
Connectivity
<
Dimension
>>
;
CSRGraph
mesh_graph
=
mesh
.
cellToCellGraph
();
private:
const
MeshType
&
m_mesh
;
using
CellListToSendByProc
=
std
::
vector
<
Array
<
const
CellId
>>
;
const
CellListToSendByProc
m_cell_list_to_send_by_proc
;
const
int
reader_rank
=
[
&
]()
{
Array
<
int
>
parts
=
allGather
(
static_cast
<
int
>
(
mesh
.
numberOfCells
()));
std
::
set
<
int
>
part_set
;
for
(
size_t
i
=
0
;
i
<
parts
.
size
();
++
i
)
{
if
(
parts
[
i
]
!=
0
)
{
part_set
.
insert
(
i
);
}
}
if
(
part_set
.
size
()
!=
1
)
{
perr
()
<<
"mesh should be read by one processor
\n
"
;
}
return
*
begin
(
part_set
);
}
();
Array
<
int
>
m_nb_cell_to_send_by_proc
;
Array
<
int
>
m_nb_cell_to_recv_by_proc
;
pout
()
<<
"Mesh read by process "
<<
rang
::
style
::
bold
<<
reader_rank
<<
rang
::
style
::
reset
<<
'\n'
;
const
CellListToSendByProc
_buildCellListToSend
()
const
{
CSRGraph
mesh_graph
=
m_mesh
.
cellToCellGraph
();
Partitioner
P
;
Array
<
int
>
cell_new_owner
=
P
.
partition
(
mesh_graph
);
const
std
::
vector
<
Array
<
const
CellId
>>
cell_to_send_by_proc
=
[
&
]
()
{
std
::
vector
<
std
::
vector
<
CellId
>>
cell_vector_to_send_by_proc
(
commSize
());
for
(
size_t
i
=
0
;
i
<
cell_new_owner
.
size
();
++
i
)
{
cell_vector_to_send_by_proc
[
cell_new_owner
[
i
]].
push_back
(
CellId
{
i
});
}
std
::
vector
<
Array
<
const
CellId
>>
cell_to_send_by_proc
(
commSize
());
std
::
vector
<
Array
<
const
CellId
>>
cell_
list_
to_send_by_proc
(
commSize
());
for
(
size_t
i
=
0
;
i
<
commSize
();
++
i
)
{
cell_to_send_by_proc
[
i
]
=
convert_to_array
(
cell_vector_to_send_by_proc
[
i
]);
cell_
list_
to_send_by_proc
[
i
]
=
convert_to_array
(
cell_vector_to_send_by_proc
[
i
]);
}
return
std
::
move
(
cell_to_send_by_proc
);
}
();
return
std
::
move
(
cell_
list_
to_send_by_proc
);
}
const
auto
&
cell_number
=
mesh
.
connectivity
().
cellNumber
();
const
std
::
vector
<
Array
<
const
int
>>
cell_number_to_send_by_proc
=
[
&
]
()
{
std
::
vector
<
Array
<
const
int
>>
cell_number_to_send_by_proc
(
commSize
());
Array
<
int
>
_buildNbCellToSend
()
{
Array
<
int
>
nb_cell_to_send_by_proc
(
commSize
());
for
(
size_t
i
=
0
;
i
<
commSize
();
++
i
)
{
const
Array
<
const
CellId
>&
cell_list
=
cell_to_send_by_proc
[
i
];
Array
<
int
>
cell_number_list
(
cell_list
.
size
());
nb_cell_to_send_by_proc
[
i
]
=
m_cell_list_to_send_by_proc
[
i
].
size
();
}
return
nb_cell_to_send_by_proc
;
}
public
:
template
<
typename
DataType
>
std
::
vector
<
Array
<
std
::
remove_const_t
<
DataType
>>>
exchange
(
const
CellValue
<
DataType
>&
cell_value
)
const
{
using
MutableDataType
=
std
::
remove_const_t
<
DataType
>
;
std
::
vector
<
Array
<
DataType
>>
cell_value_to_send_by_proc
(
commSize
());
for
(
size_t
i
=
0
;
i
<
commSize
();
++
i
)
{
const
Array
<
const
CellId
>&
cell_list
=
m_cell_list_to_send_by_proc
[
i
];
Array
<
MutableDataType
>
cell_value_list
(
cell_list
.
size
());
parallel_for
(
cell_list
.
size
(),
PASTIS_LAMBDA
(
const
CellId
&
cell_id
)
{
cell_number
_list
[
cell_id
]
=
cell_
number
[
cell_list
[
cell_id
]];
cell_value
_list
[
cell_id
]
=
cell_
value
[
cell_list
[
cell_id
]];
});
cell_
number
_to_send_by_proc
[
i
]
=
cell_
number
_list
;
cell_
value
_to_send_by_proc
[
i
]
=
cell_
value
_list
;
}
return
std
::
move
(
cell_number_to_send_by_proc
);
}
();
Array
<
int
>
nb_cell_to_send
_by_proc
(
commSize
());
std
::
vector
<
Array
<
MutableDataType
>>
recv_cell_value
_by_proc
(
commSize
());
for
(
size_t
i
=
0
;
i
<
commSize
();
++
i
)
{
nb_cell_to_send_by_proc
[
i
]
=
cell_to_
send
_by_proc
[
i
]
.
size
(
);
recv_cell_value_by_proc
[
i
]
=
Array
<
MutableDataType
>
(
m_nb_
cell_to_
recv
_by_proc
[
i
]);
}
Array
<
int
>
nb_cell_to_recv_by_proc
=
allToAll
(
nb_cell_to_send_by_proc
);
::
exchange
(
cell_value_to_send_by_proc
,
recv_cell_value_by_proc
);
return
std
::
move
(
recv_cell_value_by_proc
);
}
const
size_t
new_cell_number
=
mesh
.
numberOfCells
()
+
Sum
(
nb_cell_to_recv_by_proc
)
-
Sum
(
nb_cell_to_send_by_proc
);
[[
deprecated
]]
const
CellListToSendByProc
&
cell_list_to_send_by_proc
()
const
{
return
m_cell_list_to_send_by_proc
;
}
std
::
vector
<
Array
<
int
>>
recv_cell_number_by_proc
(
commSize
());
for
(
size_t
i
=
0
;
i
<
commSize
();
++
i
)
{
recv_cell_number_by_proc
[
i
]
=
Array
<
int
>
(
nb_cell_to_recv_by_proc
[
i
]);
MeshDispatcher
(
const
MeshType
&
mesh
)
:
m_mesh
(
mesh
),
m_cell_list_to_send_by_proc
(
_buildCellListToSend
()),
m_nb_cell_to_send_by_proc
(
_buildNbCellToSend
()),
m_nb_cell_to_recv_by_proc
(
allToAll
(
m_nb_cell_to_send_by_proc
))
{
;
}
exchange
(
cell_number_to_send_by_proc
,
recv_cell_number_by_proc
);
MeshDispatcher
(
const
MeshDispatcher
&
)
=
delete
;
~
MeshDispatcher
()
=
default
;
};
template
<
int
Dimension
>
void
GmshReader
::
_dispatch
()
{
using
ConnectivityType
=
Connectivity
<
Dimension
>
;
using
Rd
=
TinyVector
<
Dimension
>
;
using
MeshType
=
Mesh
<
ConnectivityType
>
;
if
(
not
m_mesh
)
{
std
::
shared_ptr
<
ConnectivityType
>
connectivity
(
new
ConnectivityType
({},{},{}));
NodeValue
<
Rd
>
xr
;
m_mesh
=
std
::
shared_ptr
<
IMesh
>
(
new
MeshType
(
connectivity
,
xr
));
}
const
MeshType
&
mesh
=
static_cast
<
const
MeshType
&>
(
*
m_mesh
);
MeshDispatcher
<
Dimension
>
dispatcher
(
mesh
);
std
::
vector
<
Array
<
int
>>
recv_cell_number_by_proc
=
dispatcher
.
exchange
(
mesh
.
connectivity
().
cellNumber
());
std
::
vector
<
Array
<
CellType
>>
recv_cell_type_by_proc
=
dispatcher
.
exchange
(
mesh
.
connectivity
().
cellType
());
// const std::vector<Array<const CellId>>& cell_to_send_by_proc
// = dispatcher.cell_list_to_send_by_proc();
// Array<int> nb_cell_to_send_by_proc(commSize());
// for (size_t i=0; i<commSize(); ++i) {
// nb_cell_to_send_by_proc[i] = cell_to_send_by_proc[i].size();
// }
// Array<int> nb_cell_to_recv_by_proc = allToAll(nb_cell_to_send_by_proc);
// const auto& cell_number = mesh.connectivity().cellNumber();
// const std::vector<Array<const int>> cell_number_to_send_by_proc
// = [&] () {
// std::vector<Array<const int>> cell_number_to_send_by_proc(commSize());
// for (size_t i=0; i<commSize(); ++i) {
// const Array<const CellId>& cell_list = cell_to_send_by_proc[i];
// Array<int> cell_number_list(cell_list.size());
// parallel_for (cell_list.size(), PASTIS_LAMBDA(const CellId& cell_id) {
// cell_number_list[cell_id] = cell_number[cell_list[cell_id]];
// });
// cell_number_to_send_by_proc[i] = cell_number_list;
// }
// return std::move(cell_number_to_send_by_proc);
// } ();
// std::vector<Array<int>> recv_cell_number_by_proc(commSize());
// for (size_t i=0; i<commSize(); ++i) {
// recv_cell_number_by_proc[i] = Array<int>(nb_cell_to_recv_by_proc[i]);
// }
// exchange(cell_number_to_send_by_proc, recv_cell_number_by_proc);
// std::vector<Array<CellType>> cell_type_to_send_by_proc
// = [&] () {
...
...
@@ -250,6 +311,12 @@ void GmshReader::_dispatch()
// barrier();
}
// const size_t new_cell_number
// = mesh.numberOfCells()
// + Sum(nb_cell_to_recv_by_proc)
// - Sum(nb_cell_to_send_by_proc);
Messenger
::
destroy
();
std
::
exit
(
0
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment