Skip to content

Commit 43fd1cc

Browse files
committed
Minor formatting
1 parent 3ee4679 commit 43fd1cc

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

chapters/Coding_style.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
If a function does not fit in its entirety on a single screen, it is too long---split it up.
4646
Don't worry about the overhead of calling a function.
4747
If you use optimization flags like \texttt{-O3}, the compiler will try to inline them anyway.
48-
\item\textbf{Modules}---\marginnote{It's also a good idea to put all physical parameters (number of particles, $\pi$, $c$, $k_B$, etc.) into their own module, even if they're just constant numbers. You can then ``load'' the parameters into your subroutines with the \keyword{use} statement instead of having absurdly long lists of arguments, or worse, global variables.}Separate your program into logical units.
49-
Combine related functions and subroutines into modules.
48+
\item\textbf{Modules}---Separate your program into logical units.
49+
Combine related functions and subroutines into modules\footnote{It's also convenient to put all physical parameters (number of particles, $\pi$, $c$, $k_B$, etc.) into their own module, even if they're just constant numbers. You can then ``load'' the parameters into your subroutines with the \keyword{use} statement instead of having absurdly long lists of arguments, or worse, global variables.}.
5050
For example, a single module with function integrators, or ODE solvers.
5151
If you use the object-oriented features of Fortran, it is also good practice to create separate modules for classes, \eg, a sparse-matrix object.
5252
\item\textbf{Comments}---Comments are kind of a double-edged sword.

chapters/Optimization.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ \section{Some optimizations you are allowed to use}
7979
i & j & k & l
8080
\end{bmatrix}
8181
\end{equation*}
82-
is actually stored in memory\footnote{Notice, column-major ordering means the leftmost index moves the fastest as one traverses consecutive memory entries. Predictably, row-major ordering means the same for the rightmost index.} as $\left[a,e,i,b,f,j,c,g,k,d,h,l\right]$.
82+
is actually stored in memory as $\left[a,e,i,b,f,j,c,g,k,d,h,l\right]$.
8383
Because of this, operations within a single column are much faster than operations within a single row; the processor can easily load a whole column into the cache, but not a whole row.
8484
It is therefore important to carefully consider your array layout.
8585
For example, if you have an array containing the coordinates of many particles, then a $3\times n$ layout will be more efficient than $n\times 3$.

chapters/Structuring_your_code.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ \section{Functions and subroutines}
3131
Fortran subroutines are invoked with the keyword \keyword{call} followed by the name of the routine and an optional list of parameters in parentheses.
3232
The code for the subroutine itself appears after the keyword \keyword{contains}.
3333
We don't have to type \keyword{implicit none} again, since that's inherited from the program.
34-
\marginnote{A \textbf{big} fortran gotcha involves initializing local variables while declaring them (\ie\ \lstinline$real :: x = 10.0$). Variables like this have an implicit \keyword{save}\index{Fortran!save@\keyword{save}} statement, meaning they retain their value through subsequent calls to the subroutine. It's best to either mark these variables with the \keyword{save} attribute explicitly \emph{or} separate initialization from declaration within subroutines and functions.}
34+
\marginnote{A \textbf{big} fortran gotcha involves initializing local variables while declaring them (\ie\ \lstinline$real :: x = 10.0$). Variables like this have an implicit \keyword{save}\index{Fortran!save@\keyword{save}} statement, meaning they retain their value through subsequent calls to the subroutine. It's a good idea to either mark these variables with the \keyword{save} attribute explicitly \emph{or} separate initialization from declaration within subroutines and functions.}
3535
When declaring the parameters, we need to specify not only the type, but also how we're going to use them, \ie, the \emph{intent}.\index{Fortran!intent(in/out)@\keyword{intent} (\keyword{in}/\keyword{out})}
3636
For input and output parameters, we use \texttt{\keyword{intent}(\keyword{in})} and \texttt{\keyword{intent}(\keyword{out})}, respectively.
3737
For parameters functioning as both, we use \texttt{\keyword{intent}(\keyword{inout})}.

0 commit comments

Comments
 (0)