


'''simple docstring'''





import fcntl
import os
import socket

import torch
import torch.distributed as dist


def        a__     (					*UpperCamelCase_						:      Union[str, Any]						):
   with open(_A,   '''r'''						) as fh:
      fcntl.flock(_A,   fcntl.LOCK_EX						)
      try:
         print(*_A						)
      finally:
         fcntl.flock(_A,   fcntl.LOCK_UN						)


__lowerCamelCase												=						int(os.environ['''LOCAL_RANK'''])
torch.cuda.set_device(local_rank)
__lowerCamelCase												=						torch.device('''cuda''', local_rank)
__lowerCamelCase												=						socket.gethostname()

__lowerCamelCase												=						F'''[{hostname}-{local_rank}]'''

try:
    # test distributed
    dist.init_process_group('''nccl''')
    dist.all_reduce(torch.ones(1).to(device), op=dist.ReduceOp.SUM)
    dist.barrier()

    # test cuda is available and can allocate memory
    torch.cuda.is_available()
    torch.ones(1).cuda(local_rank)

    # global rank
    __lowerCamelCase												=						dist.get_rank()
    __lowerCamelCase												=						dist.get_world_size()

    printflock(F'''{gpu} is OK (global rank: {rank}/{world_size})''')

    dist.barrier()
    if rank == 0:
        printflock(F'''pt={torch.__version__}, cuda={torch.version.cuda}, nccl={torch.cuda.nccl.version()}''')

except Exception:
    printflock(F'''{gpu} is broken''')
    raise











"""simple docstring"""







def      UpperCamelCase       ( _A  ,				_A )     ->       None:
				lowercase    :      List[Any]       = len(_A )
				print("""The following activities are selected:""" )

				# The first activity is always selected
				lowercase    :      Optional[int]       = 0
				print(_A  ,				end=""",""" )

				# Consider rest of the activities
				for j in range(_A ):
								# If this activity has start time greater than
								# or equal to the finish time of previously
								# selected activity, then select it
								if start[j] >= finish[i]:
												print(_A  ,				end=""",""" )
												lowercase    :      str       = j


if __name__ == "__main__":
				import doctest

				doctest.testmod()

				_lowerCAmelCase            =	[1, 3, 0, 5, 8, 5]
				_lowerCAmelCase            =	[2, 4, 6, 7, 9, 9]
				print_max_activities(start, finish)
