This section shows you how to write a fast loop, and how efficient it is. Five examples will be demonstrated different ways o write the loop for the same purpose which is "sum a large matrix several times", as the following,

  1. "Sum by for 1" -- use for() loop to sum up the matrix by column.

  2. "Sum by for 2" -- use for() loop to sum up the matrix by row.

  3. "Sum by apply" -- use apply() function to sum up the matrix.

  4. "Sum by rowSums" -- use rowSums() internal function to sum up the matrix.

  5. "Sum by dyn" -- use "dynamical loading" to load external function to sum up the matrix.
Finally, the computing time of the above methods will be listed. The parallel version of these methods will be demonstrated and compared at the section of "LAM/MPI/Rmpi".