PageRenderTime 60ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/docs/codemanagement.html

https://bitbucket.org/alexei-matveev/petsc-debian-pkg
HTML | 248 lines | 208 code | 40 blank | 0 comment | 0 complexity | a37bcd4f57abd317f5fcb5732cbad99f MD5 | raw file
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head> <link rel="canonical" href="http://www.mcs.anl.gov/petsc/petsc-current/docs/codemanagement.html" />
  4. <meta http-equiv="content-type" content="text/html;charset=utf-8">
  5. <title>Documentation: Code Management</title>
  6. </head>
  7. <body bgcolor="#ffffff">
  8. <div id="version" align=right><b>petsc-3.3-p3 2012-08-29</b></div>
  9. <h1>Documentation: Code Management</h1>
  10. <div id="main">
  11. <p>
  12. In this file we list some of the techniques that may be used to increase
  13. one's efficiency when developing PETSc application codes. We have learned
  14. to use these techniques ourselves, and they have improved our efficiency
  15. tremendously.
  16. </p>
  17. <h2>Editing and Compiling</h2>
  18. <p>
  19. The biggest time sink in code development is generally the cycle of
  20. EDIT-COMPILE-LINK-RUN. We often see users working in a single window
  21. with a cycle such as:
  22. </p>
  23. <ul>
  24. <li>Edit a file with <code>emacs</code>.</li>
  25. <li>Exit <code>emacs</code>.</li>
  26. <li>Run <code>make</code> and see some error messages.</li>
  27. <li>
  28. Start <code>emacs</code> and try to fix the errors; often starting
  29. <code>emacs</code> hides the error messages so that users cannot
  30. remember all of them and thus do not fix all the compiler errors.
  31. </li>
  32. <li>Run <code>make</code> generating a bunch of object (.o) files.</li>
  33. <li>
  34. Link the executable (which also removes the .o files).
  35. Users may delete the .o files because they anticipate compiling
  36. the next time on a different machine that uses a different
  37. compiler.
  38. </li>
  39. <li>Run the executable.</li>
  40. <li>Detect some error condition and restart the cycle.</li>
  41. </ul>
  42. <p>
  43. In addition, during this process the user often moves manually
  44. among different directories for editing, compiling, and running.
  45. </p>
  46. <h2>Several easy ways to improve the cycle:</h2>
  47. <ul>
  48. <li>
  49. <code>emacs</code> has a feature to allow the user to compile using make
  50. and have the editor automatically jump to the line of source
  51. code where the compiler detects an error, even when not
  52. currently editing the erroneous file.
  53. </li>
  54. <li>
  55. The etags feature of <code>emacs</code> enables one to search quickly
  56. through a group of user-defined source files (and/or PETSc
  57. source files) regardless of the directory in which they are located.
  58. Etags usage tips (where <code>M-</code> denotes the "meta" key in <code>emacs</code>):
  59. <ul>
  60. <li>
  61. To access the predefined PETSc tags in <code>emacs</code>, type
  62. <code>M-x visit-tags-table</code> and specify the file
  63. <code>${PETSC_DIR}/TAGS</code>
  64. </li>
  65. <li>
  66. To move to where a PETSc function is defined, enter <code>M-.</code>
  67. This is useful for viewing manpages and locating source code.
  68. </li>
  69. <li>
  70. To search for a string and move to the first
  71. occurrence, use <code>M-x tags-search</code> Then, to locate later
  72. occurrences, type <code>M-,</code> In particular, this is useful for
  73. quickly locating examples of usage of certain PETSc routines.
  74. </li>
  75. <li>
  76. Another quite helpful command is <code>M-x tags-query-replace</code>
  77. which replaces occurrences of a string hroughout all tagged
  78. files (can retain any entries if desired); this enables quick and
  79. painless revisions of source code, particularly when routines are
  80. spread throughout many files and directories.
  81. </li>
  82. </ul>
  83. </li>
  84. <li>
  85. Also, <code>emacs</code> easily enables:
  86. <ul>
  87. <li>editing files that reside in any directory and retaining one's place within each of them</li>
  88. <li>searching for files in any directory as one attempts to load them into the editor</li>
  89. </ul>
  90. </li>
  91. </ul>
  92. <p>
  93. Admittedly, it takes a while to get the hang of using <code>emacs</code>.
  94. But we've found that the increase in our programming efficiency has
  95. been well worth the time spent learning to use this editor. We
  96. seriously believe that we could not have developed PETSc as it is today
  97. if we had not switched to <code>emacs</code>.
  98. </p>
  99. <p>
  100. <code>vi</code> and <code>Eclipse</code> also provide tools for quickly finding things
  101. and searching in PETSc source code, see the Emacs, VI/Vim and Eclipse
  102. sections of the <a href="http://www.mcs.anl.gov/petsc/petsc-dev/docs/manual.pdf">users manual</a>.
  103. <a href="http://gnu.org/s/global">GNU Global</a> is a richer alternative to
  104. etags, see the user's manual for more details.<br>
  105. </p>
  106. <h2>Debugging</h2>
  107. <p>
  108. Most code development for PETSc codes should be done on one processor;
  109. hence, using a standard debugger such as dbx, gdb, xdbx, etc. is fine.
  110. For debugging parallel runs we suggest <b>Totalview</b> if it
  111. is available on your machine. Otherwise, you can run each process in
  112. a separate debugger; this is not the same as using a parallel debugger,
  113. but in most cases it is not so bad. The PETSc run-time options
  114. <code>-start_in_debugger</code> [-display xdisplay:0] will open
  115. separate windows and debuggers for each process. You should debug using
  116. the debugging versions of the libraries (run ./configure with the
  117. additional option --with-debugging (the default)).
  118. </p>
  119. <p>
  120. It really pays to learn how to use a debugger; you will end up
  121. writing more interesting and far more ambitious codes once it
  122. is easy for you to track down problems in the codes.
  123. </p>
  124. <h2>Other suggestions</h2>
  125. <ul>
  126. <li>
  127. Choose consistent and obvious names for variables and functions.
  128. (Short variable names may be faster to type, but by using longer
  129. names you don't have to remember what they represent since it is
  130. clear from the name.)
  131. </li>
  132. <li>Use informative comments.</li>
  133. <li>Leave space in the code to make it readable.</li>
  134. <li>
  135. Line things up in the code for readability. Remember that any code
  136. written for an application will be visited <b>over and
  137. over</b> again, so spending an extra 20 percent of effort on
  138. it the first time will make each of those visits faster and more
  139. efficient.
  140. </li>
  141. <li>
  142. Realize that you <b>will</b> have to debug your code.
  143. <b>No one</b> writes perfect code, so always write code
  144. that may be debugged and learn how to use a debugger. In most cases
  145. using the debugger to track down problems is much faster than using
  146. print statements.
  147. </li>
  148. <li>
  149. <b>Never</b> hardwire a large problem size into your code.
  150. Instead, allow a command line option to run a small problem. We've
  151. seen people developing codes who have to wait 15 minutes after
  152. starting a run to reach the crashing point; this is an inefficient
  153. way of developing code.
  154. </li>
  155. <li>
  156. Develop your code on the simplest machine to which you have access.
  157. We have accounts on a variety of large parallel machines, but we
  158. write and initially test all our code on laptops or workstations
  159. because the user interface is friendlier, and the turn-around time
  160. for compiling and running is much faster than for the parallel
  161. machines. We use the parallel machines only for large jobs. Since
  162. PETSc code is completely portable, switching to a parallel machine
  163. from our laptop/workstation development environment simply means
  164. logging into another machine -- there are no code or makefile
  165. changes.
  166. </li>
  167. <li>
  168. Never develop code directly on a multi-node computing system; your
  169. productivity will be much lower than if you developed on
  170. a well-organized workstation.
  171. </li>
  172. <li>
  173. Keep your machines' operating systems and compilers up-to-date (or
  174. force your systems people to do this :-). You should always work with
  175. whatever tools are currently the best available. It may seem that you
  176. are saving time by not spending the time upgrading your system, but,
  177. in fact, your loss in efficiency by sticking with an outdated system
  178. is probably larger than then the time required to keep it up-to-date.
  179. </li>
  180. </ul>
  181. <h2>Fortran notes</h2>
  182. <p>
  183. Since Fortran77 does not provide type checking of routine input/output
  184. parameters, we find that many errors encountered within PETSc Fortran77
  185. programs result from accidentally using incorrect calling sequences.
  186. Thus, if your Fortran program is crashing, one of the first things to
  187. check is that all subroutines are being called with the correct arguments.
  188. </p>
  189. <p>
  190. When passing floating point numbers into Fortran subroutines, always
  191. make sure you have them marked as double precision (e.g., pass in 10.d0
  192. instead of 10.0). Otherwise, the compiler interprets the input as
  193. a single precision number, which can cause crashes or other mysterious
  194. problems. Make sure to declare all variables (do not use the implicit
  195. feature of Fortran). In fact, we <b>highly</b> recommend
  196. using the <b>implicit none</b> option at the begining of each
  197. Fortran subroutine you write.
  198. </p>
  199. <p>
  200. Fortran 90 provides the ability to do some type checking of subroutine
  201. calls by using Fortran 90 interfaces or modules. PETSc now provides
  202. interfaces and modules for Fortran 90; see the
  203. <a href="manualpages/Sys/UsingFortran.html">manual page</a>
  204. for how to use them.
  205. </p>
  206. </div>
  207. </body>
  208. </html>