code: def generate_pairs(all_walks, window_size, num_workers):
      # for each node, choose the first neighbor and second neighbor of it to form pairs
      # Get all worker processes
      start_time = time.time()
      print(
          "We are generating pairs with {} cores.".format(num_workers)
      )
  
      # Start all worker processes
      pool = multiprocessing.Pool(processes=num_workers)
      pairs = []
      skip_window = window_size // 2
      for layer_id, walks in enumerate(all_walks):
          block_num = len(walks) // num_workers
          if block_num > 0:
              walks_list = [
                  walks[
                      i
                      * block_num : min((i + 1) * block_num, len(walks))
                  ]
                  for i in range(num_workers)
              ]
          else:
              walks_list = [walks]
          tmp_result = pool.map(
              partial(
                  generate_pairs_parallel,
                  skip_window=skip_window,
                  layer_id=layer_id,
              ),
              walks_list,
          )
          pairs += reduce(lambda x, y: x + y, tmp_result)
  
      pool.close()
      end_time = time.time()
      print(
          "Generate pairs end, use {}s.".format(end_time - start_time)
      )
      return np.array([list(pair) for pair in set(pairs)])
  
file_path: dgl/examples/pytorch/GATNE-T/src/utils.py
imports: import argparse
  import multiprocessing
  import time
  from collections import defaultdict
  from functools import partial, reduce, wraps
  import networkx
  import numpy
  import torch
  from gensim.models.keyedvectors import Vocab
  from six import iteritems
  from sklearn.metrics import auc, f1_score, precision_recall_curve, roc_auc_score
label_desc: Use image node_id 6 for calling a global function with example usage: generate_pairs(all_walks, window_size, num_workers) and returns: np