Exemplo n.º 1
0
void chpl_mem_layerInit(void) {
  void* heap_base_;
  size_t heap_size_;

  chpl_comm_desired_shared_heap(&heap_base_, &heap_size_);
  if (heap_base_ != NULL && heap_size_ == 0) {
    chpl_internal_error("if heap address is specified, size must be also");
  }

  // If we have a shared heap, initialize our shared heap. This will take care
  // of initializing jemalloc. If we're not using a shared heap, do a first
  // allocation to allow jemaloc to set up:
  //
  //   jemalloc 4.0.4 man: "Once, when the first call is made to one of the
  //   memory allocation routines, the allocator initializes its internals"
  if (heap_base_ != NULL) {
    heap_base = heap_base_;
    heap_size = heap_size_;
    cur_heap_offset = 0;
    if (pthread_mutex_init(&chunk_alloc_lock, NULL) != 0) {
      chpl_internal_error("cannot init chunk_alloc lock");
    }
    initializeSharedHeap();
  } else {
    void* p;
    if ((p = je_malloc(1)) == NULL) {
      chpl_internal_error("cannot init heap: je_malloc() failed");
    }
    je_free(p);
  }
}
Exemplo n.º 2
0
void chpl_thread_init(int32_t numThreadsPerLocale,
                      int32_t maxThreadsPerLocale,
                      uint64_t callStackSize,
                      void(*threadBeginFn)(void*),
                      void(*threadEndFn)(void)) {
  //
  // If a value was specified for the call stack size config const, use
  // that (rounded up to a whole number of pages) to set the system
  // stack limit.
  //
  if (callStackSize != 0) {
    uint64_t      pagesize = (uint64_t) sysconf(_SC_PAGESIZE);
    struct rlimit rlim;

    callStackSize = (callStackSize + pagesize - 1) & ~(pagesize - 1);

    if (getrlimit(RLIMIT_STACK, &rlim) != 0)
      chpl_internal_error("getrlimit() failed");

    if (rlim.rlim_max != RLIM_INFINITY && callStackSize > rlim.rlim_max) {
      char warning[128];
      sprintf(warning, "callStackSize capped at %lu\n", 
              (unsigned long)rlim.rlim_max);
      chpl_warning(warning, 0, NULL);

      callStackSize = rlim.rlim_max;
    }

    rlim.rlim_cur = threadCallStackSize = callStackSize;

    if (setrlimit(RLIMIT_STACK, &rlim) != 0)
      chpl_internal_error("setrlimit() failed");
  }
}
Exemplo n.º 3
0
// initialize our arenas (this is required to be able to set the chunk hooks)
static void initialize_arenas(void) {
  size_t s_narenas;
  unsigned narenas;
  unsigned arena;

  // "thread.arena" takes an unsigned, but num_arenas is a size_t.
  s_narenas = get_num_arenas();
  if (s_narenas > (size_t) UINT_MAX) {
    chpl_internal_error("narenas too large to fit into unsigned");
  }
  narenas = (unsigned) s_narenas;

  // for each non-zero arena, set the current thread to use it (this
  // initializes each arena). arena 0 is automatically initialized.
  //
  //   jemalloc 4.0.4 man: "If the specified arena was not initialized
  //   beforehand, it will be automatically initialized as a side effect of
  //   calling this interface."
  for (arena=1; arena<narenas; arena++) {
    if (je_mallctl("thread.arena", NULL, NULL, &arena, sizeof(arena)) != 0) {
      chpl_internal_error("could not change current thread's arena");
    }
  }

  // then set the current thread back to using arena 0
  arena = 0;
  if (je_mallctl("thread.arena", NULL, NULL, &arena, sizeof(arena)) != 0) {
      chpl_internal_error("could not change current thread's arena back to 0");
  }
}
Exemplo n.º 4
0
void chpl_thread_exit(void) {
  chpl_bool debug = false;
  thread_list_p tlp;

  pthread_mutex_lock(&thread_info_lock);
  exiting = true;

  // shut down all threads
  for (tlp = thread_list_head; tlp != NULL; tlp = tlp->next) {
    if (pthread_cancel(tlp->thread) != 0)
      chpl_internal_error("thread cancel failed");
  }

  pthread_mutex_unlock(&thread_info_lock);

  while (thread_list_head != NULL) {
    if (pthread_join(thread_list_head->thread, NULL) != 0)
      chpl_internal_error("thread join failed");
    tlp = thread_list_head;
    thread_list_head = thread_list_head->next;
    chpl_mem_free(tlp, 0, 0);
  }

  CHPL_TLS_DELETE(chpl_thread_id);
  CHPL_TLS_DELETE(chpl_thread_data);

  if (pthread_attr_destroy(&thread_attributes) != 0)
    chpl_internal_error("pthread_attr_destroy() failed");

  if (debug)
    fprintf(stderr, "A total of %u threads were created\n", numThreads);
}
Exemplo n.º 5
0
void chpl_mem_layerInit(void)
{
  void*  heap_base;
  size_t heap_size;

  chpl_comm_desired_shared_heap(&heap_base, &heap_size);

  if (heap_base != NULL && heap_size == 0)
    chpl_internal_error("if heap address is specified, size must be also");

  //
  // Do a first allocation, to allow tcmalloc to set up its internal
  // management structures.
  //
  {
    void* p;

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

  //
  // Initialize our tcmalloc system allocator.
  //
  tcmallocChapelInit_c(heap_base, heap_size);

  //
  // If the heap has to come from the memory supplied to us (say, in
  // order that the comm layer be able to depend on all allocations
  // having come from it), use up all the system memory tcmalloc had
  // acquired before we set up our own system allocator just now.
  // All allocations after this will come from the memory supplied
  // to us.
  //
  // Note that this can waste up to twice INITIAL_USE_UP_SIZE bytes
  // of the memory supplied to us, plus overhead.
  //
  if (heap_base != NULL) {
#define INITIAL_USE_UP_SIZE ((size_t) 4 * 1024)

    size_t size;
    char*  p;

    for (size = INITIAL_USE_UP_SIZE; size > 0; size /= 2) {
      do {
        p = tc_malloc(size);
      } while (p != NULL
               && (p < (char*) heap_base
                   || p > (char*) heap_base + heap_size));

#undef INITIAL_USE_UP_SIZE
    }
  }
}
Exemplo n.º 6
0
static
void maybe_set_jemalloc_lg_chunk(void) {
  size_t hps;

  hps = chpl_comm_ugni_getHeapPageSize();
  if (hps == chpl_comm_ugni_getSysPageSize())
    return;

  //
  // We're using the jemalloc memory layer, the heap is dynamically
  // extensible, and we've got hugepages, so we'll be registering
  // memory.  (chpl_comm_ugni_getHeapPageSize()) checks all this.)
  //
  // Arrange for jemalloc's chunk size (and alignment) to be the same
  // as what the comm layer recommends, which is the heap page size.
  // Make sure this is a power of 2, because jemalloc needs that.
  //
  int hps_log2;
  char* ev;
  char buf[1000];

  // sanity check: power of 2 and >= sys page size
  assert((hps & (hps - 1)) == 0
         && hps >= chpl_comm_ugni_getSysPageSize());

  // lg_chunk is specified as the base-2 log of the expansion chunk size
  hps_log2 = lrint(log2((double) hps));

  //
  // Now, set the jemalloc environment variable.  We also must include
  // the "purge:" setting we specify at jemalloc configuration time,
  // because the env var overrides config-time settings.
  //
  if ((ev = getenv(jemalloc_conf_ev_name())) == NULL) {
    const char* fmt = "purge:decay,lg_chunk:%d";
    if (snprintf(buf, sizeof(buf), fmt, hps_log2) >= sizeof(buf)) {
      chpl_internal_error("setting jemalloc conf env var would truncate");
    }
  } else {
    // Override any user-specified lg_chunk.  Smaller or larger, it
    // would break our logic either way.
    const char* fmt = ((strstr(ev, "purge:") == NULL)
                       ? "%s,purge:decay,lg_chunk:%d"
                       : "%s,lg_chunk:%d");
    if (snprintf(buf, sizeof(buf), fmt, ev, hps_log2) >= sizeof(buf)) {
      chpl_internal_error("setting jemalloc conf env var would truncate");
    }
  }

  if (setenv(jemalloc_conf_ev_name(), buf, 1) != 0)
    chpl_internal_error("cannot setenv jemalloc conf env var");
}
Exemplo n.º 7
0
static
void report_error(const char* what, int errnum) {
  char buf[100];

  snprintf(buf, sizeof(buf), "%s: %s", what, strerror(errnum));
  chpl_internal_error(buf);
}
Exemplo n.º 8
0
void chpl_comm_post_task_init(void) {
  int i;

  if (chpl_numNodes == 1) {
    // return;
  }

  libfabric_init();
  chpl_comm_ofi_put_get_init(&ofi);
  chpl_comm_ofi_am_init(&ofi);

  if (num_progress_threads > 0) {
    // Start progress thread(s).  Don't proceed from here until at
    // least one is running.
    CALL_CHECK_ZERO(pthread_mutex_lock(&progress_thread_entEx_cond_mutex));

    for (i = 0; i < num_progress_threads; i++) {
      pti[i]. id = i;
      if (chpl_task_createCommTask(progress_thread, (void *) &pti[i]) != 0) {
        chpl_internal_error("unable to start progress thread");
      }
    }

    // Some progress thread we created will release us.
    CALL_CHECK_ZERO(pthread_cond_wait(&progress_thread_enter_cond,
                                      &progress_thread_entEx_cond_mutex));
    CALL_CHECK_ZERO(pthread_mutex_unlock(&progress_thread_entEx_cond_mutex));
  }

  // Initialize the caching layer, if it is active.
  // chpl_cache_init();

}
Exemplo n.º 9
0
// replace the chunk hooks for each arena with the hooks we provided above
static void replaceChunkHooks(void) {
  size_t narenas;
  size_t arena;

  // set the pointers for the new_hooks to our above functions
  chunk_hooks_t new_hooks = {
    chunk_alloc,
    null_dalloc,
    null_commit,
    null_decommit,
    null_purge,
    null_split,
    null_merge
  };

  // for each arena, change the chunk hooks
  narenas = get_num_arenas();
  for (arena=0; arena<narenas; arena++) {
    char path[128];
    snprintf(path, sizeof(path), "arena.%zu.chunk_hooks", arena);
    if (je_mallctl(path, NULL, NULL, &new_hooks, sizeof(chunk_hooks_t)) != 0) {
      chpl_internal_error("could not update the chunk hooks");
    }
  }
}
Exemplo n.º 10
0
static char* chpl_launch_create_command(int argc, char* argv[], 
                                        int32_t numLocales) {
  int i;
  int size;
  char baseCommand[256];
  char* command;

  chpl_compute_real_binary_name(argv[0]);

  sprintf(baseCommand, "mpirun -np %d %s %s", numLocales, MPIRUN_XTRA_OPTS, 
          chpl_get_real_binary_name());

  size = strlen(MPIRUN_PATH) + 1 + strlen(baseCommand) + 1;

  for (i=1; i<argc; i++) {
    size += strlen(argv[i]) + 3;
  }

  command = chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, "");
  
  sprintf(command, "%s/%s", MPIRUN_PATH, baseCommand);
  for (i=1; i<argc; i++) {
    strcat(command, " '");
    strcat(command, argv[i]);
    strcat(command, "'");
  }

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

  return command;
}
Exemplo n.º 11
0
//
// With mem=jemalloc and comm=ugni with hugepages and a dynamically
// extensible heap, we have to configure jemalloc's large chunk size.
// It would be preferable to deal with this entirely within the target
// program, but we need it before jemalloc does its constructor-based
// initialization and we don't have a dependable way to arrange that
// in the target program.
//
static
char* jemalloc_conf_ev_name(void) {
#define _STRFY(s)              #s
#define _EXPAND_THEN_STRFY(s)  _STRFY(s)
#ifdef CHPL_JEMALLOC_PREFIX
  #define EVN_PREFIX_STR         _EXPAND_THEN_STRFY(CHPL_JEMALLOC_PREFIX)
#else
  #define EVN_PREFIX_STR         ""
#endif

  static char evn[100] = "";

  // safe because always called serially
  if (evn[0] != '\0')
    return evn;

  if (snprintf(evn, sizeof(evn), "%sMALLOC_CONF", EVN_PREFIX_STR)
      >= sizeof(evn)) {
    chpl_internal_error("jemalloc conf env var name buffer is too small");
  }

  for (int i = 0; evn[i] != '\0'; i++) {
    if (islower(evn[i]))
      evn[i] = toupper(evn[i]);
  }

  return evn;

#undef _STRFY
#undef _EXPAND_THEN_STRFY
#undef EVN_PREFIX_STR
}
Exemplo n.º 12
0
static char* chpl_launch_create_command(int argc, char* argv[], 
                                        int32_t numLocales) {
  int i;
  int size;
  char baseCommand[256];
  char* command;
  if (numLocales != 1) {
    chpl_error("dummy launcher only supports numLocales==1", 0, "<command-line>");
  }

  chpl_compute_real_binary_name(argv[0]);

  sprintf(baseCommand, "%s", chpl_get_real_binary_name());

  size = strlen(baseCommand) + 1;

  for (i=1; i<argc; i++) {
    size += strlen(argv[i]) + 3;
  }

  command = chpl_mem_allocMany(size, sizeof(char), CHPL_RT_MD_COMMAND_BUFFER, -1, "");
  
  sprintf(command, "%s", baseCommand);
  for (i=1; i<argc; i++) {
    strcat(command, " '");
    strcat(command, argv[i]);
    strcat(command, "'");
  }

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

  return command;
}
Exemplo n.º 13
0
void chpl_compute_real_binary_name(const char* argv0) {

  char* cursor = chpl_real_binary_name;
  int exe_length = strlen(launcher_exe_suffix);
  int length;
  const char* real_suffix = getenv("CHPL_LAUNCHER_SUFFIX");

  if (NULL == real_suffix) {
    real_suffix = launcher_real_suffix;
  }
  
  length = strlen(argv0);
  if (length + strlen(launcher_real_suffix) >= BIN_NAME_SIZE)
    chpl_internal_error("Real executable name is too long.");

  // See if the launcher name contains the exe_suffix
  if (exe_length > 0 &&
      !strncmp(argv0 + length - exe_length, launcher_exe_suffix, exe_length))
    // We matched the exe suffix, so remove it before adding the real suffix.
    length -= exe_length;

  // Copy the filename sans exe suffix.
  strncpy(cursor, argv0, length);
  cursor += length;
  strcpy(cursor, launcher_real_suffix);
}
Exemplo n.º 14
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, *expectFile;
  char* projectString = getenv(launcherAccountEnvvar);
  char* basenamePtr = strrchr(argv[0], '/');
  pid_t mypid;

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

  chpl_compute_real_binary_name(argv[0]);

#ifndef DEBUG_LAUNCH
  mypid = getpid();
#else
  mypid = 0;
#endif
  sprintf(expectFilename, "%s%d", baseExpectFilename, (int)mypid);
  sprintf(llFilename, "%s%d", baseLLFilename, (int)mypid);

  llFile = fopen(llFilename, "w");
  fprintf(llFile, "# @ wall_clock_limit = 00:10:00\n");
  fprintf(llFile, "# @ job_type = parallel\n");
  fprintf(llFile, "# @ node = %d\n", numLocales);
  fprintf(llFile, "# @ tasks_per_node = 1\n");
  if (projectString && strlen(projectString) > 0)
      fprintf(llFile, "# @ class = %s\n", projectString);
  fprintf(llFile, "# @ output = out.$(jobid)\n");
  fprintf(llFile, "# @ error = err.$(jobid)\n");
  fprintf(llFile, "# @ queue\n");
  fprintf(llFile, "\n");
  fprintf(llFile, "%s", chpl_get_real_binary_name());
  for (i=1; i<argc; i++) {
      fprintf(llFile, " '%s'", argv[i]);
  }
  fprintf(llFile, "\n");
  fclose(llFile);

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

  size = strlen(baseCommand) + 1;

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

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

  return command;
}
Exemplo n.º 15
0
size_t chpl_comm_getenvMaxHeapSize(void)
{
  if (pthread_once(&maxHeapSize_once, set_maxHeapSize) != 0) {
    chpl_internal_error("pthread_once(&maxHeapSize_once) failed");
  }

  return maxHeapSize;
}
Exemplo n.º 16
0
// get the number of arenas
static size_t get_num_arenas(void) {
  size_t narenas;
  size_t sz;
  sz = sizeof(narenas);
  if (je_mallctl("opt.narenas", &narenas, &sz, NULL, 0) != 0) {
    chpl_internal_error("could not get number of arenas from jemalloc");
  }
  return narenas;
}
Exemplo n.º 17
0
static void chpl_thread_condvar_destroy(chpl_thread_condvar_t* cv) {
// Leak condvars on cygwin. Some bug results from condvars still being used at
// this point on cygwin. For now, just leak them to avoid errors as a result of
// the undefined behavior of trying to destroy an in-use condvar.
#ifndef __CYGWIN__
  if (pthread_cond_destroy((pthread_cond_t*) cv))
    chpl_internal_error("pthread_cond_destroy() failed");
#endif
}
Exemplo n.º 18
0
//
// Get the the thread private data pointer for my thread.
//
static thread_private_data_t* get_thread_private_data(void) {
  thread_private_data_t* tp;

  tp = (thread_private_data_t*) chpl_thread_getPrivateData();

  if (tp == NULL)
    chpl_internal_error("no thread private data");

  return tp;
}
Exemplo n.º 19
0
void chpl_comm_startVerbose(chpl_bool print_unstable) {
    chpl_comm_diags_print_unstable = (print_unstable == true);
  if (pthread_once(&bcastPrintUnstable_once, broadcast_print_unstable) != 0) {
    chpl_internal_error("pthread_once(&bcastPrintUnstable_once) failed");
  }

  chpl_verbose_comm = 1;
  chpl_comm_diags_disable();
  chpl_comm_bcast_rt_private(chpl_verbose_comm);
  chpl_comm_diags_enable();
}
Exemplo n.º 20
0
const char* chpl_env_rt_get(const char* evs, const char* dflt) {
  char evName[100];
  const char* evVal;

  if (snprintf(evName, sizeof(evName), "CHPL_RT_%s", evs) >= sizeof(evName))
    chpl_internal_error("environment variable name buffer too small");

  evVal = getenv(evName);
  if (evVal == NULL)
    return dflt;
  return evVal;
}
Exemplo n.º 21
0
int chpl_rt_isDir(const char* pathname, chpl_bool followLinks) {
  struct stat fileinfo;
  if (followLinks) {
    int status = stat(pathname, &fileinfo);
    if (status) {
      chpl_internal_error("Fatal error in stat()");
    }
    return S_ISDIR(fileinfo.st_mode);
    /*  return fileinfo.st_mode & S_IFDIR;*/
  } else {
    int status = lstat(pathname, &fileinfo);
    if (status) {
      chpl_internal_error("Fatal error in lstat()");
    }
    if (fileinfo.st_mode & S_IFLNK) {
      return false;
    } else {
      return S_ISDIR(fileinfo.st_mode);
    }
  }
}
Exemplo n.º 22
0
void chpl_comm_startDiagnostics(chpl_bool print_unstable) {
  chpl_comm_diags_print_unstable = (print_unstable == true);
  if (pthread_once(&bcastPrintUnstable_once, broadcast_print_unstable) != 0) {
    chpl_internal_error("pthread_once(&bcastPrintUnstable_once) failed");
  }

  // Make sure that there are no pending communication operations.
  chpl_rmem_consist_release(0, 0);

  chpl_comm_diagnostics = 1;
  chpl_comm_diags_disable();
  chpl_comm_bcast_rt_private(chpl_comm_diagnostics);
  chpl_comm_diags_enable();
}
Exemplo n.º 23
0
int chpl_launch_using_fork_exec(const char* command, char * const argv1[], const char* argv0) {
  int status;
  pid_t pid = fork();
  switch (pid) {
  case 0:
    chpl_launch_using_exec(command, argv1, argv0);
    // should not return
  case -1:
  {
    char msg[256];
    sprintf(msg, "fork() failed: %s", strerror(errno));
    chpl_internal_error(msg);
  }
  default:
    {
      if (waitpid(pid, &status, 0) != pid) {
        char msg[256];
        sprintf(msg, "waitpid() failed: %s", strerror(errno));
        chpl_internal_error(msg);
      }
    }
  }
  return WEXITSTATUS(status);
}
Exemplo n.º 24
0
const char* lookupSetValue(const char* varName, const char* moduleName) {
  configVarType* configVar;
  if (strcmp(moduleName, "") == 0) {
    const char* message = "Attempted to lookup value with the module name an "
      "empty string";
    chpl_internal_error(message);
  }

  configVar = lookupConfigVar(moduleName, varName);
  if (configVar) {
    return configVar->setValue;
  } else {
    return NULL;
  }
}
Exemplo n.º 25
0
Arquivo: chplcast.c Projeto: 8l/chapel
static int scanningNCounts(void) {
  static int answer = -1;
  if (answer == -1) {
    int result;
    int position;
    int numitems = sscanf("10", "%d%n", &result, &position);
    if (numitems == 1) {
      answer = 0;
    } else if (numitems == 2) {
      answer = 1;
    } else {
      chpl_internal_error("Misassumption in scanningNCounts()");
    }
  }
  return answer;
}
Exemplo n.º 26
0
void initSetValue(const char* varName, const char* value, 
                  const char* moduleName, 
                  int32_t lineno, chpl_string filename) {
  configVarType* configVar;
  if  (*varName == '\0') {
    const char* message = "No variable name given";
    chpl_error(message, lineno, filename);
  }
  configVar = lookupConfigVar(moduleName, varName);
  if (configVar == NULL || configVar == ambiguousConfigVar) {
    chpl_internal_error("unknown config var case not handled appropriately");
  }
  if (strcmp(varName, "numLocales") == 0) {
    parseNumLocales(value, lineno, filename);
  }
  configVar->setValue = chpl_glom_strings(1, value);
}
Exemplo n.º 27
0
static void useUpMemNotInHeap(void) {
  // grab (and leak) whatever memory jemalloc got on it's own, that's not in
  // our shared heap
  //
  //   jemalloc 4.0.4 man: "arenas may have already created chunks prior to the
  //   application having an opportunity to take over chunk allocation."
  //
  // Note that this will also allow jemalloc to initialize itself since
  char* p = NULL;
  do {
    // TODO use a larger value than size_t here (must be smaller than
    // "arenas.hchunk.0.size" though
    if ((p = je_malloc(sizeof(size_t))) == NULL) {
      chpl_internal_error("could not use up memory outside of shared heap");
    }
  } while ((p != NULL && (p < (char*) heap_base || p > (char*) heap_base + heap_size)));
}
Exemplo n.º 28
0
void chpl_task_callMain(void (*chpl_main)(void)) {
  // since we want to run all work in a task with a comm-friendly stack,
  // run main in a pthread that we will wait for.
  size_t stack_size;
  void* stack;
  pthread_attr_t attr;
  pthread_t thread;
  int rc;

  stack = NULL;
  chpl_init_heap_stack();

  rc = pthread_attr_init(&attr);
  if( rc != 0 ) {
    chpl_internal_error("pthread_attr_init main failed");
  }

  stack_size  = chpl_thread_getCallStackSize();
  
  if(chpl_alloc_stack_in_heap){
    stack = chpl_alloc_pthread_stack(stack_size);
    if(stack == NULL)
      chpl_internal_error("chpl_alloc_pthread_stack main failed");
  
    rc = pthread_attr_setstack(&attr, stack, stack_size);
    if( rc != 0 ) {
      chpl_internal_error("pthread_attr_setstack main failed");
    }
  }
  else {
    rc = pthread_attr_setstacksize(&attr, stack_size);
    if( rc != 0 ) {
      chpl_internal_error("pthread_attr_setstacksize main failed");
    }
  }

  rc = pthread_create(&thread, &attr, do_callMain, chpl_main);
  if( rc != 0 ) {
    chpl_internal_error("pthread_create main failed");
  }

  rc = pthread_join(thread, NULL);
  if( rc != 0 ) {
    chpl_internal_error("pthread_join main failed");
  }

  if(chpl_alloc_stack_in_heap){
    chpl_free_pthread_stack(stack);
  }
  
  pthread_attr_destroy(&attr);
}
Exemplo n.º 29
0
void qbytes_free_munmap(qbytes_t* b) {
  err_t err;

  /* I don't believe this is required, but 
   * I've heard here and there it might be for NFS...
   *
  rc = msync(b->data, b->len, MS_ASYNC);
  if( rc ) fprintf(stderr, "Warning - in qbytes_free_munmap, msync failed with %i, errno %i\n", rc, errno);
  */

  err = sys_munmap(b->data, b->len);

  if (err) {
    chpl_internal_error("sys_munmap() failed");
  }

  _qbytes_free_qbytes(b);
}
Exemplo n.º 30
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);
  }

}