<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE article  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd"><article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="research article"><front><journal-meta><journal-id journal-id-type="publisher-id">IJG</journal-id><journal-title-group><journal-title>International Journal of Geosciences</journal-title></journal-title-group><issn pub-type="epub">2156-8359</issn><publisher><publisher-name>Scientific Research Publishing</publisher-name></publisher></journal-meta><article-meta><article-id pub-id-type="doi">10.4236/ijg.2017.89060</article-id><article-id pub-id-type="publisher-id">IJG-79102</article-id><article-categories><subj-group subj-group-type="heading"><subject>Articles</subject></subj-group><subj-group subj-group-type="Discipline-v2"><subject>Earth&amp;Environmental Sciences</subject></subj-group></article-categories><title-group><article-title>
 
 
  A Study on Parallel Computation Based on 3D Forward Algorithm of Gravity
 
</article-title></title-group><contrib-group><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>Mao</surname><given-names>Wang</given-names></name><xref ref-type="aff" rid="aff1"><sup>1</sup></xref><xref ref-type="corresp" rid="cor1"><sup>*</sup></xref></contrib><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>Yuanman</surname><given-names>Zheng</given-names></name><xref ref-type="aff" rid="aff1"><sup>1</sup></xref></contrib><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>Changli</surname><given-names>Yao</given-names></name><xref ref-type="aff" rid="aff1"><sup>1</sup></xref></contrib></contrib-group><aff id="aff1"><addr-line>School of Geophysics and Geoinformation Technology, China University of Geosciences, Beijing, China</addr-line></aff><author-notes><corresp id="cor1">* E-mail:<email>wangmao@cugb.edu.cn(MW)</email>;</corresp></author-notes><pub-date pub-type="epub"><day>14</day><month>09</month><year>2017</year></pub-date><volume>08</volume><issue>09</issue><fpage>1073</fpage><lpage>1079</lpage><history><date date-type="received"><day>11,</day>	<month>August</month>	<year>2017</year></date><date date-type="rev-recd"><day>12,</day>	<month>September</month>	<year>2017</year>	</date><date date-type="accepted"><day>15,</day>	<month>September</month>	<year>2017</year></date></history><permissions><copyright-statement>&#169; Copyright  2014 by authors and Scientific Research Publishing Inc. </copyright-statement><copyright-year>2014</copyright-year><license><license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p></license></permissions><abstract><p>
 
 
  Interpretation of geophysical material is the prospecting method. Interpretation of Gravity-megnetic data is based on data processing and inversion. When the grid is divided into several million cells, the computing task is heavy and time-consuming. In order to increase efficiency of the 3D forward modeling, the paper will adopt MPI parallel algorithm and the several processes will deal with data in the method. Finally, we can gather the result. Through comparing the result of sequence algorithm with the result of MPI parallel algorithm, we can see the result is the same. When the number of processes is 2 to 8, the speed-up ratio is 1.97 to 5. The MPI parallel algorithm is very efficient.
 
</p></abstract><kwd-group><kwd>Gravity</kwd><kwd> 3D Forward Modeling</kwd><kwd> Parallel Algorithm</kwd><kwd> MPI</kwd></kwd-group></article-meta></front><body><sec id="s1"><title>1. Introduction</title><p>Interpretation of Gravity-megnetic data is based on data processing and inversion. Forward modeling is important and difficult in the interpretation of geophysical data [<xref ref-type="bibr" rid="scirp.79102-ref1">1</xref>] [<xref ref-type="bibr" rid="scirp.79102-ref2">2</xref>] [<xref ref-type="bibr" rid="scirp.79102-ref3">3</xref>] , so we spend much time to do research on the problem and get much achievement. With the development of demand for geophysical data interpretation, 2D gravity-megnetic forward modeling can’t meet the requirement of identifying the geological structure, so we need to develop the gravity 3D forward modeling [<xref ref-type="bibr" rid="scirp.79102-ref4">4</xref>] [<xref ref-type="bibr" rid="scirp.79102-ref5">5</xref>] [<xref ref-type="bibr" rid="scirp.79102-ref6">6</xref>] . 3D forward modeling is very difficult and the increased computation task makes it more difficult. Many researchers do research on the problem and raise treatment method. Changli Yao adopts the grid separation and storage technology, the method decreases the computation tasks and storage [<xref ref-type="bibr" rid="scirp.79102-ref7">7</xref>] [<xref ref-type="bibr" rid="scirp.79102-ref8">8</xref>] , so it gets better effect. In the method we need to supplement many observation points. Zhaoxi Chen adopts the GPU parallel technology to accelerate the processing speed and it gets good effects [<xref ref-type="bibr" rid="scirp.79102-ref9">9</xref>] [<xref ref-type="bibr" rid="scirp.79102-ref10">10</xref>] . The paper adopts the MPI parallel technology to accelerate the processing speed of 3D forward modeling. It gets good effects.</p></sec><sec id="s2"><title>2. Gravity 3D Forward Modeling</title><p>We divide the source field underground into many cuboids (<xref ref-type="fig" rid="fig1">Figure 1</xref>). Forward modeling is the basic work of inversion [<xref ref-type="bibr" rid="scirp.79102-ref11">11</xref>] [<xref ref-type="bibr" rid="scirp.79102-ref12">12</xref>] . By means of traditional method that deals with the forward data one by one, the computation tasks will be huge and it will take a long time. The 3D density model forward equation illustrates the forward status. In the <xref ref-type="fig" rid="fig1">Figure 1</xref>, according the known equation we can get the gravity anomaly of the P(x,y,z) which is the jth cell.</p><p>Δ g j ( x , y , z ) = G σ j ∑ l = 1 2 ∑ m = 1 2 ∑ n = 1 2 ( − 1 ) l + m + n { ( x l − x ) ln [ ( y m − y ) + R l m n ] + ( y m − y ) ln [ ( x l − x ) + R l m n ] + ( z n − z ) tan − 1 ( z n − z ) R l m n ( x l − x ) ( y m − y ) } (1)</p><p>G is gravitational constant, σ<sub>j</sub> is the density of the jth cell.</p><p>R l m n = ( x l − x ) 2 + ( y m − y ) 2 + ( z n − z ) 2 (2)</p><p>By analyzing the equation, we know that in order to compute the gravity anomaly that the jth cell produces at the point P(x,y,z), we need to do so many computations: 16 times log, 8 times inverse trigonometric functions, 64 times multiplications, 8 times divisions, 8 times evolutions, 120 times additions or subtractions. The computation task is so huge for a cell at a point. If the number of the model cell is big, the total computation task will be very huge. The total computation is very huge, so the huge computation is a bottleneck problem.</p></sec><sec id="s3"><title>3. MPI Parallel Algorithm</title><sec id="s3_1"><title>3.1. Introduction of MPI</title><p>MPI realize the data broadcasting, data sending, data receiving and data synchronization [<xref ref-type="bibr" rid="scirp.79102-ref13">13</xref>] . MPI support several data type, including complex. Although</p><p>the MPI program is code, the program is different and it can identified by process ID. Different process has different computation task.</p><p>In the MPI program, every process has all the variates and functions. The variates and functions have the same name, but the data in the variate is always not the same. If the process needs to know the data of other process, it needs to communicate. Every process can allocate different memory for a pointer. When the task is different for a process in the 3D gravity forward algorithm, it needs to allocate memory more flexibly [<xref ref-type="bibr" rid="scirp.79102-ref14">14</xref>] [<xref ref-type="bibr" rid="scirp.79102-ref15">15</xref>] .</p></sec><sec id="s3_2"><title>3.2. The MPI Parallel Algorithm Based on 3D Gravity Forward</title><p>The gravity forward modeling is that the sum of the anomaly that every cuboid in the model produces. The serial program needs loop computation for 5 times. For the observing point, we need to calculate the point of x direction and y direction. For every point, we need calculate the sum of anomaly that the cell produces for x direction, y direction and z direction. The pseudo-code is following.</p><p>For(i=1;i &lt; nx_obs;i++) //observing x direction, nx_obs points</p><p>For(j=1;i&lt; ny_obs;i++) //observing x direction, ny_obs points</p><p>For(l=1;i &lt; nz_model;i++) //cells along the z direction，the number of cells along z direction is nz_model</p><p>For(m=1;i &lt; nx_model;i++) //cells along the x direction，the number of cells along x direction is nz_model</p><p>For(n=1;i &lt; ny_model;i++) //cells along the y direction，the number of cells along y direction is nz_model</p><p>forwarddata(I,j) =forwarddata (I,j)+forward(I,j,l,m,n)</p><p>We analyze the 3d gravity forward algorithm and find that the algorithm needs loop computation for 5 times. The loop is the main work for parallel computation. We can divide the nx_obs into several parts for processes. The computation task that every process in parallel algorithm needs to do is less than that in the serial algorithm. Firstly, we need to divide the computation task into several parts.</p><p>count = nx_obs / size; // observing along x direction, nx_obs points. Size is the number of processes</p><p>segment = nx_obs %size; //when tasks is allocated for every process equally, segment is the number of remainder</p><p>for (i = 0; i &lt; size; i++)</p><p>{</p><p>if (i &lt; segment)</p><p>parr[i] = count + 1;</p><p>else</p><p>parr[i] = count;</p><p>}</p><p>Parr is an array. The array records the computation task that every process needs to do. For example, nx_obs is 101, size is 4. We known parr[<xref ref-type="bibr" rid="scirp.79102-ref0">0</xref>] = 26, parr[<xref ref-type="bibr" rid="scirp.79102-ref1">1</xref>] = 25, parr[<xref ref-type="bibr" rid="scirp.79102-ref2">2</xref>] = 25, parr[<xref ref-type="bibr" rid="scirp.79102-ref3">3</xref>] = 25. The processes need to calculate 1 - 26, 27 - 51, 52 - 76, 77 - 101 row data, so every process do smaller task in the MPI algorithm than that in the serial algorithm.</p><p>The method uses MPI_Gatherv function to gather result. In the parallel algorithm, the program allocates the computation tasks, and every process only has his data result. If we don’t gather the data result, the process can write a file for the result data. For example the algorithm has 4 processes, we can get 4 files of data. If we want to get the final data result, we need merge 4 files manually. It is very difficult. MPI_Gatherv (forwarddata, count, MPI_FLOAT, forwarddata_all, rcounts, displs, MPI_FLOAT, 0, MPI_COMM_WORLD). The function MPI_Gatherv gathers the forwarddata to forwarddata_all and gathers the data from different process to one process. The length of the data can not the same. It is very useful.</p><p><xref ref-type="fig" rid="fig2">Figure 2</xref> is gravity 3D forward MPI algorithm flow chart. The program allocates the computation tasks to every process, and process 0 is the manager process. It reads the parameter file, and allocates the computation tasks to every process. It broadcasts the parameter to processes, and gathers the data result from processes. Finally, it writes the result file. Other processes receive the parameter, and do the computation tasks. They send the data result to the manager process. At the same time, manager process also do computation task. We will introduce the performing process.</p><p>(1) Initial the MPI environment, MPI_INT(). The manager process reads the model data and broadcasts the data to other process, MPI_Bcast().</p><p>(2) The manager process allocates the computation tasks according to the task</p><p>allocate <xref ref-type="table" rid="table1">Table 1</xref>. Processes do the tasks separately and get the forward data for every observed point.</p><p>(3) After all the processes have done the tasks, the manager process gathers the data.</p><p>(4) The manager process writes the data file and finalize the MPI environment, MPI_FINALIZE().</p><p>The MPI parallel environment</p><p>OS: windows 7</p><p>CPU: intel core i7 3.2 Ghz support 8 processes</p><p>Memory: 8 GB</p><p>Develop language: c</p><p>Compiler:visual studo 2010</p><p>Parallel environment: mpich2</p><p>Command: Mpiexec -np N ./gstd_forward N is the number of processes.</p></sec></sec><sec id="s4"><title>4. Result and Discussions</title><p>The grid of the model is 101 &#215; 101 &#215; 30. The model is 101 columns, 101 rows and 30 layers. The distance along x direction between 2 neighbor points is 10 m, the distance along y direction between 2 neighbor points is 10 m, the distance along z direction between 2 neighbor points is 2 m. The observed points are 101 &#215; 101 on the ground.</p><sec id="s4_1"><title>4.1. Validate of the Forward Result</title><p>The parallel computation is based on the serial program. According to the characteristics, that process does computation task separately. It distributes the tasks to all processes and never changes other algorithm, so the parallel computation result is the same with the serial program’s result. The study compares the forward result of two programs, the result is the same. We choose a line to draw a picture. In <xref ref-type="fig" rid="fig3">Figure 3</xref>, x axis is position of the observed point, y axis is the Δg forward data, dot is the MPI result and plus is the serial algorithm result. We can see that the forward data in 6th row is the same, so it proves the validity of the program.</p></sec><sec id="s4_2"><title>4.2. Discussions of Parallel Efficiency</title><p>Analysis of the <xref ref-type="table" rid="table2">Table 2</xref> shows that the efficiency is the highest when the number of processes is 2. The speedup changes slightly and the efficiency declines when</p><table-wrap id="table1" ><label><xref ref-type="table" rid="table1">Table 1</xref></label><caption><title> Task allocated Table</title></caption><table><tbody><thead><tr><th align="center" valign="middle" >Process ID</th><th align="center" valign="middle" >Computation task</th></tr></thead><tr><td align="center" valign="middle" >0</td><td align="center" valign="middle" >1 - 26</td></tr><tr><td align="center" valign="middle" >1</td><td align="center" valign="middle" >27 - 51</td></tr><tr><td align="center" valign="middle" >2</td><td align="center" valign="middle" >52 - 76</td></tr><tr><td align="center" valign="middle" >3</td><td align="center" valign="middle" >77 - 101</td></tr></tbody></table></table-wrap><table-wrap id="table2" ><label><xref ref-type="table" rid="table2">Table 2</xref></label><caption><title> 3D gravity forward parallel algorithm time used statistics</title></caption><table><tbody><thead><tr><th align="center" valign="middle" >The model of program</th><th align="center" valign="middle" >The amount of processes</th><th align="center" valign="middle" >The amount of the rows distributed for process</th><th align="center" valign="middle" >The size of 3D grid</th><th align="center" valign="middle" >The running time of program (minutes)</th><th align="center" valign="middle" >Parallel speedup</th><th align="center" valign="middle" >Parallel efficiency</th></tr></thead><tr><td align="center" valign="middle" >Serial program</td><td align="center" valign="middle" >1</td><td align="center" valign="middle" >101</td><td align="center" valign="middle" >101 &#215; 101 &#215; 30</td><td align="center" valign="middle" >65</td><td align="center" valign="middle" >empty</td><td align="center" valign="middle" >empty</td></tr><tr><td align="center" valign="middle"  rowspan="3"  >Parallel program</td><td align="center" valign="middle" >2</td><td align="center" valign="middle" >51, 50,</td><td align="center" valign="middle" >101 &#215; 101 &#215; 30</td><td align="center" valign="middle" >33</td><td align="center" valign="middle" >1.97</td><td align="center" valign="middle" >0.99</td></tr><tr><td align="center" valign="middle" >4</td><td align="center" valign="middle" >26, 25, 25, 25</td><td align="center" valign="middle" >101 &#215; 101 &#215; 30</td><td align="center" valign="middle" >20</td><td align="center" valign="middle" >3.25</td><td align="center" valign="middle" >0.81</td></tr><tr><td align="center" valign="middle" >8</td><td align="center" valign="middle" >13, 13, 13, 13, 13, 12, 12, 12</td><td align="center" valign="middle" >101 &#215; 101 &#215; 30</td><td align="center" valign="middle" >13</td><td align="center" valign="middle" >5</td><td align="center" valign="middle" >0.62</td></tr></tbody></table></table-wrap><p>the number of processes changes from 4 to 8. The communication of the processes occupy much time when the number of processes increases from 4 to 8. We can see that the effect of parallel algorithm is very obvious. When the number of processes is 8, we can save 52 minutes compared to sequential algorithm.</p></sec></sec><sec id="s5"><title>5. Conclusion</title><p>The computation of 3D gravity forward for relatively big grid spends much time and the forward algorithm is called for dozens of times, so the key to the problems is parallel computation. The study realizes the parallel algorithm for 3D gravity forward in the MPI environment. The algorithm is proved correct and efficient. The study lays the foundation of the parallel computation for 3D gravity inversion.</p></sec><sec id="s6"><title>Funding</title><p>The paper is supported by China university of Geosciences (Beijing) basic research funding (2-9-2017-096).</p></sec><sec id="s7"><title>Cite this paper</title><p>Wang, M., Zheng, Y.M. and Yao, C.L. (2017) A Study on Parallel Computation Based on 3D forward Algorithm of Gravity. International Journal of Geosciences, 8, 1073-1079. https://doi.org/10.4236/ijg.2017.89060</p></sec></body><back><ref-list><title>References</title><ref id="scirp.79102-ref1"><label>1</label><mixed-citation publication-type="other" xlink:type="simple">Yang, W.C., Shi, Z.Q., Hou, Z.Z., et al. (2001) Discrete Wavelet Transform and Gravity Anomaly Decomposition. Chinese Journal of Geophysics, 44, 534-541.</mixed-citation></ref><ref id="scirp.79102-ref2"><label>2</label><mixed-citation publication-type="other" xlink:type="simple">Li, J. and Zhou, Y.X. (2000) Principle of Multi-Scale Gravity-Magnetic Field. Global geology, 19, 379-391.</mixed-citation></ref><ref id="scirp.79102-ref3"><label>3</label><mixed-citation publication-type="other" xlink:type="simple">Yang, Y.S., Liu, T.Y. and Li, Y.Y. (2005) The Three-Dimensional Visualization Inversion of the Gravity-Magnetic Field for Arbitrary Shape by Means of Numerical Integration. Geology and Prospecting.</mixed-citation></ref><ref id="scirp.79102-ref4"><label>4</label><mixed-citation publication-type="other" xlink:type="simple">Lin, Z.M. and Chen, S.Q. (1996) 3D Gravity-Magnetic Interaction Interpretation and Separation of Regional and Local Anomalies. Chinese Journal of Geophysics, 39, 705-711.</mixed-citation></ref><ref id="scirp.79102-ref5"><label>5</label><mixed-citation publication-type="other" xlink:type="simple">Yao, C.L., Zheng, Y.M. and Zhang, Y.W. (2007) 3D Gravity-Magnetic Inversion by Means of Random Subdomain Method. Chinese Journal of Geophysics, 50, 1576-1583.</mixed-citation></ref><ref id="scirp.79102-ref6"><label>6</label><mixed-citation publication-type="other" xlink:type="simple">Yao, C.L., Hao, T.Y., et al. (2003) The High Speed Computation and Storage Method for 3D Gravity-Magnetic Genetic Inversion Algorithm. Chinese Journal of Geophysics, 46, 252-258</mixed-citation></ref><ref id="scirp.79102-ref7"><label>7</label><mixed-citation publication-type="other" xlink:type="simple">Zheng, Y.M. (2011) The Research of 3D Gravity-Magnetic Real-Time and Visualization. PHD Paper, China University of Geosciences, Beijing.</mixed-citation></ref><ref id="scirp.79102-ref8"><label>8</label><mixed-citation publication-type="other" xlink:type="simple">Yao, C.L. and Guan, Z.N. (1997) Computation of Magnetic Gradients Due to Three-Dimensional Bodies. Science in China Series D: Earth Sciences, 40, 293-299.</mixed-citation></ref><ref id="scirp.79102-ref9"><label>9</label><mixed-citation publication-type="other" xlink:type="simple">Zhang, S. (2009) High-Performance Computing, CUDA. China WaterPower Press, Beijing.</mixed-citation></ref><ref id="scirp.79102-ref10"><label>10</label><mixed-citation publication-type="other" xlink:type="simple">Chen, Z.X., Meng, X.H., Guo, L.H., Liu, G.F. (2012) GPU Parallel High Speed Computation for 3D Gravity and Gravity Gradient Forward and Inversion Algorithm.</mixed-citation></ref><ref id="scirp.79102-ref11"><label>11</label><mixed-citation publication-type="other" xlink:type="simple">Yao, C.L. and Zheng, Y.M. (2002) Dynamic Array Optimization for 3D Gravity-Magnetic Genetic Inversion Algorithm. Computing Techniques for Geophysical and Geochemical, 24, 240-245.</mixed-citation></ref><ref id="scirp.79102-ref12"><label>12</label><mixed-citation publication-type="other" xlink:type="simple">Shen, N.H. and Guan, Z.N. (1985) Magnetic Prospecting. Geological Publish House, London.</mixed-citation></ref><ref id="scirp.79102-ref13"><label>13</label><mixed-citation publication-type="other" xlink:type="simple">Du, Z.H. (2001) Parallel Computation Technology.</mixed-citation></ref><ref id="scirp.79102-ref14"><label>14</label><mixed-citation publication-type="other" xlink:type="simple">Zhang, W.S. and Xue, W. (2009) Parallel Programming with MPI. Tsinghua University Press, Beijing.</mixed-citation></ref><ref id="scirp.79102-ref15"><label>15</label><mixed-citation publication-type="other" xlink:type="simple">Wang, M., Tan, H.D., Lin, C.H., et al. (2015) A Study on Parallel Computation Based on Finite element Forward Modeling of 2D Magnetotelluric. International Journal of Geosciences, 6, 863-868. https://doi.org/10.4236/ijg.2015.68070</mixed-citation></ref></ref-list></back></article>