include: macros/bench_frame.def
include: macros/mtest.def

/* A simpler version of p2p_bw. Instead of warmup and iterate over a
 * range of message sizes, just send/recv one message of size.
 */

macros:
    MEM_TYPES: sendrecv

subcode: _autoload
    $register_name(src) int
    $register_name(dst) int
    $register_name(buf) void *
    $register_name(size) int
    $define TAG 0

subcode: report_header
    printf("%12s %10s %12s\n", "msgsize", "latency(sec)", "bandwidth(GB/s)");

subcode: report_one
    tf_bw = size / tf_latency / 1e9
    printf("%12d %10.3f %12.3f\n", size, tf_latency, tf_bw);

page: p2p_one, bench_frame
    MAX_BUFSIZE: 1000000000
    data: buf, size, MPI_CHAR

    size = MAX_BUFSIZE

    /* Repeat a few times to see variations or the need to warm up */
    $for iter=0:5
        $if grank == gsrc
            tf_start = MPI_Wtime()
            $call @send_side
            $call recv_sync, gdst
            tf_latency = MPI_Wtime() - tf_start
            $call report_one
        $elif grank == gdst
            $call @recv_side
            $call send_sync, gsrc

    subcode: send_side
        MPI_Send($(data), gdst, TAG, comm)

    subcode: recv_side
        MPI_Recv($(data), gsrc, TAG, comm, MPI_STATUS_IGNORE)

    subcode: send_sync(rank)
        MPI_Send(NULL, 0, MPI_DATATYPE_NULL, $(rank), TAG, comm)

    subcode: recv_sync(rank)
        MPI_Recv(NULL, 0, MPI_DATATYPE_NULL, $(rank), TAG, comm, MPI_STATUS_IGNORE)
