def dist_sampler_init_process(rank, world_size, windows_ds):
    """Initialize the process group for multi-CPU training."""
    dist.init_process_group(
        backend="gloo",
        init_method="tcp://127.0.0.1:29500",  # Localhost for single machine
        rank=rank,
        world_size=world_size
    )
    print(f"Process {rank} initialized")

    sampler = DistributedRecordingSampler(windows_ds.get_metadata(), random_state=87)
    if world_size == 1:
        sampler_single = RecordingSampler(windows_ds.get_metadata(), random_state=87)
        assert sampler.n_recordings == windows_ds.description.shape[0] == sampler_single.n_recordings
    assert len(sampler.dataset) == windows_ds.description.shape[0]
    assert sampler.n_recordings <= windows_ds.description.shape[0] // world_size
    print(f"Rank {rank} has {sampler.n_recordings} datasets after splitting")

    # Test info attribute
    assert isinstance(sampler.info, pd.DataFrame)
    assert isinstance(sampler.info.index, pd.MultiIndex)
    inds = np.concatenate(sampler.info["index"].values)
    assert len(inds) == len(windows_ds)
    assert len(inds) == len(set(inds))

    # Test methods
    for _ in range(100):
        rec_ind = sampler.sample_recording()
        assert rec_ind in range(windows_ds.description.shape[0])

        win_ind, rec_ind2 = sampler.sample_window(rec_ind=rec_ind)
        dataset_ind = find_dataset_ind(windows_ds, win_ind)
        assert rec_ind2 == rec_ind == dataset_ind

        X, y, z = windows_ds[win_ind]

        win_ind, rec_ind = sampler.sample_window(rec_ind=None)
        assert rec_ind in range(windows_ds.description.shape[0])

    # Cleanup
    dist.destroy_process_group()
Initialize the process group for multi-CPU training.
test/unit_tests/samplers/test_samplers.py