Commits

cgreene  committed 96c4267

Make memory mapping of output files optional via -M flag. This flag affects the inference mode and should only be used if you have sufficient local storage for intermediate networks. Without this flag, it is best to have sufficient RAM for intermediate networks.

  • Participants
  • Parent commits c9dd362

Comments (0)

Files changed (4)

File tools/Counter/Counter.cpp

 		else
 			vecpGenes[ i ]->Open( Genome.GetGeneNames( ), false );
 		vecpYes[ i ] = new CDat( );
-		vecpYes[ i ]->Open( Genome.GetGeneNames( ), false, ( (string)sArgs.output_arg + '/' +
-			( sArgs.inputs_num ? CMeta::Basename( sArgs.inputs[ i ] ) : "global" ) + c_acDab ).c_str( ) );
 		vecpNo[ i ] = new CDat( );
-		if( !( szTemp = _tempnam( sArgs.temporary_arg, NULL ) ) ) {
-			cerr << "Could not generate temporary file name in: " << sArgs.temporary_arg << endl;
-			return 1; }
-		vecstrTmps[ i ] = szTemp;
-		free( szTemp );
-		vecpNo[ i ]->Open( Genome.GetGeneNames( ), false, vecstrTmps[ i ].c_str( ) ); }
+		if( sArgs.memmapout_flag ) {
+			vecpYes[ i ]->Open( Genome.GetGeneNames( ), false,
+					((string) sArgs.output_arg + '/' + (sArgs.inputs_num ? CMeta::Basename(
+							sArgs.inputs[ i ] ) : "global") + c_acDab).c_str( ) );
+			/*FIXME: _tempnam can result in a filename that ends up in use later via race condition */
+			if( !(szTemp = _tempnam( sArgs.temporary_arg, NULL )) ) {
+				cerr << "Could not generate temporary file name in: " << sArgs.temporary_arg << endl;
+				return 1;
+			}
+			cout << "File: " << szTemp << endl;
+			vecstrTmps[ i ] = szTemp;
+			free( szTemp );
+			vecpNo[ i ]->Open( Genome.GetGeneNames( ), false, vecstrTmps[ i ].c_str( ) );
+		} else {
+			vecpYes[ i ]->Open( Genome.GetGeneNames( ), false, NULL );
+			vecpNo[ i ]->Open( Genome.GetGeneNames( ), false, NULL );
+		}
+	}
 
 	veciGenes.resize( vecpYes[ 0 ]->GetGenes( ) );
 	vecsData.resize( vecpGenes.size( ) );
 		for( i = 0; i < iThread; ++i )
 			pthread_join( vecpthdThreads[ iTerm + i ], NULL ); }
 
-	for( i = 0; i < vecstrTmps.size( ); ++i )
-		_unlink( vecstrTmps[ i ].c_str( ) );
+	if( sArgs.memmapout_flag ) {
+		for( i = 0; i < vecstrTmps.size( ); ++i ) {
+			_unlink( vecstrTmps[ i ].c_str( ) );
+		}
+	}
 	for( i = 0; i < vecpBNs.size( ); ++i )
 		delete vecpBNs[ i ];
 	for( i = 0; i < vecpGenes.size( ); ++i ) {
+		delete vecpNo[ i ];
+		if( !sArgs.memmapout_flag ) {
+			vecpYes[ i ]->Save( ((string) sArgs.output_arg + '/' + (sArgs.inputs_num ? CMeta::Basename(
+					sArgs.inputs[ i ] ) : "global") + c_acDab).c_str( ) );
+		}
 		delete vecpYes[ i ];
-		delete vecpNo[ i ];
-		delete vecpGenes[ i ]; }
+		delete vecpGenes[ i ];
+	}
 
 	return 0; }
 

File tools/Counter/Counter.ggo

 							flag	on
 option	"memmap"		m	"Memory map input files"
 							flag	off
+option  "memmapout" M "Memory map output files (only for inference mode)"
+              flag  off
 option	"threads"		t	"Maximum number of threads to spawn"
 							int	default="-1"
 option	"verbosity"		v	"Message verbosity"

File tools/Counter/cmdline.c

 /*
-  File autogenerated by gengetopt version 2.22
+  File autogenerated by gengetopt version 2.22.4
   generated with the following command:
-  /home/chuttenh/hg/sleipnir/trunk/../extlib/gengetopt-2.22/bin/gengetopt -iCounter.ggo --default-optional -u -N -e 
+  /usr/bin/gengetopt -iCounter.ggo --default-optional -u -N -e 
 
   The developers of gengetopt consider the fixed text that goes in all
   gengetopt output files to be in the public domain:
 #include <stdlib.h>
 #include <string.h>
 
-#include "getopt.h"
+#ifndef FIX_UNUSED
+#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
+#endif
+
+#include <getopt.h>
 
 #include "cmdline.h"
 
   "  -l, --smile                   Output SMILE (X)DSL files rather than minimal \n                                  networks  (default=off)",
   "  -x, --xdsl                    Generate XDSL output rather than DSL  \n                                  (default=on)",
   "  -m, --memmap                  Memory map input files  (default=off)",
+  "  -M, --memmapout               Memory map output files (only for inference \n                                  mode)  (default=off)",
   "  -t, --threads=INT             Maximum number of threads to spawn  \n                                  (default=`-1')",
   "  -v, --verbosity=INT           Message verbosity  (default=`5')",
     0
 void clear_args (struct gengetopt_args_info *args_info);
 
 static int
-cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
+cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
                         struct cmdline_parser_params *params, const char *additional_error);
 
 static int
   args_info->smile_given = 0 ;
   args_info->xdsl_given = 0 ;
   args_info->memmap_given = 0 ;
+  args_info->memmapout_given = 0 ;
   args_info->threads_given = 0 ;
   args_info->verbosity_given = 0 ;
   args_info->Mode_group_counter = 0 ;
 static
 void clear_args (struct gengetopt_args_info *args_info)
 {
+  FIX_UNUSED (args_info);
   args_info->answers_arg = NULL;
   args_info->answers_orig = NULL;
   args_info->counts_arg = NULL;
   args_info->smile_flag = 0;
   args_info->xdsl_flag = 1;
   args_info->memmap_flag = 0;
+  args_info->memmapout_flag = 0;
   args_info->threads_arg = -1;
   args_info->threads_orig = NULL;
   args_info->verbosity_arg = 5;
   args_info->smile_help = gengetopt_args_info_help[28] ;
   args_info->xdsl_help = gengetopt_args_info_help[29] ;
   args_info->memmap_help = gengetopt_args_info_help[30] ;
-  args_info->threads_help = gengetopt_args_info_help[31] ;
-  args_info->verbosity_help = gengetopt_args_info_help[32] ;
+  args_info->memmapout_help = gengetopt_args_info_help[31] ;
+  args_info->threads_help = gengetopt_args_info_help[32] ;
+  args_info->verbosity_help = gengetopt_args_info_help[33] ;
   
 }
 
 void
 cmdline_parser_print_version (void)
 {
-  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
+  printf ("%s %s\n",
+     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
+     CMDLINE_PARSER_VERSION);
 }
 
 static void print_help_common(void) {
   printf("\n");
 
   if (strlen(gengetopt_args_info_description) > 0)
-    printf("%s\n", gengetopt_args_info_description);
+    printf("%s\n\n", gengetopt_args_info_description);
 }
 
 void
   clear_args (args_info);
   init_args_info (args_info);
 
-  args_info->inputs = NULL;
+  args_info->inputs = 0;
   args_info->inputs_num = 0;
 }
 
 
 
 static void
-write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
+write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
 {
+  FIX_UNUSED (values);
   if (arg) {
     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
   } else {
     write_into_file(outfile, "xdsl", 0, 0 );
   if (args_info->memmap_given)
     write_into_file(outfile, "memmap", 0, 0 );
+  if (args_info->memmapout_given)
+    write_into_file(outfile, "memmapout", 0, 0 );
   if (args_info->threads_given)
     write_into_file(outfile, "threads", args_info->threads_orig, 0);
   if (args_info->verbosity_given)
 char *
 gengetopt_strdup (const char *s)
 {
-  char *result = NULL;
+  char *result = 0;
   if (!s)
     return result;
 
 }
 
 int
-cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
+cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
 {
   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
 }
 
 int
-cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info,
+cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
                    struct cmdline_parser_params *params)
 {
   int result;
-  result = cmdline_parser_internal (argc, argv, args_info, params, NULL);
+  result = cmdline_parser_internal (argc, argv, args_info, params, 0);
 
   return result;
 }
 
 int
-cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
+cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
 {
   int result;
   struct cmdline_parser_params params;
   params.check_ambiguity = 0;
   params.print_errors = 1;
 
-  result = cmdline_parser_internal (argc, argv, args_info, &params, NULL);
+  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
 
   return result;
 }
 {
   int result = EXIT_SUCCESS;
 
-  if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
+  if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
     result = EXIT_FAILURE;
 
   return result;
 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
 {
   int error = 0;
+  FIX_UNUSED (additional_error);
 
   /* checks for required options */
   if (! args_info->output_given)
   
   if (args_info->Mode_group_counter == 0)
     {
-      fprintf (stderr, "%s: %d options of group Mode were given. One is required.%s\n", prog_name, args_info->Mode_group_counter, (additional_error ? additional_error : ""));
+      fprintf (stderr, "%s: %d options of group Mode were given. One is required%s.\n", prog_name, args_info->Mode_group_counter, (additional_error ? additional_error : ""));
       error = 1;
     }
   
 static
 int update_arg(void *field, char **orig_field,
                unsigned int *field_given, unsigned int *prev_given, 
-               char *value, char *possible_values[], const char *default_value,
+               char *value, const char *possible_values[],
+               const char *default_value,
                cmdline_parser_arg_type arg_type,
                int check_ambiguity, int override,
                int no_free, int multiple_option,
   const char *val = value;
   int found;
   char **string_field;
+  FIX_UNUSED (field);
 
   stop_char = 0;
   found = 0;
       return 1; /* failure */
     }
 
+  FIX_UNUSED (default_value);
     
   if (field_given && *field_given && ! override)
     return 0;
 
 
 int
-cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
+cmdline_parser_internal (
+  int argc, char **argv, struct gengetopt_args_info *args_info,
                         struct cmdline_parser_params *params, const char *additional_error)
 {
   int c;	/* Character of the parsed option.  */
         { "smile",	0, NULL, 'l' },
         { "xdsl",	0, NULL, 'x' },
         { "memmap",	0, NULL, 'm' },
+        { "memmapout",	0, NULL, 'M' },
         { "threads",	1, NULL, 't' },
         { "verbosity",	1, NULL, 'v' },
-        { NULL,	0, NULL, 0 }
+        { 0,  0, 0, 0 }
       };
 
-      c = getopt_long (argc, argv, "hVw:k:n:o:d:s:e:X:g:G:c:C:b:Z:Sp:a:rR:y:lxmt:v:", long_options, &option_index);
+      c = getopt_long (argc, argv, "hVw:k:n:o:d:s:e:X:g:G:c:C:b:Z:Sp:a:rR:y:lxmMt:v:", long_options, &option_index);
 
       if (c == -1) break;	/* Exit from `while (1)' loop.  */
 
             goto failure;
         
           break;
+        case 'M':	/* Memory map output files (only for inference mode).  */
+        
+        
+          if (update_arg((void *)&(args_info->memmapout_flag), 0, &(args_info->memmapout_given),
+              &(local_args_info.memmapout_given), optarg, 0, 0, ARG_FLAG,
+              check_ambiguity, override, 1, 0, "memmapout", 'M',
+              additional_error))
+            goto failure;
+        
+          break;
         case 't':	/* Maximum number of threads to spawn.  */
         
         
 
   if (args_info->Mode_group_counter > 1)
     {
-      fprintf (stderr, "%s: %d options of group Mode were given. One is required.%s\n", argv[0], args_info->Mode_group_counter, (additional_error ? additional_error : ""));
+      fprintf (stderr, "%s: %d options of group Mode were given. One is required%s.\n", argv[0], args_info->Mode_group_counter, (additional_error ? additional_error : ""));
       error = 1;
     }
   

File tools/Counter/cmdline.h

 /** @file cmdline.h
  *  @brief The header file for the command line option parser
- *  generated by GNU Gengetopt version 2.22
+ *  generated by GNU Gengetopt version 2.22.4
  *  http://www.gnu.org/software/gengetopt.
  *  DO NOT modify this file, since it can be overwritten
  *  @author GNU Gengetopt by Lorenzo Bettini */
 #endif /* __cplusplus */
 
 #ifndef CMDLINE_PARSER_PACKAGE
-/** @brief the program name */
+/** @brief the program name (used for printing errors) */
 #define CMDLINE_PARSER_PACKAGE "Counter"
 #endif
 
+#ifndef CMDLINE_PARSER_PACKAGE_NAME
+/** @brief the complete program name (used for help and version) */
+#define CMDLINE_PARSER_PACKAGE_NAME "Counter"
+#endif
+
 #ifndef CMDLINE_PARSER_VERSION
 /** @brief the program version */
 #define CMDLINE_PARSER_VERSION "1.0"
   const char *xdsl_help; /**< @brief Generate XDSL output rather than DSL help description.  */
   int memmap_flag;	/**< @brief Memory map input files (default=off).  */
   const char *memmap_help; /**< @brief Memory map input files help description.  */
+  int memmapout_flag;	/**< @brief Memory map output files (only for inference mode) (default=off).  */
+  const char *memmapout_help; /**< @brief Memory map output files (only for inference mode) help description.  */
   int threads_arg;	/**< @brief Maximum number of threads to spawn (default='-1').  */
   char * threads_orig;	/**< @brief Maximum number of threads to spawn original value given at command line.  */
   const char *threads_help; /**< @brief Maximum number of threads to spawn help description.  */
   unsigned int smile_given ;	/**< @brief Whether smile was given.  */
   unsigned int xdsl_given ;	/**< @brief Whether xdsl was given.  */
   unsigned int memmap_given ;	/**< @brief Whether memmap was given.  */
+  unsigned int memmapout_given ;	/**< @brief Whether memmapout was given.  */
   unsigned int threads_given ;	/**< @brief Whether threads was given.  */
   unsigned int verbosity_given ;	/**< @brief Whether verbosity was given.  */
 
  * @param args_info the structure where option information will be stored
  * @return 0 if everything went fine, NON 0 if an error took place
  */
-int cmdline_parser (int argc, char * const *argv,
+int cmdline_parser (int argc, char **argv,
   struct gengetopt_args_info *args_info);
 
 /**
  * @return 0 if everything went fine, NON 0 if an error took place
  * @deprecated use cmdline_parser_ext() instead
  */
-int cmdline_parser2 (int argc, char * const *argv,
+int cmdline_parser2 (int argc, char **argv,
   struct gengetopt_args_info *args_info,
   int override, int initialize, int check_required);
 
  * @param params additional parameters for the parser
  * @return 0 if everything went fine, NON 0 if an error took place
  */
-int cmdline_parser_ext (int argc, char * const *argv,
+int cmdline_parser_ext (int argc, char **argv,
   struct gengetopt_args_info *args_info,
   struct cmdline_parser_params *params);