code: def get_missing_blocks_by_rank(
      workdir, n_samples, block_size, validate=lambda f: None
  ):
      """Divide missing blocks evenly across all ranks.
  
      See 'get_missing_blocks()' above for description. The returned list of
      missing blocks is split evenly across ranks via interleaving. This way,
      each rank has a roughly equal number of blocks to process for a
      downstream operation.
      """
  
      missing_blocks = get_missing_blocks(
          workdir, n_samples, block_size, validate
      )
  
      # This rank's missing files.
      data_parallel_rank = parallel_state.get_data_parallel_rank()
      data_parallel_world_size = (
          parallel_state.get_data_parallel_world_size()
      )
      rank_missing_blocks = missing_blocks[
          data_parallel_rank : len(
              missing_blocks
          ) : data_parallel_world_size
      ]
  
      # Extend rank's missing blocks (with None) such that all ranks have equal
      # length lists. This allows for easier tracking of global progress.
      n_missing_tensor = torch.tensor(
          [len(rank_missing_blocks)], dtype=torch.long, device="cuda"
      )
      torch.distributed.all_reduce(
          n_missing_tensor, op=torch.distributed.ReduceOp.MAX
      )
      max_n_missing = n_missing_tensor.item()
      rank_missing_blocks += [None] * (
          max_n_missing - len(rank_missing_blocks)
      )
  
      return len(missing_blocks), rank_missing_blocks
  
file_path: megatron-lm/tools/bert_embedding/utils.py
imports: from collections import defaultdict
  import glob
  import numpy
  import os
  import torch
  from tqdm import tqdm
  from megatron import print_rank_0
  from megatron.core import parallel_state
  from .external_libs import h5py
label_desc: Use image node_id 4 for calling a global function with example usage: get_missing_blocks_by_rank(workdir, n_samples, block_size, validate) and returns: len,  rank_missing_blocks