This is an old revision of the document!
USE-statement should have an
ONLY:-clause, which lists the imported symbols [-Wuse-without-only].
OMP PARALLEL-region should declare
DEALLOCATE, the Fortran runtime takes care.
RANDOM_NUMBER(), it's not consistent across different compilers.
There are two measure of defense against spaghetti code:
PRIVATEand only few public symbols.
For many common operation there exist wrappers in CP2K to prevent usage errors and to allow for central redirections.
cp_files.Finstead of calling
fm-package instead of calling BLAS or Scalapack directly.
message_passing.Finstead of calling MPI directly.
machine.Fto access architecture depended things like e.g. the working directory.
iw=cp_logger_get_default_unit_nr()and write only if you actually received a unit:
IF(iw>0) WRITE (UNIT=iw, ,,,).
IF(debug_this_module)-block, with a parameter set to
.FALSE.. This way the code will stay up-to-date and easily callable.
.Ffile should contain either a
PROGRAMor a single
MODULE, whose name matches the filename.
INSTALL-file and added to the cp2k_flags function (cp2k_info.F).
make -j pretty.
SUBROUTINEshould be preceded by a valid doxygen block.
\param(for each parameter),
make doxifyto format your doxygen comments, or generate templates where none exist
Uniform formatting of CP2K source code will be enabled in the near future by a prettify script that is an almost complete auto-formatter for Fortran 90 source code. As a rule of thumb, developers should not worry about the format of their code and just let prettify do its magic by running
make -j pretty. The chosen formatting conventions for CP2K are as follows:
USEstatements, removal of unused list entries.
(/or with an assignment operator
=>. If none of the above is present, a default hanging indent of 3 characters is applied.
The following formatting decisions are still manual and are never changed by prettify:
IFstatements that are aligned with each other.
There may be cases where manual alignment is preferred over the rules stated above. The following options for manual formatting are provided:
A few examples to illustrate how to deal with cases where auto-formatting produces unsatisfying results:
! No: long_result_var_name = long_function_name(arg_1, arg_2, & arg_3, arg_4, arg_5)+ & foo ! Yes: long_result_var_name = & long_function_name( & arg_1, arg_2, & arg_3, arg_4, arg_5)+ & foo
! No: bessj0 = (r1+y*(r2+y*(r3+y*(r4+y* & (r5+y*r6)))))/(s1+y*(s2+y*(s3+y* & (s4+y*(s5+y*s6))))) ! Yes: bessj0 = (r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6)))))/ & (s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6)))))
! No: foo = bar+foobar(x1, y1, z1)* & foobar(x2, y2, z2)* & foobar(x3, y3, z3) ! Yes: foo = bar+(foobar(x1, y1, z1)* & foobar(x2, y2, z2)* & foobar(x3, y3, z3))
! Auto-formatting: align_me = [-1, 10, 0, & 0, 1000, 0, & 0, -1, 1] ! Manual alignment (!& disables whitespace formatting): align_me = [-1, 10, 0, & !& 0, 1000, 0, & !& 0, -1, 1] !& ! Alternatively: !&< align_me = [-1, 10, 0, & 0, 1000, 0, & 0, -1, 1] !&>