code: def run_on_main(
      func,
      args=None,
      kwargs=None,
      post_func=None,
      post_args=None,
      post_kwargs=None,
      run_post_on_main=False,
  ):
      """Runs a function with DPP (multi-gpu) support.
  
      The main function is only run on the main process.
      A post_function can be specified, to be on non-main processes after the main
      func completes. This way whatever the main func produces can be loaded on
      the other processes.
  
      Arguments
      ---------
      func : callable
          Function to run on the main process.
      args : list, None
          Positional args to pass to func.
      kwargs : dict, None
          Keyword args to pass to func.
      post_func : callable, None
          Function to run after func has finished on main. By default only run on
          non-main processes.
      post_args : list, None
          Positional args to pass to post_func.
      post_kwargs : dict, None
          Keyword args to pass to post_func.
      run_post_on_main : bool
          Whether to run post_func on main process as well. (default: False)
      """
      # Handle the mutable data types' default args:
      if args is None:
          args = []
      if kwargs is None:
          kwargs = {}
      if post_args is None:
          post_args = []
      if post_kwargs is None:
          post_kwargs = {}
  
      main_process_only(func)(*args, **kwargs)
      ddp_barrier()
  
      if post_func is not None:
          if run_post_on_main:
              # Just run on every process without any barrier.
              post_func(*post_args, **post_kwargs)
          else:
              # Do the opposite of `run_on_main`
              if not if_main_process():
                  post_func(*post_args, **post_kwargs)
              ddp_barrier()
  
file_path: speechbrain/speechbrain/utils/distributed.py
imports: import datetime
  import os
  import torch
  from functools import wraps
label_desc: Use image node_id 1 for calling a global function with example usage: run_on_main(func, args, kwargs, post_func, post_args, post_kwargs, run_post_on_main) without return types