def run(n):
    ret = 0
    print("Running fibonacci...")
    with profile(["wall_clock"]):
        ret += fib(n)
        ret += fib(n % 5 + 1)
    print("Running inefficient...")
    with profile(["wall_clock"]):
        ret += inefficient(n)
    return ret
Пример #2
0
def run(n):
    ret = 0

    print("Running fibonacci...")
    obj = profile(["wall_clock"], flat=True)
    obj.start()
    ret += fib(n)
    ret += fib(n % 5 + 1)
    obj.stop()

    print("Running inefficient...")
    obj = profile(["wall_clock"], timeline=True)
    obj.start()
    ret += inefficient(n)
    obj.stop()

    return ret
def inefficient(n):
    with profile(["wall_clock"], key=f"inefficient({n})", timeline=True):
        a = 0
        for i in range(n):
            a += i
            for j in range(n):
                a += j
        arr = np.arange(a * n * n * n, dtype=np.double)
        return arr.sum()
Пример #4
0
    def test_flat(self):
        """flat
        """
        n = 25
        with marker(components=["wall_clock"], key=self.shortDescription()):
            with profile(components=["wall_clock"]):
                ret = fibonacci(n)
                print("\nfibonacci({}) = {}".format(n, ret))

        # inspect data
        data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        self.assertEqual(data[-1]["depth"], 0)
Пример #5
0
    def test_no_flat(self):
        """not_flat
        """
        os.environ["TIMEMORY_FLAT_PROFILE"] = "OFF"
        tim.settings.parse()
        n = 25
        with marker(components=["wall_clock"], key=self.shortDescription()):
            with profile(components=["wall_clock"]):
                ret = fibonacci(n)
                print("\nfibonacci({}) = {}".format(n, ret))

        # inspect data
        data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        self.assertEqual(data[-1]["depth"], n)
Пример #6
0
    def test_flat(self):
        """flat"""
        n = 10
        with marker(components=["wall_clock", "cpu_clock"],
                    key=self.shortDescription()):
            with profile(
                    components=["wall_clock", "cpu_clock"],
                    flat=True,
                    timeline=False,
            ):
                fibonacci(n)

        print("{}\n".format(
            json.dumps(tim.get()["timemory"]["wall_clock"], indent=4)))
        # inspect data
        data = tim.get()["timemory"]["wall_clock"]["ranks"][0]["graph"]
        self.assertEqual(data[-1]["depth"], 0)
Пример #7
0
    def test_timeline(self):
        """timeline
        """
        n = 5

        old_data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]

        with marker(components=["wall_clock"], key=self.shortDescription()):
            with profile(components=["wall_clock"]):
                ret = fibonacci(n)
                print("\nfibonacci({}) = {}".format(n, ret))

        # inspect data
        data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        #print("\n{}".format(json.dumps(data, indent=4, sort_keys=True)))

        # counts must be == 1
        for k in data:
            if k not in old_data:
                self.assertTrue(k["stats"]["count"] == 1)
Пример #8
0
    def test_no_timeline(self):
        """no_timeline
        """
        old_data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        os.environ["TIMEMORY_TIMELINE_PROFILE"] = "OFF"

        tim.settings.parse()
        n = 5
        with marker(components=["wall_clock"], key=self.shortDescription()):
            with profile(components=["wall_clock"]):
                ret = fibonacci(n)
                print("\nfibonacci({}) = {}".format(n, ret))

        # counts must be == 1
        data = tim.get()["timemory"]["ranks"][0]["value0"]["graph"]
        #print("\n{}".format(json.dumps(data, indent=4, sort_keys=True)))
        maxcnt = 1
        for k in data:
            if k not in old_data:
                self.assertTrue(k["stats"]["count"] >= 1)
                maxcnt = max(k["stats"]["count"], maxcnt)
        self.assertTrue(maxcnt > 1)
def fib(n):
    with profile(["wall_clock"], key=f"fib({n})", flat=True):
        return n if n < 2 else (fib(n - 1) + fib(n - 2))
Пример #10
0
        "-p",
        "--profile",
        default=["mpi", "openmp", "malloc"],
        choices=("mpi", "openmp", "malloc", "nccl"),
        type=str,
        help="Profiling library wrappers to activate",
        nargs="*",
    )

    args = parser.parse_args()
    timemory.enable_signal_detection()
    timemory.settings.width = 8
    timemory.settings.precision = 2
    timemory.settings.scientific = True
    timemory.settings.plot_output = True
    timemory.settings.dart_output = False
    timemory.timemory_init([__file__])

    @function_wrappers(*args.profile, nccl=False)
    def runner(nitr, nsize):
        run_mpi(nitr, nsize)

    runner(args.iterations, args.size)

    with profile(args.components):
        ans = main(args)

    print("Success! Answer = {}. Finalizing...".format(ans))
    timemory.finalize()
    print("Python Finished")