// File: /workspace/github_cpp_makefile_star2_O1/Pyboon[P]sage/test_mpi_sage.cpp
// Function: main
int main(int argc, char** argv) {
    vector<int> spots = {11, 14, 17};
    vector<pair<int, int> > file_nums = ParseFileNum(spots);
    int file_size = file_nums.size();
    // config init
    string home_path = getenv("HOME");
    string path_cir = home_path + "/code/sage/data/low_fre_MIMO/cut_cir_bin/";
    string path_antenna = home_path + "/code/sage/data/antenna_bin/";
    string path_result  = home_path + "/code/sage/data/result/";
    IsiSage test_Sage(path_cir, path_antenna, path_result, 20, 50); 

    double start_time, end_time;
    MPI_Init(&argc, &argv);
    start_time = MPI_Wtime();

    // Get the number of processes
    int comm_size;
    MPI_Comm_size(MPI_COMM_WORLD, &comm_size);

    // Get the rank of the process
    int rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    // Get the name of the processor
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    int name_len;
    MPI_Get_processor_name(processor_name, &name_len);

    int local_size = floor(file_size / (double)comm_size);
    int left = file_size - local_size*comm_size;
    int start = 0;
    int end = 0;
    if(rank<left){
        start = (local_size+1) * rank;
        end = (local_size+1) * (rank+1);
    } else {
        start = (local_size+1)*left + (rank-left)*local_size;
        end = (local_size+1)*left + (rank-left+1)*local_size;
    }
    int spot = 0;
    int cycle_idx = 0;
    int count = 0;
    for(int i = start; i < end; ++i){
        spot = file_nums[i].first;
        cycle_idx = file_nums[i].second;
        printf("running spot_%d_cyc_%d from rank %d \n", spot, cycle_idx, rank);
        test_Sage.ConfigInit(spot, cycle_idx);
        test_Sage.run();
        ++count;
    }
    end_time = MPI_Wtime();
    printf("[%s:rank-%d]Calculation Finished, total cycle:%d, elapsed time:%lfs \n", 
    processor_name, rank, count, end_time - start_time);
    
    // Finalize the MPI environment. No more MPI calls can be made after this
    MPI_Finalize();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4c8, %rsp            # imm = 0x4C8
movl %edi, 0x1c(%rsp)
movq %rsi, 0xd8(%rsp)
movabsq $0xe0000000b, %rax      # imm = 0xE0000000B
leaq 0x260(%rsp), %rsi
movq %rax, (%rsi)
movl $0x11, 0x8(%rsi)
leaq 0x148(%rsp), %rbx
leaq 0x160(%rsp), %rcx
movl $0x3, %edx
movq %rbx, %rdi
callq 0x3dbe
leaq 0xc0(%rsp), %rdi
movq %rbx, %rsi
callq 0x3e04
leaq 0xa0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x369c
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x37fe
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0xa8(%rsp), %rbx
subq 0xa0(%rsp), %rbx
leaq 0x1880b(%rip), %rdi     # 0x1c020
callq 0x3330
leaq 0x80(%rsp), %rdi
leaq 0x260(%rsp), %rdx
movq %rax, %rsi
callq 0x3e84
leaq 0x70(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0x434a
leaq 0x187c6(%rip), %rsi     # 0x1c025
leaq 0x60(%rsp), %rdi
callq 0x34b0
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x434a
leaq 0x187b9(%rip), %rsi     # 0x1c04f
leaq 0x40(%rsp), %rdi
callq 0x34b0
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0x434a
leaq 0x1879f(%rip), %rsi     # 0x1c06c
leaq 0x20(%rsp), %rdi
callq 0x34b0
leaq 0x138(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
leaq 0x128(%rsp), %rdi
callq 0x434a
leaq 0x118(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
addq %rsi, %rdx
leaq 0x108(%rsp), %rdi
callq 0x434a
leaq 0xf8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0x434a
leaq 0x260(%rsp), %rdi
leaq 0x128(%rsp), %rsi
leaq 0x108(%rsp), %rdx
leaq 0xe8(%rsp), %rcx
movl $0x14, %r8d
movl $0x32, %r9d
callq 0x3ec2
movq 0xe8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3998
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x108(%rsp), %rdi
cmpq %r15, %rdi
je 0x39b5
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x128(%rsp), %rdi
cmpq %r14, %rdi
je 0x39d2
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x1c(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x3390
callq 0x3350
movsd %xmm0, 0xb8(%rsp)
movq 0x2b5a7(%rip), %rdi     # 0x2efa0
leaq 0x18(%rsp), %rsi
callq 0x3310
movq 0x2b596(%rip), %rdi     # 0x2efa0
leaq 0x10(%rsp), %rsi
callq 0x3380
leaq 0x160(%rsp), %rdi
leaq 0xe4(%rsp), %rsi
callq 0x32d0
shrq $0x3, %rbx
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movl 0x18(%rsp), %ebp
cvtsi2sd %ebp, %xmm1
divsd %xmm1, %xmm0
callq 0x3430
cvttsd2si %xmm0, %ecx
imull %ecx, %ebp
subl %ebp, %ebx
movl 0x10(%rsp), %edi
leal 0x1(%rcx), %esi
movl %edi, %edx
subl %ebx, %edx
jge 0x3a67
movl %esi, %eax
imull %edi, %eax
incl %edi
imull %esi, %edi
jmp 0x3a7a
imull %esi, %ebx
movl %edx, %eax
imull %ecx, %eax
addl %ebx, %eax
incl %edx
imull %ecx, %edx
addl %ebx, %edx
movl %edx, %edi
xorl %ebx, %ebx
subl %eax, %edi
jle 0x3b17
movslq %eax, %r12
leaq 0x185f6(%rip), %rbx     # 0x1c084
leaq 0x260(%rsp), %r14
movl %edi, 0x14(%rsp)
movl %edi, %r13d
movq 0xa0(%rsp), %rax
movl (%rax,%r12,8), %ebp
movl 0x4(%rax,%r12,8), %r15d
movl 0x10(%rsp), %ecx
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x3040
movl $0x4, (%rsp)
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl $0x20, %ecx
movl $0x38, %r8d
movl $0x7f, %r9d
movsd 0x1851f(%rip), %xmm0    # 0x1c008
movsd 0x1851f(%rip), %xmm1    # 0x1c010
movsd 0x1851f(%rip), %xmm2    # 0x1c018
callq 0x6a1c
movq %r14, %rdi
callq 0xeb20
incq %r12
decl %r13d
jne 0x3a9d
movl 0x14(%rsp), %ebx
leaq 0x70(%rsp), %r13
callq 0x3350
movl 0x10(%rsp), %edx
subsd 0xb8(%rsp), %xmm0
leaq 0x1857a(%rip), %rdi     # 0x1c0aa
leaq 0x160(%rsp), %rsi
movl %ebx, %ecx
movb $0x1, %al
callq 0x3040
callq 0x31f0
leaq 0x260(%rsp), %rdi
callq 0x4020
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x3b6f
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x3b8b
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x3ba2
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3bc3
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x3be0
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x148(%rsp), %rdi
testq %rdi, %rdi
je 0x3bfd
movq 0x158(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
xorl %eax, %eax
addq $0x4c8, %rsp            # imm = 0x4C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3cf6
jmp 0x3cf6
jmp 0x3cf6
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3c45
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x3c45
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r15, %rdi
je 0x3c67
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x3c67
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r14, %rdi
je 0x3d06
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x3d06
jmp 0x3c8c
movq %rax, %rbx
jmp 0x3d06
jmp 0x3c93
movq %rax, %rbx
jmp 0x3d22
movq %rax, %rbx
jmp 0x3d3e
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
jne 0x3d4d
jmp 0x3d5a
movq %rax, %rbx
jmp 0x3d5a
movq %rax, %rbx
jmp 0x3d7b
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x3d98
movq 0xd0(%rsp), %rsi
jmp 0x3d90
movq %rax, %rbx
jmp 0x3d98
jmp 0x3cf6
jmp 0x3cf6
movq %rax, %rbx
leaq 0x260(%rsp), %rdi
callq 0x4020
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x3d22
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x3d3e
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x3d5a
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3d7b
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x3d98
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq 0x148(%rsp), %rdi
testq %rdi, %rdi
je 0x3db5
movq 0x158(%rsp), %rsi
subq %rdi, %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x3460
nop