예제 #1
0
int chpl_launch_handle_arg(int argc, char* argv[], int argNum,
                           int32_t lineno, c_string filename) {
  int numArgs = 0;
  if (!strcmp(argv[argNum], CHPL_WALLTIME_FLAG)) {
    walltime = argv[argNum+1];
    return 2;
  } else if (!strncmp(argv[argNum], CHPL_WALLTIME_FLAG"=", strlen(CHPL_WALLTIME_FLAG))) {
    walltime = &(argv[argNum][strlen(CHPL_WALLTIME_FLAG)+1]);
    return 1;
  }
  if (!strcmp(argv[argNum], CHPL_QUEUE_FLAG)) {
    queue = argv[argNum+1];
    return 2;
  } else if (!strncmp(argv[argNum], CHPL_QUEUE_FLAG"=", strlen(CHPL_QUEUE_FLAG))) {
    queue = &(argv[argNum][strlen(CHPL_QUEUE_FLAG)+1]);
    return 1;
  }
  if (!strcmp(argv[argNum], CHPL_GENERATE_QSUB_SCRIPT)) {
    generate_qsub_script = 1;
    return 1;
  }
  if (!strcmp(argv[argNum], CHPL_CC_ARG)) {
    _ccArg = argv[argNum+1];
    numArgs = 2;
  } else if (!strncmp(argv[argNum], CHPL_CC_ARG"=", strlen(CHPL_CC_ARG))) {
    _ccArg = &(argv[argNum][strlen(CHPL_CC_ARG)+1]);
    numArgs = 1;
  }
  if (numArgs > 0) {
    if (strcmp(_ccArg, "none") &&
        strcmp(_ccArg, "numa_node") &&
        strcmp(_ccArg, "cpu")) {
      char msg[256];
      snprintf(msg, 256, "'%s' is not a valid cpu assignment", _ccArg);
      chpl_error(msg, 0, 0);
    }
    return numArgs;
  }
  return 0;
}
예제 #2
0
static void chpl_launch_sanity_checks(const char* argv0) {
  // Do sanity checks just before launching.
  struct stat statBuf;

  // Make sure the _real binary exists
  // (this should be called after someone has called
  // chpl_compute_real_binary_name() )
  if (stat(chpl_get_real_binary_name(), &statBuf) != 0) {
    char errorMsg[256];
    int wanted_to_write = snprintf(errorMsg, sizeof(errorMsg),
                                   "unable to locate file: %s",
                                   chpl_get_real_binary_name());
    if (wanted_to_write < 0) {
      const char fallbackMsg[] =
        "character encoding error in name of executable to be launched";
      strcpy(errorMsg, fallbackMsg);
    } else if ((size_t)wanted_to_write >= sizeof(errorMsg)) {
      strcpy(&errorMsg[sizeof(errorMsg) - 4], "...");
    }
    chpl_error(errorMsg, 0, 0);
  }
}
예제 #3
0
void chpl_mem_layerInit(void) {
  void* start;
  size_t size;

  chpl_comm_desired_shared_heap(&start, &size);

  //
  // TODO (EJR 12/17/15): add support for shared heaps. I think we basically
  // need to create a custom chunk allocator.
  //
  // HPX-5 did this so I think we can too:
  //     http://jemalloc-discuss.canonware.narkive.com/FzSQ4Qv4/need-help-in-porting-jemalloc
  //
  //     http://www.canonware.com/pipermail/jemalloc-discuss/2015-October/001179.html
  //
  //  TODO (EJR 12/17/15): when we support shared heaps, I need to remember to
  //  update the third-party README
  //
  if (start || size)
    chpl_error("set CHPL_MEM to a more appropriate mem type", 0, 0);

  //
  // Do a first allocation, to allow jemalloc to set up:
  //
  //   """
  //   Once, when the first call is made to one of the memory allocation
  //   routines, the allocator initializes its internals based in part on various
  //   options that can be specified at compile- or run-time.
  //   """
  //
  {
    void* p;

    if ((p = je_malloc(1)) == NULL)
      chpl_internal_error("cannot init heap: je_malloc() failed");
    je_free(p);
  }

}
예제 #4
0
/* Error.chpl:55 */
static void ioerror(syserr error, chpl_string msg, chpl_string path, int64_t _ln, c_string _fn) {
  int32_t call_tmp;
  chpl_bool call_tmp2;
  int32_t strerror_err;
  c_string call_tmp3;
  _ref_int32_t _ref_tmp_ = NULL;
  c_string call_tmp4;
  int64_t call_tmp5;
  c_string call_tmp6;
  c_string_copy call_tmp7;
  c_string call_tmp8;
  c_string call_tmp9;
  c_string_copy call_tmp10;
  c_string call_tmp11;
  c_string_copy call_tmp12;
  c_string call_tmp13;
  c_string_copy call_tmp14;
  call_tmp = qio_err_iserr(error);
  call_tmp2 = (call_tmp != INT32(0));
  if (call_tmp2) {
    strerror_err = INT32(0);
    _ref_tmp_ = &strerror_err;
    call_tmp3 = sys_strerror_syserr_str(error, _ref_tmp_);
    c_string_from_string(&call_tmp4, &path, _ln, _fn);
    call_tmp5 = string_length(call_tmp4);
    call_tmp6 = quote_string(path, call_tmp5, _ln, _fn);
    call_tmp7 = string_concat(call_tmp3, " ", _ln, _fn);
    c_string_from_string(&call_tmp8, &msg, _ln, _fn);
    call_tmp9 = ((c_string)(call_tmp7));
    call_tmp10 = string_concat(call_tmp9, call_tmp8, _ln, _fn);
    call_tmp11 = ((c_string)(call_tmp10));
    call_tmp12 = string_concat(call_tmp11, " with path ", _ln, _fn);
    call_tmp13 = ((c_string)(call_tmp12));
    call_tmp14 = string_concat(call_tmp13, call_tmp6, _ln, _fn);
    chpl_error(call_tmp14, _ln, _fn);
  }
  return;
}
예제 #5
0
int handleNonstandardArg(int* argc, char* argv[], int argNum, 
                         int32_t lineno, int32_t filename) {
  int numHandled = chpl_launch_handle_arg(*argc, argv, argNum, 
                                          lineno, filename);
  if (numHandled == 0) {
    if (mainHasArgs) {
      chpl_gen_main_arg.argv[chpl_gen_main_arg.argc] = argv[argNum];
      chpl_gen_main_arg.argc++;
    } else {
      char* message;
      message = chpl_glom_strings(3,"Unexpected flag:  \"",argv[argNum],"\"");
      chpl_error(message, lineno, filename);
    }
    return 0;
  } else {
    int i;
    for (i=argNum+numHandled; i<*argc; i++) {
      argv[i-numHandled] = argv[i];
    }
    *argc -= numHandled;
    return -1;  // back the cursor up in order to re-parse this arg
  }
}
// Check what version of slurm is on the system
static sbatchVersion determineSlurmVersion(void) {
  const int buflen = 256;
  char version[buflen];
  char *argv[3];
  argv[0] = (char *) "sbatch";
  argv[1] = (char *) "--version";
  argv[2] = NULL;

  memset(version, 0, buflen);
  if (chpl_run_utility1K("sbatch", argv, version, buflen) <= 0) {
    chpl_error("Error trying to determine slurm version", 0, 0);
  }

  if (strstr(version, "SBATCHPro")) {
    return slurmpro;
  } else if (strstr(version, "wrapper sbatch SBATCH UMA 1.0")) {
    return uma;
  } else if (strstr(version, "slurm")) {
    return slurm;
  } else {
    return unknown;
  }
}
예제 #7
0
static qsubVersion determineQsubVersion(void) {
  const int buflen = 256;
  char version[buflen];
  char *argv[3];
  argv[0] = (char *) "qsub";
  argv[1] = (char *) "--version";
  argv[2] = NULL;

  memset(version, 0, buflen);
  if (chpl_run_utility1K("qsub", argv, version, buflen) <= 0) {
    chpl_error("Error trying to determine qsub version", 0, 0);
  }

  if (strstr(version, "NCCS")) {
    return nccs;
  } else if (strstr(version, "PBSPro")) {
    return pbspro;
  } else if (strstr(version, "version:") || strstr(version, "Version:")) {
    return torque;
  } else {
    return unknown;
  }
}
예제 #8
0
void* _chpl_gc_malloc(size_t number, size_t size, const char* description,
                      int32_t lineno, chpl_string filename) {
  char* current = NULL;
  size_t chunk = number * size;
  if (_from_space->current + chunk > _from_space->tail) {
    // Garbage collect, then allocate
    _chpl_gc_copy_collect();
    if (_from_space->current + chunk > _from_space->tail) {
      // out of memory.  Should probably realloc the heap.
      // For now, throw an error
      char message[1024];
      sprintf(message, "Out of memory allocating \"%s\"", description);
      chpl_error(message, lineno, filename);
    } else {
      current = _from_space->current;
      _from_space->current += chunk;
    }
  } else {
    current = _from_space->current;
    _from_space->current += chunk;
  }
  return (void*)current;
}
예제 #9
0
파일: chplcast.c 프로젝트: 8l/chapel
c_string_copy
integral_to_c_string_copy(int64_t x, uint32_t size, chpl_bool isSigned)
{
  char buffer[256];
  const char* format = "";
  enum {UNSIGNED = 0<<16, SIGNED = 1<<16 };
  switch (SIGNED * isSigned + size)
  {
   default:
    chpl_error("Unexpected case in integral_to_c_string_copy", -1, "");
    break;

   case UNSIGNED + 1: format = "%" PRIu8;  break;
   case UNSIGNED + 2: format = "%" PRIu16; break;
   case UNSIGNED + 4: format = "%" PRIu32; break;
   case UNSIGNED + 8: format = "%" PRIu64; break;
   case   SIGNED + 1: format = "%" PRId8;  break;
   case   SIGNED + 2: format = "%" PRId16; break;
   case   SIGNED + 4: format = "%" PRId32; break;
   case   SIGNED + 8: format = "%" PRId64; break;
  }
  sprintf(buffer, format, x);
  return string_copy(buffer, 0, NULL);
}
예제 #10
0
static void halt3(string* const _e0_args, int64_t _e1_args, int64_t _ln, int32_t _fn) {
#line 693 "ChapelIO.chpl"
  string local__str_literal_302;
#line 693 "ChapelIO.chpl"
  string local__str_literal_1508;
#line 693 "ChapelIO.chpl"
  string tmpstring;
#line 693 "ChapelIO.chpl"
  string call_tmp;
#line 693 "ChapelIO.chpl"
  string _autoCopy_tmp_;
#line 693 "ChapelIO.chpl"
  _ref_string ret_to_arg_ref_tmp_ = NULL;
#line 693 "ChapelIO.chpl"
  string call_tmp2;
#line 693 "ChapelIO.chpl"
  _ref_string ret_to_arg_ref_tmp_2 = NULL;
#line 693 "ChapelIO.chpl"
  int32_t coerce_tmp;
#line 693 "ChapelIO.chpl"
  chpl_bool call_tmp3;
#line 693 "ChapelIO.chpl"
  c_ptr_uint8_t coerce_tmp2 = NULL;
#line 693 "ChapelIO.chpl"
  c_string call_tmp4;
#line 693 "ChapelIO.chpl"
  _ref_string _ref_tmp_ = NULL;
#line 693 "ChapelIO.chpl"
  _ref_string _ref_tmp_2 = NULL;
#line 704 "ChapelIO.chpl"
  local__str_literal_302 = _str_literal_302;
#line 703 "ChapelIO.chpl"
  local__str_literal_1508 = _str_literal_1508;
#line 703 "ChapelIO.chpl"
  ret_to_arg_ref_tmp_ = &_autoCopy_tmp_;
#line 703 "ChapelIO.chpl"
  stringify_chpl(_e0_args, _e1_args, ret_to_arg_ref_tmp_, _ln, _fn);
#line 703 "ChapelIO.chpl"
  call_tmp = _autoCopy_tmp_;
#line 703 "ChapelIO.chpl"
  ret_to_arg_ref_tmp_2 = &call_tmp2;
#line 703 "ChapelIO.chpl"
  chpl___PLUS_(&local__str_literal_1508, &_autoCopy_tmp_, ret_to_arg_ref_tmp_2, _ln, _fn);
#line 703 "ChapelIO.chpl"
  tmpstring = call_tmp2;
#line 704 "ChapelIO.chpl"
  coerce_tmp = (&tmpstring)->locale_id;
#line 704 "ChapelIO.chpl"
  call_tmp3 = (coerce_tmp != chpl_nodeID);
#line 704 "ChapelIO.chpl"
  if (call_tmp3) /* ZLINE: 704 /home/agobin/Documents/chapel-1.13.0/modules/internal/ChapelIO.chpl */
#line 704 "ChapelIO.chpl"
  {
#line 704 "ChapelIO.chpl"
    halt(&local__str_literal_302, _ln, _fn);
#line 704 "ChapelIO.chpl"
  }
#line 704 "ChapelIO.chpl"
  coerce_tmp2 = (&tmpstring)->buff;
#line 704 "ChapelIO.chpl"
  call_tmp4 = ((c_string)(coerce_tmp2));
#line 704 "ChapelIO.chpl"
  chpl_error(call_tmp4, _ln, _fn);
#line 703 "ChapelIO.chpl"
  _ref_tmp_ = &call_tmp;
#line 703 "ChapelIO.chpl"
  chpl___TILDE_string(_ref_tmp_, _ln, _fn);
#line 703 "ChapelIO.chpl"
  _ref_tmp_2 = &tmpstring;
#line 703 "ChapelIO.chpl"
  chpl___TILDE_string(_ref_tmp_2, _ln, _fn);
#line 702 "ChapelIO.chpl"
  return;
#line 702 "ChapelIO.chpl"
}
예제 #11
0
파일: arg.c 프로젝트: CoryMcCartan/chapel
void parseArgs(chpl_bool isLauncher, chpl_parseArgsMode_t mode,
               int* argc, char* argv[]) {
  int i;
  int printHelp = 0;
  int printAbout = 0;
  int origargc = *argc;
  int stop_parsing = 0;

  //
  // Handle the pre-parse for '-E' arguments separately.
  //
  if (mode == parse_dash_E) {
    assert(!isLauncher);
    parseDashEArgs(argc, argv);
    return;
  }

  for (i = 1; i < *argc; i++) {
    const char* filename = "<command-line arg>";
    int lineno = i + (origargc - *argc);
    int argLength = 0;
    const char* currentArg = argv[i];
    argLength = strlen(currentArg);

    if (mainHasArgs && (stop_parsing || argLength < 2)) {
      /* update the argv structure passed to a Chapel program, but don't parse
       * the arguments
       */
      chpl_gen_main_arg.argv[chpl_gen_main_arg.argc] = argv[i];
      chpl_gen_main_arg.argc++;
      continue;
    }

    /* if the Chapel main takes arguments, then "--" is a magic argument that
     * will prevent parsing of any additional arguments
     */
    if (mainHasArgs && strcmp(currentArg, "--") == 0) {
      stop_parsing = 1;
      continue;
    }

    if (argLength < 2) {
      const char* message = chpl_glom_strings(3, "\"", currentArg,
                                              "\" is not a valid argument");
      chpl_error(message, lineno, filename);
    }

    switch (currentArg[0]) {
    case '-':
      switch (currentArg[1]) {
      case '-':
        {
          const char* flag = currentArg + 2;

          if (strcmp(flag, "gdb") == 0) {
            gdbFlag = i;
            break;
          }

          if (strcmp(flag, "help") == 0) {
            printHelp = 1;
            chpl_gen_main_arg.argv[chpl_gen_main_arg.argc] = "--help";
            chpl_gen_main_arg.argc++;
            break;
          }
          if (strcmp(flag, "about") == 0) {
            printAbout = 1;
            break;
          }
          if (strcmp(flag, "verbose") == 0) {
            verbosity=2;
            break;
          }
          if (strcmp(flag, "blockreport") == 0) {
            blockreport = 1;
            break;
          }
          if (strcmp(flag, "taskreport") == 0) {
            taskreport = 1;
            break;
          }
          if (strcmp(flag, "quiet") == 0) {
            verbosity = 0;
            break;
          }
          if (argLength < 3) {
            char* message = chpl_glom_strings(3, "\"", currentArg,
                                              "\" is not a valid argument");
            chpl_error(message, lineno, filename);
          }
          i += handlePossibleConfigVar(argc, argv, i, lineno, filename);
          break;
        }

      case 'a':
        if (currentArg[2] == '\0') {
          printAbout = 1;
        } else {
          i += handleNonstandardArg(argc, argv, i, lineno, filename);
        }
        break;

      case 'b':
        if (currentArg[2] == '\0') {
          blockreport = 1;
        } else {
          i += handleNonstandardArg(argc, argv, i, lineno, filename);
        }
        break;

      case 'E':
        if (isLauncher) {
          i += handleNonstandardArg(argc, argv, i, lineno, filename);
        } else {
          //
          // We parse -E only in parse_dash_E mode, which is handled above.
          //
          if (currentArg[2] == '\0') {
            i++;
          }
        }
        break;

      case 'f':
        if (currentArg[2] == '\0') {
          i++;
          if (i >= *argc) {
            chpl_error("-f flag is missing <filename> argument",
                       lineno, filename);
          }
          currentArg = argv[i];
          parseConfigFile(currentArg, lineno, filename);
        } else {
          parseConfigFile(currentArg + 2, lineno, filename);
        }
        break;

      case 'h':
        if (currentArg[2] == '\0') {
          printHelp = 1;
          chpl_gen_main_arg.argv[chpl_gen_main_arg.argc] = "-h";
          chpl_gen_main_arg.argc++;
        } else {
          i += handleNonstandardArg(argc, argv, i, lineno, filename);
        }
        break;

      case 'n':
        if (currentArg[2] == 'l') {
          const char* numPtr;
          if (currentArg[3] == '\0') {
            i++;
            if (i >= *argc) {
              chpl_error("-nl flag is missing <numLocales> argument",
                         lineno, filename);
            }
            currentArg = argv[i];
            numPtr = currentArg;
          } else {
            numPtr = &(currentArg[3]);
          }
          initSetValue("numLocales", numPtr, "Built-in", lineno, filename);
          break;
        }
        i += handleNonstandardArg(argc, argv, i, lineno, filename);
        break;

      case 'q':
        if (currentArg[2] == '\0') {
          verbosity = 0;
        } else {
          i += handleNonstandardArg(argc, argv, i, lineno, filename);
        }
        break;

      case 's':
        {
          if (argLength < 3) {
            char* message = chpl_glom_strings(3, "\"", currentArg,
                                              "\" is not a valid argument");
            chpl_error(message, lineno, filename);
          }
          i += handlePossibleConfigVar(argc, argv, i, lineno, filename);
          break;
        }

      case 't':
        if (currentArg[2] == '\0') {
          taskreport = 1;
        } else {
          i += handleNonstandardArg(argc, argv, i, lineno, filename);
        }
        break;

      case 'v':
        if (currentArg[2] == '\0') {
          verbosity = 2;
        } else {
          i += handleNonstandardArg(argc, argv, i, lineno, filename);
        }
        break;

      default:
        i += handleNonstandardArg(argc, argv, i, lineno, filename);
        break;
      }
      break;

    default:
      i += handleNonstandardArg(argc, argv, i, lineno, filename);
      break;
    }
  }

  if (printAbout) {
    chpl_program_about();
    chpl_exit_any(0);
  }

  if (printHelp) {
    if (!mainHasArgs) {
      printHelpTable();
      printConfigVarTable();
      chpl_exit_any(0);
    }
  }
}
예제 #12
0
파일: arg.c 프로젝트: CoryMcCartan/chapel
int chpl_specify_locales_error(void) {
  chpl_error("Specify number of locales via -nl <#> or --numLocales=<#>", 0, 0);
  return 0;
}
예제 #13
0
int getCoresPerLocale() {
  int numCores = -1;
  char* numCoresString = getenv("CHPL_LAUNCHER_CORES_PER_LOCALE");

  if (numCoresString) {
    numCores = atoi(numCoresString);
    if (numCores <= 0)
      chpl_warning("CHPL_LAUNCHER_CORES_PER_LOCALE set to invalid value.", 0, 0);
  }

  if (numCores > 0)
    return numCores;

  if (strstr(CNA, "numcores") != NULL) {
    const int buflen = 1024;
    char buf[buflen];
    char* argv[3];

    argv[0] = (char *) "cnselect";
    argv[1] = (char *) "-Lnumcores";
    argv[2] = NULL;
  
    memset(buf, 0, buflen);
    if (chpl_run_utility1K("cnselect", argv, buf, buflen) <= 0)
      chpl_error("Error trying to determine number of cores per node", 0, 0);

    if (sscanf(buf, "%d", &numCores) != 1)
      chpl_error("unable to determine number of cores per locale; "
                 "please set CHPL_LAUNCHER_CORES_PER_LOCALE", 0, 0);

    return numCores;
  }

  if (strstr(CNA, "coremask") != NULL) {
    const int buflen = 1024;
    char buf[buflen];
    char* argv[3];
 
    argv[0] = (char *) "cnselect";
    argv[1] = (char *) "-Lcoremask";
    argv[2] = NULL;
  
    memset(buf, 0, buflen);
    if (chpl_run_utility1K("cnselect", argv, buf, buflen) <= 0)
      chpl_error("Error trying to determine number coremask on node", 0, 0);

    {
      int coreMask;
      int bitMask = 0x1;

      if (sscanf(buf, "%d", &coreMask) != 1)
        chpl_error("unable to determine coremask for locale; "
                   "please set CHPL_LAUNCHER_CORES_PER_LOCALE", 0, 0);

      coreMask >>= 1;
      numCores = 1;
      while (coreMask & bitMask) {
        coreMask >>= 1;
        numCores += 1;
      }
    }

    return numCores;
  }

  // neither numcores nor coremask is available in this version
  chpl_error("Error trying to determine number of cores per node", 0, 0);

  return 0;
}
예제 #14
0
파일: config.c 프로젝트: chapel-lang/chapel
/* This function parses a config var of type string, and sets its value in 
   the hash table.  
*/
static int aParsedString(FILE* argFile, char* setConfigBuffer, 
                         int32_t lineno, int32_t filename) {
  char* equalsSign = strchr(setConfigBuffer, '=');
  int stringLength = strlen(setConfigBuffer);
  char firstChar;
  char* value;
  char lastChar;
  const char* moduleName;
  char* varName;

  if (!equalsSign || !(equalsSign + 1)) {
    return 0;
  }

  firstChar = equalsSign[1];
  if ((firstChar != '"') && (firstChar != '\'')) {
    return 0;
  }

  value = equalsSign + 2;
  *equalsSign = '\0';
  lastChar = setConfigBuffer[stringLength - 1];

  parseModVarName(setConfigBuffer, &moduleName, &varName);
  
  if ((firstChar != lastChar) || (strlen(value) == 0)) {
    int nextChar = fgetc(argFile);
    do {
      switch (nextChar) {
      case EOF:
        {
          char* message;
          setConfigBuffer[stringLength] = '\0';
          message = chpl_glom_strings(2, "Found end of file while reading string: ",
                                      equalsSign + 1);
          chpl_error(message, lineno, filename);
          break;
        }
      case '\n':
        {
          char* message;
          setConfigBuffer[stringLength] = '\0';
          message = chpl_glom_strings(2, "Found newline while reading string: ", 
                                      equalsSign + 1);
          chpl_error(message, lineno, filename);
          break;
        }
      default:
        {
          if (stringLength >= _default_string_length - 1) {
            char dsl[1024];
            char* message;
            sprintf(dsl, "%d", _default_string_length);
            message = chpl_glom_strings(2, "String exceeds the maximum string length of ",
                                        dsl);
            chpl_error(message, lineno, filename);
          }
          setConfigBuffer[stringLength] = nextChar;
          stringLength++;
          nextChar = fgetc(argFile);
        }
      }
    } while (nextChar != firstChar);
  } else {
    stringLength--;
  }
  setConfigBuffer[stringLength] = '\0';
  initSetValue(varName, value, moduleName, lineno, filename);
  return 1;
}
예제 #15
0
static void
printMemAllocs(chpl_mem_descInt_t description, int64_t threshold,
               int32_t lineno, int32_t filename) {
  const int numberWidth   = 9;
  const int precision     = sizeof(uintptr_t) * 2;
  const int addressWidth  = precision+4;
  const int descWidth     = 33;
  int filenameWidth       = strlen("Allocated Memory (Bytes)");
  int totalWidth;
  int filenameLength;

  memTableEntry* memEntry;
  c_string memEntryFilename;
  int n, i;
  char* loc;
  memTableEntry** table;

  if (!chpl_memTrack) {
    chpl_warning("invalid call to printMemAllocs(); rerun with --memTrack",
                 lineno, filename);
    return;
  }

  n = 0;
  filenameWidth = strlen("Allocated Memory (Bytes)");
  for (i = 0; i < hashSize; i++) {
    for (memEntry = memTable[i]; memEntry != NULL; memEntry = memEntry->nextInBucket) {
      size_t chunk = memEntry->number * memEntry->size;
      if (chunk < threshold)
        continue;
      if (description != -1 && memEntry->description != description)
        continue;
      n += 1;
      if (memEntry->filename) {
        memEntryFilename = chpl_lookupFilename(memEntry->filename);
        filenameLength = strlen(memEntryFilename);
        if (filenameLength > filenameWidth)
          filenameWidth = filenameLength;
      }
    }
  }

  totalWidth = filenameWidth+numberWidth*4+descWidth+20;
  for (i = 0; i < totalWidth; i++)
    fprintf(memLogFile, "=");
  fprintf(memLogFile, "\n");
  fprintf(memLogFile, "%-*s%-*s%-*s%-*s%-*s%-*s\n",
         filenameWidth+numberWidth, "Allocated Memory (Bytes)",
         numberWidth, "Number",
         numberWidth, "Size",
         numberWidth, "Total",
         descWidth, "Description",
         20, "Address");
  for (i = 0; i < totalWidth; i++)
    fprintf(memLogFile, "=");
  fprintf(memLogFile, "\n");

  table = (memTableEntry**)sys_malloc(n*sizeof(memTableEntry*));
  if (!table)
    chpl_error("out of memory printing memory table", lineno, filename);

  n = 0;
  for (i = 0; i < hashSize; i++) {
    for (memEntry = memTable[i]; memEntry != NULL; memEntry = memEntry->nextInBucket) {
      size_t chunk = memEntry->number * memEntry->size;
      if (chunk < threshold)
        continue;
      if (description != -1 && memEntry->description != description)
        continue;
      table[n++] = memEntry;
    }
  }
  qsort(table, n, sizeof(memTableEntry*), descCmp);

  loc = (char*)sys_malloc((filenameWidth+numberWidth+1)*sizeof(char));

  for (i = 0; i < n; i++) {
    memEntry = table[i];
    if (memEntry->filename) {
      memEntryFilename = chpl_lookupFilename(memEntry->filename);
      sprintf(loc, "%s:%" PRId32, memEntryFilename, memEntry->lineno);
    } else {
      sprintf(loc, "--");
    }
    fprintf(memLogFile, "%-*s%-*zu%-*zu%-*zu%-*s%#-*.*" PRIxPTR "\n",
           filenameWidth+numberWidth, loc,
           numberWidth, memEntry->number,
           numberWidth, memEntry->size,
           numberWidth, memEntry->size*memEntry->number,
           descWidth, chpl_mem_descString(memEntry->description),
           addressWidth, precision, (uintptr_t)memEntry->memAlloc);
  }
  for (i = 0; i < totalWidth; i++)
    fprintf(memLogFile, "=");
  fprintf(memLogFile, "\n");
  putchar('\n');

  sys_free(table);
  sys_free(loc);
}
예제 #16
0
uint64_t chpl_memoryUsed(int32_t lineno, c_string filename) {
  if (!chpl_memTrack)
    chpl_error("invalid call to memoryUsed(); rerun with --memTrack",
               lineno, filename);
  return (uint64_t)totalMem;
}
예제 #17
0
//
// If generate_qsub_script, return the filename of the qsub script that
//   was written with the qsub options
// else return the qsub options for the command line as a string
//
static char* genQsubOptions(char* genFilename, char* projectString, qsubVersion qsub, 
                            int32_t numLocales, int32_t numCoresPerLocale) {
  const size_t maxOptLength = 256;
  char* optionString = NULL;
  int length = 0;
  FILE *qsubScript = NULL;
  char *qsubFilename = expectFilename;

  if (!queue) {
    queue = getenv("CHPL_LAUNCHER_QUEUE");
  }
  if (!walltime) {
    walltime = getenv("CHPL_LAUNCHER_WALLTIME");
  }

  if (generate_qsub_script) {
    pid_t mypid = debug ? 0 : getpid();
    sprintf(qsubFilename, "qsub.%s-%d", genFilename, (int) mypid);
    qsubScript = fopen(qsubFilename, "w");
    fprintf(qsubScript, "#PBS -j oe\n");
    fprintf(qsubScript, "#PBS -zV\n");
    fprintf(qsubScript, "#PBS -N Chpl-%.10s\n", genFilename);
  } else {
    optionString = chpl_mem_allocMany(maxOptLength, sizeof(char),
                                      CHPL_RT_MD_COMMAND_BUFFER, -1, "");
    length += snprintf(optionString + length, maxOptLength - length,
                       "-z -V -I -N Chpl-%.10s", genFilename);
  }

  if (projectString && strlen(projectString) != 0) {
    if (generate_qsub_script) {
      fprintf(qsubScript, "#PBS -A %s\n", projectString);
    } else {
      length += snprintf(optionString + length, maxOptLength - length,
                         " -A %s", projectString);
    }
  }
  if (queue) {
    if (generate_qsub_script) {
      fprintf(qsubScript, "#PBS -q %s\n", queue);
    } else {
      length += snprintf(optionString + length, maxOptLength - length,
                         " -q %s", queue);
    }
  }
  if (walltime) {
    if (generate_qsub_script) {
      fprintf(qsubScript, "#PBS -l walltime=%s\n", walltime);
    } else {
      length += snprintf(optionString + length, maxOptLength - length,
                         " -l walltime=%s", walltime);
    }
  }
  switch (qsub) {
  case pbspro:
  case unknown:
    if (generate_qsub_script) {
      fprintf(qsubScript, "#PBS -l mppwidth=%d\n", numLocales);
      fprintf(qsubScript, "#PBS -l mppnppn=%d\n", procsPerNode);
      fprintf(qsubScript, "#PBS -l mppdepth=%d\n", numCoresPerLocale);
    } else {
      length += snprintf(optionString + length, maxOptLength - length,
                         " -l mppwidth=%d -l mppnppn=%d -l mppdepth=%d",
                         numLocales, procsPerNode, numCoresPerLocale);
    }
    break;
  case moab:
    if (generate_qsub_script) {
      fprintf(qsubScript, "#PBS -l nodes=%d\n", numLocales);
    } else {
      length += snprintf(optionString + length, maxOptLength - length,
                         " -l nodes=%d", numLocales);
    }
    break;
  case nccs:
    if (generate_qsub_script) {
      fprintf(qsubScript, "#PBS -l nodes=%d\n", numLocales);
    } else {
      if (!queue && !walltime)
        chpl_error("An execution time must be specified for the NCCS launcher if no queue is\n"
                   "specified -- use the CHPL_LAUNCHER_WALLTIME and/or CHPL_LAUNCHER_QUEUE\n"
                   "environment variables", 0, 0);
      length += snprintf(optionString + length, maxOptLength - length,
                         " -l nodes=%d\n", numLocales);
    }
    break;
  }

  if (generate_qsub_script) {
    fclose(qsubScript);
    optionString = qsubFilename;
  }

  return optionString;
}
예제 #18
0
void chpl_printMemTable(int64_t threshold, int32_t lineno, c_string filename) {
  const int numberWidth   = 9;
  const int precision     = sizeof(uintptr_t) * 2;
  const int addressWidth  = precision+4;
  const int descWidth     = 33;
  int filenameWidth       = strlen("Allocated Memory (Bytes)");
  int totalWidth;

  memTableEntry* memEntry;
  int n, i;
  char* loc;
  memTableEntry** table;

  if (!chpl_memTrack)
    chpl_error("The printMemTable function only works with the --memTrack flag", lineno, filename);

  n = 0;
  filenameWidth = strlen("Allocated Memory (Bytes)");
  for (i = 0; i < hashSize; i++) {
    for (memEntry = memTable[i]; memEntry != NULL; memEntry = memEntry->nextInBucket) {
      size_t chunk = memEntry->number * memEntry->size;
      if (chunk >= threshold) {
        n += 1;
        if (memEntry->filename) {
          int filenameLength = strlen(memEntry->filename);
          if (filenameLength > filenameWidth)
            filenameWidth = filenameLength;
        }
      }
    }
  }

  totalWidth = filenameWidth+numberWidth*4+descWidth+20;
  for (i = 0; i < totalWidth; i++)
    fprintf(memLogFile, "=");
  fprintf(memLogFile, "\n");
  fprintf(memLogFile, "%-*s%-*s%-*s%-*s%-*s%-*s\n",
         filenameWidth+numberWidth, "Allocated Memory (Bytes)",
         numberWidth, "Number",
         numberWidth, "Size",
         numberWidth, "Total",
         descWidth, "Description",
         20, "Address");
  for (i = 0; i < totalWidth; i++)
    fprintf(memLogFile, "=");
  fprintf(memLogFile, "\n");

  table = (memTableEntry**)malloc(n*sizeof(memTableEntry*));
  if (!table)
    chpl_error("out of memory printing memory table", lineno, filename);

  n = 0;
  for (i = 0; i < hashSize; i++) {
    for (memEntry = memTable[i]; memEntry != NULL; memEntry = memEntry->nextInBucket) {
      size_t chunk = memEntry->number * memEntry->size;
      if (chunk >= threshold) {
        table[n++] = memEntry;
      }
    }
  }
  qsort(table, n, sizeof(memTableEntry*), descCmp);

  loc = (char*)malloc((filenameWidth+numberWidth+1)*sizeof(char));

  for (i = 0; i < n; i++) {
    memEntry = table[i];
    if (memEntry->filename)
      sprintf(loc, "%s:%"PRId32, memEntry->filename, memEntry->lineno);
    else
      sprintf(loc, "--");
    fprintf(memLogFile, "%-*s%-*zu%-*zu%-*zu%-*s%#-*.*" PRIxPTR "\n",
           filenameWidth+numberWidth, loc,
           numberWidth, memEntry->number,
           numberWidth, memEntry->size,
           numberWidth, memEntry->size*memEntry->number,
           descWidth, chpl_mem_descString(memEntry->description),
           addressWidth, precision, (uintptr_t)memEntry->memAlloc);
  }
  for (i = 0; i < totalWidth; i++)
    fprintf(memLogFile, "=");
  fprintf(memLogFile, "\n");
  putchar('\n');

  free(table);
  free(loc);
}
예제 #19
0
static char* chpl_launch_create_command(int argc, char* argv[], 
                                        int32_t numLocales) {
  int i;
  int size;
  char baseCommand[256];
  char* command;
  FILE* llFile;
  //  char* projectString = getenv(launcherAccountEnvvar);
  char* basenamePtr = strrchr(argv[0], '/');
  pid_t mypid;

  if (!walltime) {
    chpl_error("You must specify the wall clock time limit of your job using --walltime\n"
               "or CHPL_LAUNCHER_WALLTIME (HH:MM:SS)", 0, NULL);
  }

  if (basenamePtr == NULL) {
      basenamePtr = argv[0];
  } else {
      basenamePtr++;
  }

  chpl_compute_real_binary_name(argv[0]);

  if (debug) {
    mypid = 0;
  } else {
    mypid = getpid();
  }

  sprintf(llFilename, "%s%d", baseLLFilename, (int)mypid);

  llFile = fopen(llFilename, "w");
  fprintf(llFile, "#!/bin/bash\n");
  if (queue) {
    fprintf(llFile, "# @ class = %s\n", queue);
  }
  fprintf(llFile, "# @ job_name = %s\n", basenamePtr);
  fprintf(llFile, "# @ initialdir = .\n");
  fprintf(llFile, "# @ output = %s_%%j.out\n", basenamePtr);
  fprintf(llFile, "# @ error = %s_%%j.out\n", basenamePtr);
  fprintf(llFile, "# @ total_tasks = %d\n", numLocales);
  fprintf(llFile, "# @ cpus_per_task = 4\n");
  fprintf(llFile, "# @ tasks_per_node = 1\n");
  fprintf(llFile, "# @ wall_clock_limit = %s\n", walltime);
  fprintf(llFile, "\n");
#if CHPL_COMM_SUBSTRATE == udp
  fprintf(llFile, "MLIST=$(/opt/perf/bin/sl_get_machine_list -j=\\$SLURM_JOB_ID )\n");
  fprintf(llFile, "\n");
  fprintf(llFile, "export -n SSH_SERVERS\n");
  fprintf(llFile, "for i in $MLIST ; do\n");
  fprintf(llFile, "  export SSH_SERVERS=\"$SSH_SERVERS $i\" ;\n");
  fprintf(llFile, "done\n");
  if (debug) {
    fprintf(llFile, "echo $SSH_SERVERS\n");
  }
  fprintf(llFile, "\n");

  fprintf(llFile, "%samudprun ", WRAP_TO_STR(LAUNCH_PATH));
#elif CHPL_COMM_SUBSTRATE == mpi
  fprintf(llFile, "export MPIRUN_CMD='srun --kill-on-bad-exit %%C'\n");
  fprintf(llFile, "export MPIRUN_CMD_OK=true\n");
  fprintf(llFile, "\n");
  fprintf(llFile, "%sgasnetrun_mpi ", WRAP_TO_STR(LAUNCH_PATH));
#elif CHPL_COMM_SUBSTRATE == none
#else
#error "Unknown CHPL_COMM_SUBSTRATE"
#endif
#if CHPL_COMM_SUBSTRATE != none
  fprintf(llFile, "-n %d ", numLocales);
#endif
  fprintf(llFile, "%s", chpl_get_real_binary_name());
  for (i=1; i<argc; i++) {
    fprintf(llFile, " '%s'", argv[i]);
  }
  fprintf(llFile, " || echo -n \"\"\n");
  fclose(llFile);

  sprintf(baseCommand, "mnsubmit %s", llFilename);

  size = strlen(baseCommand) + 1;

  command = chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, 0);
  
  sprintf(command, "%s", baseCommand);

  if (strlen(command)+1 > size) {
    chpl_internal_error("buffer overflow");
  }

  return command;
}