<commit_before>/*
 * pv.cpp
 *
 */


#include <columns/buildandrun.hpp>
#include <io/RequireAllZeroActivityProbe.hpp>
#include <layers/Movie.cpp>

#define MAIN_USES_CUSTOMGROUPS
#define CORRECT_PVP_NX 32 // The x-dimension in the "correct.pvp" file.  Needed by generate()
#define CORRECT_PVP_NY 32 // The y-dimension in the "correct.pvp" file.  Needed by generate()
#define CORRECT_PVP_NF 8 // The number of features in the "correct.pvp" file.  Needed by generate()

int copyCorrectOutput(HyPerCol * hc, int argc, char * argv[]);
int assertAllZeroes(HyPerCol * hc, int argc, char * argv[]);

int generate(int argc, char * argv[], int rank);
int testrun(int argc, char * argv[], int rank);
int testcheckpoint(int argc, char * argv[], int rank);
int testioparams(int argc, char * argv[], int rank);

void * customgroup(const char * name, const char * groupname, HyPerCol * hc);
// customgroups is for adding objects not supported by build().

int main(int argc, char * argv[]) {
   int rank = 0;
#if PV_USE_MPI
   MPI_Init(&argc, &argv);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif // PV_USE_MPI

   int pv_argc = 0;
   bool generateFlag = false; // Flag for whether to generate correct output for future tests; don't check the RequireAllZeroActivity probe
   bool testrunFlag = false;  // Flag for whether to run from params and then check the RequireAllZeroActivity probe
   bool testcheckpointFlag = false;  // Flag for whether to run from checkpoint and then check the RequireAllZeroActivity probe
   bool testioparamsFlag = false; // Flag for whether to run from the output pv.params and then check the RequireAllZeroActivity probe
   char ** pv_argv = (char **) calloc((size_t) (argc+1), sizeof(char *));
   if (pv_argv==NULL) {
      fprintf(stderr, "Error allocating memory in rank %d process: %s\n", rank, strerror(errno));
      abort();
   }

   // Run through the command line arguments.  If an argument is any of
   // --generate
   // --testrun
   // --testcheckpoint
   // --testioparams
   // --testall
   // set the appropriate test flags
   for (int arg=0; arg<argc;arg++) {
      const char * thisarg = argv[arg];
      if (!strcmp(thisarg, "--generate")) {
         generateFlag = true;
      }
      else if (!strcmp(thisarg, "--testrun")) {
         testrunFlag = true;
      }
      else if (!strcmp(thisarg, "--testcheckpoint")) {
         testcheckpointFlag = true;
      }
      else if (!strcmp(thisarg, "--testioparams")) {
         testioparamsFlag = true;
      }
      else if (!strcmp(thisarg, "--testall")) {
         testrunFlag = true;
         testcheckpointFlag = true;
         testioparamsFlag = true;
      }
      else {
         pv_argv[pv_argc] = argv[arg];
         pv_argc++;
         assert(pv_argc<=argc);
      }
   }
   pv_argv[pv_argc]=NULL;
   if (generateFlag && (testrunFlag||testcheckpointFlag||testioparamsFlag)) {
      if (rank==0) {
         fprintf(stderr, "%s error: --generate option conflicts with the --test* options.\n", argv[0]);
      }
      MPI_Barrier(MPI_COMM_WORLD); // Make sure no child processes take down the MPI environment before root process prints error message.
      exit(EXIT_FAILURE);
   }
   if (!(generateFlag||testrunFlag||testcheckpointFlag||testioparamsFlag)) {
      if (rank==0) {
         fprintf(stderr, "%s error: At least of \"--generate\", \"--testrun\", \"--testcheckpoint\", \"testioparams\" must be selected.\n", argv[0]);
      }
      MPI_Barrier(MPI_COMM_WORLD); // Make sure no child processes take down the MPI environment before root process prints error message.
      exit(EXIT_FAILURE);
   }
   assert(generateFlag||testrunFlag||testcheckpointFlag||testioparamsFlag);

   int status = PV_SUCCESS;
   if (generateFlag) {
      if (generate(pv_argc, pv_argv,rank)!=PV_SUCCESS) {
         status = PV_FAILURE;
         if (rank==0) {
            fprintf(stderr, "%s: generate failed.\n", pv_argv[0]);
         }
      }
   }
   if (testrunFlag) {
      if (testrun(pv_argc, pv_argv,rank)!=PV_SUCCESS) {
         status = PV_FAILURE;
         if (rank==0) {
            fprintf(stderr, "%s: testrun failed.\n", pv_argv[0]);
         }
      }
   }
   if (testcheckpointFlag) {
      if (testcheckpoint(pv_argc, pv_argv,rank)!=PV_SUCCESS) {
         status = PV_FAILURE;
         if (rank==0) {
            fprintf(stderr, "%s: testcheckpoint failed.\n", pv_argv[0]);
         }
      }
   }
   if (testioparamsFlag) {
      if (testioparams(pv_argc, pv_argv,rank)!=PV_SUCCESS) {
         status = PV_FAILURE;
         if (rank==0) {
            fprintf(stderr, "%s: testioparams failed.\n", pv_argv[0]);
         }
      }
   }
   free(pv_argv); pv_argv = NULL;

   return status==PV_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
}

int generate(int argc, char * argv[], int rank) {
   // Remove -r and -c
   char ** pv_argv = (char **) calloc((size_t) (argc+1), sizeof(char *));
   assert(pv_argv);
   int pv_argc = 0;<commit_msg>GenericSystemTest needs to call MPI_Finalize<commit_after>/*
 * pv.cpp
 *
 */


#include <columns/buildandrun.hpp>
#include <io/RequireAllZeroActivityProbe.hpp>
#include <layers/Movie.cpp>

#define MAIN_USES_CUSTOMGROUPS
#define CORRECT_PVP_NX 32 // The x-dimension in the "correct.pvp" file.  Needed by generate()
#define CORRECT_PVP_NY 32 // The y-dimension in the "correct.pvp" file.  Needed by generate()
#define CORRECT_PVP_NF 8 // The number of features in the "correct.pvp" file.  Needed by generate()

int copyCorrectOutput(HyPerCol * hc, int argc, char * argv[]);
int assertAllZeroes(HyPerCol * hc, int argc, char * argv[]);

int generate(int argc, char * argv[], int rank);
int testrun(int argc, char * argv[], int rank);
int testcheckpoint(int argc, char * argv[], int rank);
int testioparams(int argc, char * argv[], int rank);

void * customgroup(const char * name, const char * groupname, HyPerCol * hc);
// customgroups is for adding objects not supported by build().

int main(int argc, char * argv[]) {
   int rank = 0;
#if PV_USE_MPI
   MPI_Init(&argc, &argv);
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif // PV_USE_MPI

   int pv_argc = 0;
   bool generateFlag = false; // Flag for whether to generate correct output for future tests; don't check the RequireAllZeroActivity probe
   bool testrunFlag = false;  // Flag for whether to run from params and then check the RequireAllZeroActivity probe
   bool testcheckpointFlag = false;  // Flag for whether to run from checkpoint and then check the RequireAllZeroActivity probe
   bool testioparamsFlag = false; // Flag for whether to run from the output pv.params and then check the RequireAllZeroActivity probe
   char ** pv_argv = (char **) calloc((size_t) (argc+1), sizeof(char *));
   if (pv_argv==NULL) {
      fprintf(stderr, "Error allocating memory in rank %d process: %s\n", rank, strerror(errno));
      abort();
   }

   // Run through the command line arguments.  If an argument is any of
   // --generate
   // --testrun
   // --testcheckpoint
   // --testioparams
   // --testall
   // set the appropriate test flags
   for (int arg=0; arg<argc;arg++) {
      const char * thisarg = argv[arg];
      if (!strcmp(thisarg, "--generate")) {
         generateFlag = true;
      }
      else if (!strcmp(thisarg, "--testrun")) {
         testrunFlag = true;
      }
      else if (!strcmp(thisarg, "--testcheckpoint")) {
         testcheckpointFlag = true;
      }
      else if (!strcmp(thisarg, "--testioparams")) {
         testioparamsFlag = true;
      }
      else if (!strcmp(thisarg, "--testall")) {
         testrunFlag = true;
         testcheckpointFlag = true;
         testioparamsFlag = true;
      }
      else {
         pv_argv[pv_argc] = argv[arg];
         pv_argc++;
         assert(pv_argc<=argc);
      }
   }
   pv_argv[pv_argc]=NULL;
   if (generateFlag && (testrunFlag||testcheckpointFlag||testioparamsFlag)) {
      if (rank==0) {
         fprintf(stderr, "%s error: --generate option conflicts with the --test* options.\n", argv[0]);
      }
      MPI_Barrier(MPI_COMM_WORLD); // Make sure no child processes take down the MPI environment before root process prints error message.
      exit(EXIT_FAILURE);
   }
   if (!(generateFlag||testrunFlag||testcheckpointFlag||testioparamsFlag)) {
      if (rank==0) {
         fprintf(stderr, "%s error: At least of \"--generate\", \"--testrun\", \"--testcheckpoint\", \"testioparams\" must be selected.\n", argv[0]);
      }
      MPI_Barrier(MPI_COMM_WORLD); // Make sure no child processes take down the MPI environment before root process prints error message.
      exit(EXIT_FAILURE);
   }
   assert(generateFlag||testrunFlag||testcheckpointFlag||testioparamsFlag);

   int status = PV_SUCCESS;
   if (generateFlag) {
      if (generate(pv_argc, pv_argv,rank)!=PV_SUCCESS) {
         status = PV_FAILURE;
         if (rank==0) {
            fprintf(stderr, "%s: generate failed.\n", pv_argv[0]);
         }
      }
   }
   if (testrunFlag) {
      if (testrun(pv_argc, pv_argv,rank)!=PV_SUCCESS) {
         status = PV_FAILURE;
         if (rank==0) {
            fprintf(stderr, "%s: testrun failed.\n", pv_argv[0]);
         }
      }
   }
   if (testcheckpointFlag) {
      if (testcheckpoint(pv_argc, pv_argv,rank)!=PV_SUCCESS) {
         status = PV_FAILURE;
         if (rank==0) {
            fprintf(stderr, "%s: testcheckpoint failed.\n", pv_argv[0]);
         }
      }
   }
   if (testioparamsFlag) {
      if (testioparams(pv_argc, pv_argv,rank)!=PV_SUCCESS) {
         status = PV_FAILURE;
         if (rank==0) {
            fprintf(stderr, "%s: testioparams failed.\n", pv_argv[0]);
         }
      }
   }
   free(pv_argv); pv_argv = NULL;

#if PV_USE_MPI
   MPI_Finalize();
#endif // PV_USE_MPI

   return status==PV_SUCCESS ? EXIT_SUCCESS : EXIT_FAILURE;
}

int generate(int argc, char * argv[], int rank) {
   // Remove -r and -c
   char ** pv_argv = (char **) calloc((size_t) (argc+1), sizeof(char *));
   assert(pv_argv);
   int pv_argc = 0;
{'fraction_non_alphanumeric': 0.13122171945701358, 'fraction_numerical': 0.004625439919557567, 'mean_word_length': 2.8927592954990216, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3841881', 'n_tokens_mistral': 3295, 'n_tokens_neox': 3284, 'n_words': 892}