struct options parseOptions()

in gloo/benchmark/options.cc [145:376]


struct options parseOptions(int argc, char** argv) {
  struct options result;

  static struct option long_options[] = {
      {"rank", required_argument, nullptr, 'r'},
      {"size", required_argument, nullptr, 's'},
      {"redis-host", required_argument, nullptr, 'h'},
      {"redis-port", required_argument, nullptr, 'p'},
      {"prefix", required_argument, nullptr, 'x'},
      {"shared-path", required_argument, nullptr, 0x1012},
      {"transport", required_argument, nullptr, 't'},
      {"no-verify", no_argument, nullptr, 0x1001},
      {"show-all-errors", no_argument, nullptr, 0x1015},
      {"elements", required_argument, nullptr, 0x1002},
      {"warmup-iters", required_argument, nullptr, 0x1014},
      {"iteration-count", required_argument, nullptr, 0x1003},
      {"iteration-time", required_argument, nullptr, 0x1004},
      {"sync", required_argument, nullptr, 0x1005},
      {"nanos", no_argument, nullptr, 0x1006},
      {"busy-poll", required_argument, nullptr, 0x1007},
      {"inputs", required_argument, nullptr, 0x1008},
      {"gpudirect", no_argument, nullptr, 0x1009},
      {"halfprecision", no_argument, nullptr, 0x100a},
      {"destinations", required_argument, nullptr, 0x100b},
      {"threads", required_argument, nullptr, 0x100c},
      {"ib-device", required_argument, nullptr, 0x100d},
      {"ib-index", required_argument, nullptr, 0x100e},
      {"ib-port", required_argument, nullptr, 0x100f},
      {"tcp-device", required_argument, nullptr, 0x1010},
      {"base", required_argument, nullptr, 0x1011},
      {"messages", required_argument, nullptr, 0x1013},
      {"pkey", required_argument, nullptr, 0x2001},
      {"cert", required_argument, nullptr, 0x2002},
      {"ca-file", required_argument, nullptr, 0x2003},
      {"ca-path", required_argument, nullptr, 0x2004},
      {"help", no_argument, nullptr, 0xffff},
      {nullptr, 0, nullptr, 0}};

  int opt;
  while (1) {
    int option_index = 0;
    opt = getopt_long(argc, argv, "r:s:h:p:x:t:", long_options, &option_index);
    if (opt == -1) {
      break;
    }

    switch (opt) {
      case 'r': {
        result.contextRank = atoi(optarg);
        break;
      }
      case 's': {
        result.contextSize = atoi(optarg);
        break;
      }
      case 'h': {
        result.redisHost = std::string(optarg, strlen(optarg));
        break;
      }
      case 'p': {
        result.redisPort = atoi(optarg);
        break;
      }
      case 'x': {
        result.prefix = std::string(optarg, strlen(optarg));
        break;
      }
      case 't': {
        result.transport = std::string(optarg, strlen(optarg));
        break;
      }
      case 0x1001: // --no-verify
      {
        result.verify = false;
        break;
      }
      case 0x1015: // --show-all-errors
      {
        result.showAllErrors = true;
        break;
      }
      case 0x1002: // --elements
      {
        result.elements = atoi(optarg);
        break;
      }
      case 0x1014: // --warmup-iters
      {
        result.warmupIterationCount = atoi(optarg);
        break;
      }
      case 0x1003: // --iteration-count
      {
        result.iterationCount = atoi(optarg);
        break;
      }
      case 0x1004: // --iteration-time
      {
        result.minIterationTimeNanos = argToNanos(argv, optarg);
        break;
      }
      case 0x1005: // --sync
      {
        result.sync =
          atoi(optarg) == 1 ||
          tolower(optarg[0])== 't' ||
          tolower(optarg[0])== 'y';
        break;
      }
      case 0x1006: // --nanos
      {
        result.showNanos = true;
        break;
      }
      case 0x1007: // --busy-poll
      {
        result.busyPoll =
          atoi(optarg) == 1 ||
          tolower(optarg[0])== 't' ||
          tolower(optarg[0])== 'y';
        break;
      }
      case 0x1008: // --inputs
      {
        result.inputs = atoi(optarg);
        break;
      }
      case 0x1009: // --gpudirect
      {
        result.gpuDirect = true;
        break;
      }
      case 0x100a: // --halfprecision
      {
        result.halfPrecision = true;
        break;
      }
      case 0x100b: // --destinations
      {
        result.destinations = atoi(optarg);
        break;
      }
      case 0x100c: // --threads
      {
        result.threads = atoi(optarg);
        break;
      }
      case 0x100d: // --ib-device
      {
        result.ibverbsDevice = split(optarg, ',');
        break;
      }
      case 0x100e: // --ib-index
      {
        result.ibverbsIndex = atoi(optarg);
        break;
      }
      case 0x100f: // --ib-port
      {
        result.ibverbsPort = atoi(optarg);
        break;
      }
      case 0x1010: // --tcp-device
      {
        result.tcpDevice = split(optarg, ',');
        break;
      }
      case 0x1011: // --base
      {
        result.base = atoi(optarg);
        break;
      }
      case 0x1012: // --shared-path
      {
        result.sharedPath = std::string(optarg, strlen(optarg));
        break;
      }
      case 0x1013: // --messages
      {
        result.messages = atoi(optarg);
        break;
      }
      case 0x2001: // --pkey
      {
        result.pkey = std::string(optarg, strlen(optarg));
        break;
      }
      case 0x2002: // --cert
      {
        result.cert = std::string(optarg, strlen(optarg));
        break;
      }
      case 0x2003: // --ca-file
      {
        result.caFile = std::string(optarg, strlen(optarg));
        break;
      }
      case 0x2004: // --ca-path
      {
        result.caPath = std::string(optarg, strlen(optarg));
        break;
      }
      case 0xffff: // --help
      {
        usage(EXIT_SUCCESS, argv[0]);
        break;
      }
      default: {
        usage(EXIT_FAILURE, argv[0]);
        break;
      }
    }
  }

#if GLOO_USE_MPI
  // Use MPI if started through mpirun
  result.mpi = (getenv("OMPI_UNIVERSE_SIZE") != nullptr);
#endif

  if (result.busyPoll && !result.sync) {
    fprintf(stderr, "%s: busy poll can only be used with sync mode\n", argv[0]);
    usage(EXIT_FAILURE, argv[0]);
  }

  if (optind != (argc - 1)) {
    fprintf(stderr, "%s: missing benchmark specifier\n", argv[0]);
    usage(EXIT_FAILURE, argv[0]);
  }

  result.benchmark = argv[optind];
  return result;
}