// File: /workspace/github_cpp_makefile_star2_O2/poseidon1214[P]logistic-regression-ftrl-mpi/src/main.cpp
// Function: main
int main(int argc,char* argv[]){  
    int rank, nproc;
    int namelen = 1024;
    char processor_name[namelen];
    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    MPI_Comm_size(MPI_COMM_WORLD,&nproc);
    MPI_Get_processor_name(processor_name,&namelen);
    std::cout<<"my host = "<<processor_name<<" my rank = "<<rank<<std::endl;
    
    int epochnum = atoi(argv[2]);
    int batchsize = atoi(argv[3]);
    float bias = atof(argv[4]);
    float alpha = atof(argv[5]);
    float beta = atof(argv[6]);
    float lambda1 = atof(argv[7]);
    float lambda2 = atof(argv[8]);

    char train_data_path[1024];
    snprintf(train_data_path, 1024, "%s-%05d", argv[9], rank);
    char test_data_path[1024];
    snprintf(test_data_path, 1024, "%s-%05d", argv[10], rank);

    Load_Data test_data(test_data_path);
    test_data.load_data_batch(nproc, rank);
    Predict predict(&test_data, nproc, rank);

    Load_Data train_data(train_data_path); 
    train_data.load_data_batch(nproc, rank);

    if(strcmp(argv[1], "ftrl") == 0){
        FTRL ftrl(&train_data, &predict, nproc, rank);
        ftrl.epochs = epochnum;
        ftrl.batch_size = batchsize;
        ftrl.bias = bias;
        ftrl.alpha = alpha;
        ftrl.beta = beta;
        ftrl.lambda1 = lambda1;
        ftrl.lambda2 = lambda2;
        ftrl.ftrl();
        for(int j = 0; j < train_data.glo_fea_dim; j++){
	        //if(ftrl.loc_w[j] != 0)std::cout<<"w["<< j << "]: "<<ftrl.loc_w[j]<<std::endl;
        }
        std::cout<<"rank "<<rank<<" train finished! "<<processor_name<<std::endl;
        predict.run(ftrl.loc_w);
    }

    MPI::Finalize();
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x12a8, %rsp           # imm = 0x12A8
movq %rsp, -0x68(%rbp)
leaq -0x78(%rbp), %rax
movl %edi, (%rax)
leaq -0x70(%rbp), %r13
movq %rsi, (%r13)
leaq -0x74(%rbp), %rbx
movl $0x400, (%rbx)          # imm = 0x400
movq %rax, %rdi
movq %r13, %rsi
callq 0x2250
movq 0x3b32(%rip), %r14      # 0x5fb0
leaq -0x2c(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x2240
leaq -0x30(%rbp), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x21e0
leaq -0xad0(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21c0
movq 0x3b1b(%rip), %rdi      # 0x5fd0
leaq 0x1b94(%rip), %rsi      # 0x4050
callq 0x21a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21a0
leaq 0x1b88(%rip), %rsi      # 0x405b
movq %rax, %rdi
callq 0x21a0
movl (%r15), %esi
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20f0
movq (%r13), %rbx
movq 0x10(%rbx), %rdi
callq 0x2280
movl %eax, -0x34(%rbp)
movq 0x18(%rbx), %rdi
callq 0x2280
movl %eax, %r14d
movq 0x20(%rbx), %rdi
callq 0x2210
movsd %xmm0, -0x60(%rbp)
movq 0x28(%rbx), %rdi
callq 0x2210
movsd %xmm0, -0x58(%rbp)
movq 0x30(%rbx), %rdi
callq 0x2210
movsd %xmm0, -0x50(%rbp)
movq 0x38(%rbx), %rdi
callq 0x2210
movsd %xmm0, -0x48(%rbp)
movq 0x40(%rbx), %rdi
callq 0x2210
movsd %xmm0, -0x40(%rbp)
movq 0x48(%rbx), %rcx
movl (%r15), %r8d
leaq 0x1b09(%rip), %rbx      # 0x4067
leaq -0xed0(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2290
movq (%r13), %rax
movq 0x50(%rax), %rcx
movl (%r15), %r8d
leaq -0x12d0(%rbp), %r13
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2290
leaq -0x6c8(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x275e
movl (%r12), %esi
movl (%r15), %edx
movq %rbx, %rdi
callq 0x288a
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
leaq -0xe0(%rbp), %r15
leaq -0x6c8(%rbp), %rsi
movq %r15, %rdi
callq 0x2aa4
leaq -0x418(%rbp), %rdi
leaq -0xed0(%rbp), %rsi
callq 0x275e
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
leaq -0x418(%rbp), %r12
movq %r12, %rdi
callq 0x288a
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x1a63(%rip), %rsi      # 0x406f
callq 0x2230
testl %eax, %eax
jne 0x26de
movl -0x30(%rbp), %eax
movl -0x2c(%rbp), %ecx
leaq -0x168(%rbp), %rdi
movq %r12, 0x40(%rdi)
movq %r15, 0x48(%rdi)
movl %eax, 0x80(%rdi)
movl %ecx, 0x84(%rdi)
callq 0x34e0
cvtsd2ss -0x60(%rbp), %xmm0
cvtsd2ss -0x58(%rbp), %xmm1
cvtsd2ss -0x50(%rbp), %xmm2
cvtsd2ss -0x48(%rbp), %xmm3
cvtsd2ss -0x40(%rbp), %xmm4
leaq -0x168(%rbp), %rdi
movl -0x34(%rbp), %eax
movl %eax, 0x8(%rdi)
movl %r14d, 0xc(%rdi)
movss %xmm0, 0x10(%rdi)
movss %xmm1, 0x14(%rdi)
movss %xmm2, 0x18(%rdi)
movss %xmm3, 0x1c(%rdi)
movss %xmm4, 0x20(%rdi)
callq 0x2b22
movq 0x3942(%rip), %rdi      # 0x5fd0
leaq 0x19df(%rip), %rsi      # 0x4074
callq 0x21a0
movl -0x2c(%rbp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x19ce(%rip), %rsi      # 0x407a
movq %rax, %rdi
callq 0x21a0
leaq -0xad0(%rbp), %rsi
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20f0
movq -0x168(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x2d3c
callq 0x2140
leaq -0x418(%rbp), %rdi
callq 0x2d92
leaq -0xd8(%rbp), %rdi
callq 0x34cc
leaq -0x6c8(%rbp), %rdi
callq 0x2d92
movq -0x68(%rbp), %rsp
xorl %eax, %eax
addq $0x12a8, %rsp           # imm = 0x12A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x272f
movq %rax, %rbx
jmp 0x273e
jmp 0x2728
movq %rax, %rbx
jmp 0x274a
jmp 0x272f
movq %rax, %rbx
leaq -0x418(%rbp), %rdi
callq 0x2d92
leaq -0xd8(%rbp), %rdi
callq 0x34cc
leaq -0x6c8(%rbp), %rdi
callq 0x2d92
movq %rbx, %rdi
callq 0x22e0