arguments.cpp 5.14 KB
Newer Older
perdacherMartin's avatar
perdacherMartin committed
1 2 3 4 5


#include "arguments.h"


6
void parsing_args(int argc, char* argv[], size_t *n, double *epsilon, size_t *d, size_t *threads, size_t *blocksize, char *filename, bool *isBinary){
perdacherMartin's avatar
perdacherMartin committed
7 8 9
  char c;
  FILE *file;

Martin Perdacher's avatar
Martin Perdacher committed
10 11
  if ( argc < 6 ){
    fprintf (stderr, "There are obligatory parameters.\n");
Martin Perdacher's avatar
Martin Perdacher committed
12
    fprintf (stderr, "Usage: ./blasSelfJoinCardinality ");
Martin Perdacher's avatar
Martin Perdacher committed
13 14

    fprintf(stderr, "Obligatory parameters: \n");
Martin Perdacher's avatar
Martin Perdacher committed
15
    fprintf(stderr, "n (number of objects)\ne (epsilon)\nd (dimensionality)\ns (blocksize)");
Martin Perdacher's avatar
Martin Perdacher committed
16 17 18
    fprintf(stderr, "Optional parameters: \n t number of threads\n\n");
    fprintf(stderr, "f (filename) if there is no filename we use random generated data [0.0, 100.0)\n");
    fprintf(stderr, "b use the -b argument without options to specify that it is a binary file.\n");
Martin Perdacher's avatar
Martin Perdacher committed
19
    fprintf(stderr, "Example (with default values): ./blasSelfJoinCardinality -n 200 -e 0.2 -d 20 -s 5000 -t 64\n");
Martin Perdacher's avatar
Martin Perdacher committed
20 21
    exit(1);
  }
perdacherMartin's avatar
perdacherMartin committed
22

23
  while ( (c = getopt(argc, argv, "n:e:d:t:s:f:b") ) != -1) {
perdacherMartin's avatar
perdacherMartin committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

	if ( optarg ){
        switch(c){
            case 'n':
    		    *n = atol(optarg);
    		    break;
    		case 't':
    		    *threads = atoi(optarg);
    			break;
            case 'd':
                *d = atoi(optarg);
                break;
            case 'e':
                *epsilon = atof(optarg);
                break;
            case 'f':
                strcpy(filename, optarg);
                break;
martinp16cs's avatar
martinp16cs committed
42 43 44
            case 's':
                *blocksize = atol(optarg);
                break;
perdacherMartin's avatar
perdacherMartin committed
45
            case '?':
Martin Perdacher's avatar
Martin Perdacher committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
              if (optopt == 'c')
                fprintf (stderr, "Option -%c requires an argument.\n", optopt);
              else if (isprint (optopt)){
                  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                  exit(1);
              }
              else
                fprintf (stderr,
                         "Unknown option character `\\x%x'.\n",
                         optopt);
              exit(1);
    		default:
    			break;
        }
	}else{
        switch(c){
            case 'b':
                *isBinary = true;
                break;
            case '?':
                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                exit(1);
                break;
            default:
                break;
        }
    }
  }

  if ( *blocksize > *n || *blocksize <= 1 ){
      fprintf (stderr, "Blocksize has to be greater than 1 and smaller or equal to N\n");
Martin Perdacher's avatar
Martin Perdacher committed
77
      printf("n:%zu, blocksize: %zu\n", *n, *blocksize);fflush(stdout);
Martin Perdacher's avatar
Martin Perdacher committed
78 79 80 81 82 83 84 85 86 87 88
      exit(1);
  }
}


void parsing_args_join(int argc, char* argv[], size_t *n, size_t *m, double *epsilon, size_t *d, size_t *threads, size_t *blocksize, char *filename, char *filename2, bool *isBinary){
  char c;
  FILE *file;

  if ( argc < 6 ){
    fprintf (stderr, "There are obligatory parameters.\n");
Martin Perdacher's avatar
Martin Perdacher committed
89
    fprintf (stderr, "Usage: ./blasJoinCardinality ");
Martin Perdacher's avatar
Martin Perdacher committed
90 91 92 93

    fprintf(stderr, "Obligatory parameters: \n");
    fprintf(stderr, "n (number of objects in set A)\nm (number of objects in set B) \ne (epsilon)\nd (dimensionality)\ns (blocksize)");
    fprintf(stderr, "Optional parameters: \n t number of threads\n\n");
Martin Perdacher's avatar
Martin Perdacher committed
94 95
    fprintf(stderr, "f (filename set A) if there is no filename we use random generated data [0.0, 1.0)\n");
    fprintf(stderr, "g (filename set B) if there is no filename we use random generated data [0.0, 1.0)\n");
Martin Perdacher's avatar
Martin Perdacher committed
96
    fprintf(stderr, "b use the -b argument without options to specify that it is a binary file.\n");
Martin Perdacher's avatar
Martin Perdacher committed
97
    fprintf(stderr, "Example (with default values): ./blasJoinCardinality -n 200000 -m 200000 -e 0.2 -d 64 -s 5000 -t 64\n");
Martin Perdacher's avatar
Martin Perdacher committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    exit(1);
  }

  while ( (c = getopt(argc, argv, "n:m:e:d:t:s:f:g:b") ) != -1) {

	if ( optarg ){
        switch(c){
            case 'n':
    		    *n = atol(optarg);
    		    break;
            case 'm':
    		    *m = atol(optarg);
    		    break;
    		case 't':
    		    *threads = atoi(optarg);
    			break;
            case 'd':
                *d = atoi(optarg);
                break;
            case 'e':
                *epsilon = atof(optarg);
                break;
            case 'f':
                strcpy(filename, optarg);
                break;
            case 's':
                *blocksize = atol(optarg);
                break;
            case '?':
perdacherMartin's avatar
perdacherMartin committed
127 128 129 130
              if (optopt == 'c')
                fprintf (stderr, "Option -%c requires an argument.\n", optopt);
              else if (isprint (optopt)){
                  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
martinp16cs's avatar
martinp16cs committed
131
                  exit(1);
perdacherMartin's avatar
perdacherMartin committed
132 133 134 135 136 137 138 139 140
              }
              else
                fprintf (stderr,
                         "Unknown option character `\\x%x'.\n",
                         optopt);
              exit(1);
    		default:
    			break;
        }
141 142 143
	}else{
        switch(c){
            case 'b':
Martin Perdacher's avatar
Martin Perdacher committed
144
                *isBinary = true;
145 146 147 148 149 150 151 152 153 154 155
                break;
            case '?':
                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                exit(1);
                break;
            default:
                break;
        }
    }
  }

Martin Perdacher's avatar
Martin Perdacher committed
156
  if ( *blocksize > *n || *blocksize <= 1 ){
157
      fprintf (stderr, "Blocksize has to be greater than 1 and smaller or equal to N\n");
Martin Perdacher's avatar
Martin Perdacher committed
158
      printf("n:%zu, blocksize: %zu\n", *n, *blocksize);fflush(stdout);
159
      exit(1);
perdacherMartin's avatar
perdacherMartin committed
160 161 162
  }

}