xref: /aosp_15_r20/external/pytorch/test/distributed/elastic/multiprocessing/bin/echo3.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1#!/usr/bin/env python3
2
3# Copyright (c) Facebook, Inc. and its affiliates.
4# All rights reserved.
5#
6# This source code is licensed under the BSD-style license found in the
7# LICENSE file in the root directory of this source tree.
8
9import argparse
10import ctypes
11import os
12
13
14if __name__ == "__main__":
15    parser = argparse.ArgumentParser(
16        description="test binary, triggers a segfault (SIGSEGV)"
17    )
18    parser.add_argument("--segfault", type=bool, default=False)
19    parser.add_argument("msg", type=str)
20    args = parser.parse_args()
21
22    rank = int(os.environ["RANK"])
23
24    if args.segfault:
25        ctypes.string_at(0)
26    else:
27        print(f"{args.msg} from {rank}")
28