Next: Configuration Files
Up: Tutorial
Previous: Tutorial
Contents
Cactus allows you to write thorns using any mixture of Fortran 77,
Fortran 90, C and C++, in this case there is only one source code
routine in the thorn, and we have chosen to write this in C. Later we
will see how this routine can be scheduled to executed when
Cactus is run.
The actual code which prints is in the file
CactusExamples/HelloWorld/src/HelloWorld.c
Note that this file is listed in the thorn make file
CactusExamples/HelloWorld/src/make.code.defn
which informs Cactus to include this file when building executables.
The HelloWorld.c file contains the lines
C1. #include "cctk.h"
C2. #include "cctk_Arguments.h"
C3
C4. void HelloWorld(CCTK_ARGUMENTS)
C5. {
C6. DECLARE_CCTK_ARGUMENTS
C7.
C8. CCTK_INFO("Hello World !");
C9.
C10. return;
C11. }
Lets go through this line by line, and compare it to a standalone Hello World program written to match the lines of the Cactus routine.
S1. #include <stdio.h>
S2.
S3.
S4. int main()
S5. {
S6.
S7.
S8. printf("Hello World !\n");
S9.
S10. return 0;
S11. }
- Include Files (C1/C2): All source files which make use of Cactus infrastructure need to include cctk.h, this sets up the Cactus data types and prototypes Cactus functions. All scheduled functions also need to include cctk_Arguments.h which contains information about the data variables which are available to the function.
- Function Name (C4): Scheduled functions are always void, and the argument contains the macro CCTK_ARGUMENTS which is expanded during compilation to contain information about the data variable available to the function. In our simple case there are actually no data variables.
- Arguments Declaration (C6): This line defines any data variables
available to the routine, from this thorn and inherited from other thorns.
- Cactus Info (C8): Finally, the line to print to screen. We could
have just used printf("Hello World !
n") here as in the
standalone function, but here we actually use a Cactus function CCTK_INFO which formats output to screen to include the name of the
thorn. That isn't so useful here, but in cases where there are many
thorns it helps for understanding the screen output. Also, for more complicated applications running in parallel, the CCTK_INFO function controls which of the processors actually writes to screen (having 1024 processors each writing Hello World ! could look confusing!).
Next: Configuration Files
Up: Tutorial
Previous: Tutorial
Contents
|