main.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ///////////////////////////////////////////////////////////////////////////////////////
  2. /// \file main.cpp
  3. /// \brief Main module for command line version of LPJ-GUESS
  4. ///
  5. /// \author Ben Smith
  6. /// $Date: 2014-05-13 14:55:59 +0200 (Tue, 13 May 2014) $
  7. ///
  8. ///////////////////////////////////////////////////////////////////////////////////////
  9. #include "config.h"
  10. #include "guess.h"
  11. #include "framework.h"
  12. #include "commandlinearguments.h"
  13. #include "parallel.h"
  14. #include <stdlib.h>
  15. #include "eceframework.h"
  16. #ifdef __unix__
  17. // includes needed for umask()
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20. #endif
  21. ///////////////////////////////////////////////////////////////////////////////////////
  22. // LOG FILE
  23. // The name of the log file to which output from all dprintf and fail calls is sent is
  24. // set here
  25. xtring file_log="guess.log";
  26. // ecev3 - needed to initialise MPI with call to init(.,.) below.
  27. using namespace GuessParallel;
  28. ///////////////////////////////////////////////////////////////////////////////////////
  29. // MAIN
  30. // This is the function called when the executable is run
  31. int main(int argc,char* argv[]) {
  32. // Initialize parallel communication if available.
  33. // This needs to be done before command line parsing since some MPI
  34. // implementations put their own arguments in our command line
  35. // (which should then be removed after the MPI initialization).
  36. // ecev3 - moved this line from it's previous position below.
  37. // Set our shell for the model to communicate with the world
  38. set_shell(new CommandLineShell(file_log));
  39. dprintf("Welcome to LPJ-GUESS! \n");
  40. #ifdef __unix__
  41. // On unix systems we set the umask (which controls the file permissions
  42. // of files we create). Some MPI implementations set a restrictive umask
  43. // which would mean that other users can't read the files generated by
  44. // LPJ-GUESS.
  45. umask(S_IWGRP | S_IWOTH); // only disable write access for group and others
  46. #endif
  47. // Parse command line arguments
  48. CommandLineArguments args(argc, argv);
  49. dprintf("Read CommandLineArguments ... \n");
  50. // ecev3 - initialise MPI if needed.
  51. init(argc, argv);
  52. // run_ecev3_not_cruncep
  53. // Change working directory according to rank if parallel, spinup run
  54. if (args.get_parallel() && args.get_islpjgspinup() && !ECEARTHWITHCRUNCEP) {
  55. int thisrank = GuessParallel::get_rank();
  56. xtring path;
  57. path.printf("./run%d", thisrank+1); // ecev3 - was rank+1
  58. dprintf("\nParallel LPJ-GUESS spinup, so creating directory on node %d\n",thisrank);
  59. if (change_directory(path) != 0) {
  60. fprintf(stderr, "Failed to change to run directory for a parallel LPJ-GUESS spinup\n");
  61. return EXIT_FAILURE;
  62. }
  63. }
  64. // run_cruncep_not_ecev3
  65. // Change working directory according to rank if parallel run
  66. if (args.get_parallel() && ECEARTHWITHCRUNCEP) {
  67. xtring path;
  68. path.printf("./run%d", GuessParallel::get_rank() + 1);
  69. if (change_directory(path) != 0) {
  70. fprintf(stderr, "Failed to change to run directory\n");
  71. return EXIT_FAILURE;
  72. }
  73. }
  74. // Set our shell for the model to communicate with the world
  75. // set_shell(new CommandLineShell(file_log)); // ecev3 - moved up!
  76. if (args.get_help()) {
  77. printhelp();
  78. return EXIT_SUCCESS;
  79. }
  80. // Call the framework
  81. if (ECEARTHWITHCRUNCEP) {
  82. framework(args); // run_cruncep_not_ecev3
  83. }
  84. // ecev3 - call ecemain in eceframework.cpp instead
  85. if (!ECEARTHWITHCRUNCEP) {
  86. ecemain(args); // run_ecev3_not_cruncep
  87. }
  88. // Say goodbye
  89. dprintf("\nFinished\n");
  90. return EXIT_SUCCESS;
  91. }