



'''simple docstring'''


import fcntl
import os
import socket

import torch
import torch.distributed as dist







def      SCREAMING_SNAKE_CASE				(				*lowercase_    :      Any						):
      with open(UpperCamelCase__ ,  """r"""						) as fh:
            fcntl.flock(UpperCamelCase__ ,  fcntl.LOCK_EX						)
            try:
                  print(*UpperCamelCase__						)
            finally:
                  fcntl.flock(UpperCamelCase__ ,  fcntl.LOCK_UN						)


lowercase_      :				Union[str, Any]   					=    int(os.environ['''LOCAL_RANK'''])
torch.cuda.set_device(local_rank)
lowercase_      :				Tuple   					=    torch.device('''cuda''', local_rank)
lowercase_      :				int   					=    socket.gethostname()

lowercase_      :				Tuple   					=    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
      lowercase_      :				Union[str, Any]   					=    dist.get_rank()
      lowercase_      :				str   					=    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'''


import os







def      SCREAMING_SNAKE_CASE				(				):
						lowercase        =							os.path.join(os.path.dirname(lowercase_						) ,  """num.txt"""						)
						with open(lowercase_						) as file_hand:
												return str(sum(int(lowercase_						) for line in file_hand						)						)[:10]


if __name__ == "__main__":
						print(solution())


