I have an implementation question with MPI and OPENMP.
I have a large three-dimensional surface mesh divided into elements. I want to loop over each element (outer loop) and compute an integral over the whole surface (inner loop). There are two loops in total. I wish to parallelise this operation.
This kind of operation occurs in boundary element methods. For example, such an operation is needed to solve the electrostatic potential on an arbitrary surface. The first loop goes through every evaluation points $\boldsymbol{x}_0$ at the centre of each element and the second loop performs the integration for this particular $\boldsymbol{x}_0$:
$\phi (\boldsymbol{x}_0) = -\int\limits_S G(\boldsymbol{x}_0, \boldsymbol{x}) [\boldsymbol{n}(\boldsymbol{x})\boldsymbol{\cdot}\boldsymbol{\nabla} \phi (\boldsymbol{x})] + \phi (\boldsymbol{x})[\boldsymbol{n}(\boldsymbol{x})\boldsymbol{\cdot}\boldsymbol{\nabla}G(\boldsymbol{x}_0, \boldsymbol{x}) ]~ \mathrm{d}S$
where $G(\boldsymbol{x}_0, \boldsymbol{x})=1/4\pi|\boldsymbol{x}_0-\boldsymbol{x}|$ is the free-space Green's function for Laplace equation and $\phi$ is the unknown potential that we want to solve for some given boundary conditions.
MPI: Here I have two options.
I can generate the mesh in one processor and broadcast it to all the others. Then I can divide the integration work amongst the processors. Let's say I have N_elm elements and n_procs processors, then each processor be responsible for integrating (N_elm/n_procs) elements. (Question) While this will not require any communication when doing the integration, will this make n_procs copies of the mesh in the memory?
I generate the mesh in one processor, divide it into (N_elm/n_procs) elements, so that each processor only has a part of the domain. Each processor will be able to loop over its own element and integrate locally over its part of the mesh. However, for integrating over parts of mesh it doesn't have communication will be required. So, I can create a temporary array for each processor of size [(N_elm/n_procs) elements * 3] for this purpose. In total, each processor will then have created 2*[(N_elm/n_procs) elements * 3], one for its own mesh and a second temporary one which gets replaced.
(Question) Is 1 or 2 preferable, or there is a 3rd option?
OPENMP: Here the implementation is easier. (Question) What happens under the hood when I create a mesh and parallelise the for-loop? Are the threads given multiple copies of the entire mesh similar to number (1) above or the threads share the mesh between each other, more like number (2) above.