arguments.cpp 2.44 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 12 13 14 15 16 17 18 19 20 21
  if ( argc < 6 ){
    fprintf (stderr, "There are obligatory parameters.\n");
    fprintf (stderr, "Usage: ./blasJoin ");

    fprintf(stderr, "Obligatory parameters: \n");
    fprintf(stderr, "n (number of objects in thousands (*1000))\ne (epsilon)\nd (dimensionality)\ns (blocksize)");
    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");
    fprintf(stderr, "Example (with default values): ./blasJoin -n 200 -e 0.2 -d 20 -s 5000 -t 64\n");
    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 46 47 48 49
            case '?':
              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
50
                  exit(1);
perdacherMartin's avatar
perdacherMartin committed
51 52 53 54 55 56 57 58 59
              }
              else
                fprintf (stderr,
                         "Unknown option character `\\x%x'.\n",
                         optopt);
              exit(1);
    		default:
    			break;
        }
60 61 62
	}else{
        switch(c){
            case 'b':
Martin Perdacher's avatar
Martin Perdacher committed
63
                *isBinary = true;
64 65 66 67 68 69 70 71 72 73 74
                break;
            case '?':
                fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                exit(1);
                break;
            default:
                break;
        }
    }
  }

Martin Perdacher's avatar
Martin Perdacher committed
75
  if ( *blocksize > *n || *blocksize <= 1 ){
76
      fprintf (stderr, "Blocksize has to be greater than 1 and smaller or equal to N\n");
Martin Perdacher's avatar
update  
Martin Perdacher committed
77
      printf("n:%d, blocksize: %d\n", *n, *blocksize);fflush(stdout);
78
      exit(1);
perdacherMartin's avatar
perdacherMartin committed
79 80 81
  }

}