main.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. // this is now now done in runlpjguess()
  55. //if (args.get_parallel() && args.get_islpjgspinup() && !ECEARTHWITHCRUNCEP) {
  56. if (false) {
  57. int thisrank = GuessParallel::get_rank();
  58. xtring path;
  59. path.printf("./run%d", thisrank+1); // ecev3 - was rank+1
  60. dprintf("\nParallel LPJ-GUESS spinup, so creating directory on node %d\n",thisrank);
  61. if (change_directory(path) != 0) {
  62. fprintf(stderr, "Failed to change to run directory for a parallel LPJ-GUESS spinup\n");
  63. return EXIT_FAILURE;
  64. }
  65. }
  66. // run_cruncep_not_ecev3
  67. // Change working directory according to rank if parallel run
  68. if (args.get_parallel() && ECEARTHWITHCRUNCEP) {
  69. xtring path;
  70. path.printf("./run%d", GuessParallel::get_rank() + 1);
  71. if (change_directory(path) != 0) {
  72. fprintf(stderr, "Failed to change to run directory\n");
  73. return EXIT_FAILURE;
  74. }
  75. }
  76. // Set our shell for the model to communicate with the world
  77. // set_shell(new CommandLineShell(file_log)); // ecev3 - moved up!
  78. if (args.get_help()) {
  79. printhelp();
  80. return EXIT_SUCCESS;
  81. }
  82. // Call the framework
  83. if (ECEARTHWITHCRUNCEP) {
  84. framework(args); // run_cruncep_not_ecev3
  85. }
  86. // ecev3 - call ecemain in eceframework.cpp instead
  87. if (!ECEARTHWITHCRUNCEP) {
  88. ecemain(args); // run_ecev3_not_cruncep
  89. }
  90. // Say goodbye
  91. dprintf("\nFinished\n");
  92. return EXIT_SUCCESS;
  93. }