void fractal_group::run( bool create_second_fractal ) {
    // initialize task scheduler
    tbb::task_scheduler_init init( num_threads );

    // create contexts to manage fractal priorities
    context = new tbb::task_group_context[2];

    set_priorities();
    draw_borders();

    // the second fractal is calculating on separated thread
    std::thread *fg_thread = 0;
    if ( create_second_fractal ) fg_thread = new std::thread( fg_thread_func, this );

    // calculate the first fractal
    calc_fractal( 0 );

    if ( fg_thread ) {
        // wait for second fractal
        fg_thread->join();
        delete fg_thread;
    }

    delete[] context;
}
Example #2
0
File: hh_shared.c Project: 2bj/hhvm
void hh_shared_init() {
  /* MAP_NORESERVE is because we want a lot more virtual memory than what
   * we are actually going to use.
   */
  int flags = MAP_SHARED | MAP_ANONYMOUS | MAP_NORESERVE;
  int prot  = PROT_READ  | PROT_WRITE;

  page_size = getpagesize();

  shared_mem = 
    (char*)mmap(NULL, page_size + SHARED_MEM_SIZE, prot, flags, 0, 0);

  if(shared_mem == MAP_FAILED) {
    printf("Error initializing: %s\n", strerror(errno));
    exit(2);
  }

  // Keeping the pids around to make asserts.
  master_pid = getpid();
  my_pid = master_pid;

  init_shared_globals(shared_mem);

  // Uninstall ocaml's segfault handler. It's supposed to throw an exception on
  // stack overflow, but we don't actually handle that exception, so what
  // happens in practice is we terminate at toplevel with an unhandled exception
  // and a useless ocaml backtrace. A core dump is actually more useful. Sigh.
  struct sigaction sigact = {};
  sigact.sa_handler = SIG_DFL;
  sigemptyset(&sigact.sa_mask);
  sigact.sa_flags = 0;
  sigaction(SIGSEGV, &sigact, NULL);

  set_priorities();
}
Example #3
0
void fractal_group::run( bool create_second_fractal ) {
    // initialize task scheduler
    tbb::task_scheduler_init init( num_threads );

    // create contexts to manage fractal priorities
    context = new tbb::task_group_context[2];

    set_priorities();
    draw_borders();

    tbb::task_arena arena;
    tbb::task_group gr;

    // the second fractal is calculating on separated thread
    if ( create_second_fractal ) {
#if __TBB_CPP11_LAMBDAS_PRESENT
        arena.execute( [&] {
            gr.run( [&] { calc_fractal( 1 ); } );
        } );
#else
        task_group_body tg_body( *this );
        arena_body a_body( tg_body, gr );
        arena.execute( a_body );
#endif
    }

    // calculate the first fractal
    calc_fractal( 0 );

    if ( create_second_fractal ) {
#if __TBB_CPP11_LAMBDAS_PRESENT
        // wait for second fractal
        arena.execute( [&] { gr.wait(); } );
#else
        arena.execute( arena_body_wait( gr ) );
#endif
    }

    delete[] context;
}
Example #4
0
/*
 * Take a list of jobs, break it into sublists, return a pointer to a
 * new list of jobs in the order in which they should be run.
 */
Job *
schd_sort_jobs(Job *jobs)
  {
  Job *newjobs = NULL;

  if (split_jobs(jobs))
    return (NULL);

  /* Create the list of all users with queued and running jobs */
  get_users();

  /* Assign jobs a priority value based on their originating queue */
  set_priorities();

  /* Sort jobs in normalQ. */
  sort_jobs();

  /* Convert arrays of jobs into a linked list. */
  newjobs = make_job_list();

  return (newjobs);
  }
Example #5
0
void fractal_group::switch_priorities( int new_active ) {
    if( new_active!=-1 ) active = new_active;
    else                 active = 1-active; // assumes 'active' is only 0 or 1
    set_priorities();
    draw_borders();
}
Example #6
0
void hh_shared_init(
  value global_size_val,
  value heap_size_val
) {

  CAMLparam2(global_size_val, heap_size_val);

  global_size_b = Long_val(global_size_val);
  heap_size = Long_val(heap_size_val);

  /* MAP_NORESERVE is because we want a lot more virtual memory than what
   * we are actually going to use.
   */
  int flags = MAP_SHARED | MAP_ANON | MAP_NORESERVE | MAP_FIXED;
  int prot  = PROT_READ  | PROT_WRITE;

  int page_size = getpagesize();

  /* The total size of the shared memory.  Most of it is going to remain
   * virtual. */
  size_t shared_mem_size = global_size_b + 2 * DEP_SIZE_B + HASHTBL_SIZE_B +
      heap_size;

  char* shared_mem =
    (char*)mmap((void*)SHARED_MEM_INIT, page_size + shared_mem_size, prot,
                flags, 0, 0);

  if(shared_mem == MAP_FAILED) {
    printf("Error initializing: %s\n", strerror(errno));
    exit(2);
  }

#ifdef MADV_DONTDUMP
  // We are unlikely to get much useful information out of the shared heap in
  // a core file. Moreover, it can be HUGE, and the extensive work done dumping
  // it once for each CPU can mean that the user will reboot their machine
  // before the much more useful stack gets dumped!
  madvise(shared_mem, page_size + shared_mem_size, MADV_DONTDUMP);
#endif

  // Keeping the pids around to make asserts.
  master_pid = getpid();
  my_pid = master_pid;

  char* bottom = shared_mem;

  init_shared_globals(shared_mem);

  // Checking that we did the maths correctly.
  assert(*heap + heap_size == bottom + shared_mem_size + page_size);

  // Uninstall ocaml's segfault handler. It's supposed to throw an exception on
  // stack overflow, but we don't actually handle that exception, so what
  // happens in practice is we terminate at toplevel with an unhandled exception
  // and a useless ocaml backtrace. A core dump is actually more useful. Sigh.
  struct sigaction sigact;
  sigact.sa_handler = SIG_DFL;
  sigemptyset(&sigact.sa_mask);
  sigact.sa_flags = 0;
  sigaction(SIGSEGV, &sigact, NULL);

  set_priorities();

  CAMLreturn0;
}
Example #7
0
value hh_shared_init(
  value global_size_val,
  value heap_size_val
) {

  CAMLparam2(global_size_val, heap_size_val);

  global_size_b = Long_val(global_size_val);
  heap_size = Long_val(heap_size_val);

  char* shared_mem;

  size_t page_size = getpagesize();

  /* The total size of the shared memory.  Most of it is going to remain
   * virtual. */
  size_t shared_mem_size =
    global_size_b + 2 * DEP_SIZE_B + HASHTBL_SIZE_B +
    heap_size + page_size;

#ifdef _WIN32
  /*

     We create an anonymous memory file, whose `handle` might be
     inherited by slave processes.

     This memory file is tagged "reserved" but not "committed". This
     means that the memory space will be reserved in the virtual
     memory table but the pages will not be bound to any physical
     memory yet. Further calls to 'VirtualAlloc' will "commit" pages,
     meaning they will be bound to physical memory.

     This is behavior that should reflect the 'MAP_NORESERVE' flag of
     'mmap' on Unix. But, on Unix, the "commit" is implicit.

     Committing the whole shared heap at once would require the same
     amount of free space in memory (or in swap file).

  */
  HANDLE handle = CreateFileMapping(
    INVALID_HANDLE_VALUE,
    NULL,
    PAGE_READWRITE | SEC_RESERVE,
    shared_mem_size >> 32, shared_mem_size & ((1ll << 32) - 1),
    NULL);
  if (handle == NULL) {
    win32_maperr(GetLastError());
    uerror("CreateFileMapping", Nothing);
  }
  if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT)) {
    win32_maperr(GetLastError());
    uerror("SetHandleInformation", Nothing);
  }
  shared_mem = MapViewOfFileEx(
    handle,
    FILE_MAP_ALL_ACCESS,
    0, 0,
    0,
    (char *)SHARED_MEM_INIT);
  if (shared_mem != (char *)SHARED_MEM_INIT) {
    shared_mem = NULL;
    win32_maperr(GetLastError());
    uerror("MapViewOfFileEx", Nothing);
  }

#else /* _WIN32 */

  /* MAP_NORESERVE is because we want a lot more virtual memory than what
   * we are actually going to use.
   */
  int flags = MAP_SHARED | MAP_ANON | MAP_NORESERVE | MAP_FIXED;
  int prot  = PROT_READ  | PROT_WRITE;

  shared_mem =
    (char*)mmap((void*)SHARED_MEM_INIT,  shared_mem_size, prot,
                flags, 0, 0);
  if(shared_mem == MAP_FAILED) {
    printf("Error initializing: %s\n", strerror(errno));
    exit(2);
  }

#ifdef MADV_DONTDUMP
  // We are unlikely to get much useful information out of the shared heap in
  // a core file. Moreover, it can be HUGE, and the extensive work done dumping
  // it once for each CPU can mean that the user will reboot their machine
  // before the much more useful stack gets dumped!
  madvise(shared_mem, shared_mem_size, MADV_DONTDUMP);
#endif

  // Keeping the pids around to make asserts.
  master_pid = getpid();
  my_pid = master_pid;

#endif /* _WIN32 */

  char* bottom = shared_mem;
  init_shared_globals(shared_mem);

  // Checking that we did the maths correctly.
  assert(*heap + heap_size == bottom + shared_mem_size);

#ifndef _WIN32
  // Uninstall ocaml's segfault handler. It's supposed to throw an exception on
  // stack overflow, but we don't actually handle that exception, so what
  // happens in practice is we terminate at toplevel with an unhandled exception
  // and a useless ocaml backtrace. A core dump is actually more useful. Sigh.
  struct sigaction sigact;
  sigact.sa_handler = SIG_DFL;
  sigemptyset(&sigact.sa_mask);
  sigact.sa_flags = 0;
  sigaction(SIGSEGV, &sigact, NULL);
#endif

  set_priorities();

  CAMLreturn(Val_unit);
}