Пример #1
0
        def node2vec_walks():
            """Simulate a random walk starting from start node."""
            n = start_node_idx_ary.size
            # use last entry of each walk index array to keep track of effective walk length
            walk_idx_mat = np.zeros((n, walk_length + 2), dtype=np.uint32)
            walk_idx_mat[:, 0] = start_node_idx_ary  # initialize seeds
            walk_idx_mat[:,
                         -1] = walk_length + 1  # set to full walk length by default

            # progress bar parameters
            n_checkpoints = 10
            checkpoint = n / get_num_threads() // n_checkpoints
            progress_bar_length = 25
            private_count = 0

            for i in prange(n):
                # initialize first step as normal random walk
                start_node_idx = walk_idx_mat[i, 0]
                if has_nbrs(start_node_idx):
                    walk_idx_mat[i, 1] = move_forward(start_node_idx)
                else:
                    walk_idx_mat[i, -1] = 1
                    continue

                # start bias random walk
                for j in range(2, walk_length + 1):
                    cur_idx = walk_idx_mat[i, j - 1]
                    if has_nbrs(cur_idx):
                        prev_idx = walk_idx_mat[i, j - 2]
                        walk_idx_mat[i, j] = move_forward(cur_idx, prev_idx)
                    else:
                        walk_idx_mat[i, -1] = j
                        break

                if verbose:
                    # TODO: make monitoring less messy
                    private_count += 1
                    if private_count % checkpoint == 0:
                        progress = private_count / n * progress_bar_length * get_num_threads(
                        )

                        # manuual construct progress bar since string formatting not supported
                        progress_bar = '|'
                        for k in range(progress_bar_length):
                            progress_bar += '#' if k < progress else ' '
                        progress_bar += '|'

                        print(
                            "Thread # "
                            if _get_thread_id() < 10 else "Thread #",
                            _get_thread_id(), "progress:", progress_bar,
                            get_num_threads() * private_count * 10000 // n /
                            100, "%")

            return walk_idx_mat
Пример #2
0
 def test_func():
     set_num_threads(mask)
     x = 5000000
     buf = np.empty((x, ))
     for i in prange(x):
         buf[i] = _get_thread_id()
     return len(np.unique(buf)), get_num_threads()
Пример #3
0
 def work(local_nt):  # arg is value 3
     tid = np.zeros(BIG)
     acc = 0
     set_num_threads(local_nt)  # set to 3 threads
     for i in prange(BIG):
         acc += 1
         tid[i] = _get_thread_id()
     return acc, np.unique(tid)
Пример #4
0
 def test_gufunc(x, out):
     set_num_threads(mask)
     x[:] = _get_thread_id()
     out[0] = get_num_threads()