// File: /workspace/github_cpp_makefile_star2_O1/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 0x2290
movq 0x4a02(%rip), %r14      # 0x6fb0
leaq -0x2c(%rbp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x2280
leaq -0x30(%rbp), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x2220
leaq -0xad0(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21f0
movq 0x49eb(%rip), %rbx      # 0x6fd0
leaq 0x2a64(%rip), %rsi      # 0x5050
movl $0xa, %edx
movq %rbx, %rdi
callq 0x2210
movq %r14, %rdi
callq 0x20e0
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2210
leaq 0x2a45(%rip), %rsi      # 0x505b
movl $0xb, %edx
movq %rbx, %rdi
callq 0x2210
movl (%r15), %esi
movq %rbx, %rdi
callq 0x2310
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq (%r13), %rbx
movq 0x10(%rbx), %rdi
callq 0x22c0
movl %eax, -0x34(%rbp)
movq 0x18(%rbx), %rdi
callq 0x22c0
movl %eax, %r14d
movq 0x20(%rbx), %rdi
callq 0x2250
movsd %xmm0, -0x60(%rbp)
movq 0x28(%rbx), %rdi
callq 0x2250
movsd %xmm0, -0x58(%rbp)
movq 0x30(%rbx), %rdi
callq 0x2250
movsd %xmm0, -0x50(%rbp)
movq 0x38(%rbx), %rdi
callq 0x2250
movsd %xmm0, -0x48(%rbp)
movq 0x40(%rbx), %rdi
callq 0x2250
movsd %xmm0, -0x40(%rbp)
movq 0x48(%rbx), %rcx
movl (%r15), %r8d
leaq 0x299f(%rip), %rbx      # 0x5067
leaq -0xed0(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
xorl %eax, %eax
callq 0x22d0
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 0x22d0
leaq -0x6c8(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2910
movl (%r12), %esi
movl (%r15), %edx
movq %rbx, %rdi
callq 0x2aa0
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
leaq -0xe0(%rbp), %r15
leaq -0x6c8(%rbp), %rsi
movq %r15, %rdi
callq 0x2d6e
leaq -0x418(%rbp), %rdi
leaq -0xed0(%rbp), %rsi
callq 0x2910
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
leaq -0x418(%rbp), %r12
movq %r12, %rdi
callq 0x2aa0
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x28f9(%rip), %rsi      # 0x506f
callq 0x2270
testl %eax, %eax
jne 0x2886
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 0x378a
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 0x2df8
movq 0x47d8(%rip), %rdi      # 0x6fd0
leaq 0x2875(%rip), %rsi      # 0x5074
movl $0x5, %edx
callq 0x2210
movl -0x2c(%rbp), %esi
movq 0x47bd(%rip), %rdi      # 0x6fd0
callq 0x2310
movq %rax, %rbx
leaq 0x2858(%rip), %rsi      # 0x507a
movl $0x11, %edx
movq %rax, %rdi
callq 0x2210
leaq -0xad0(%rbp), %r14
movq %r14, %rdi
callq 0x20e0
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2210
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2140
movq -0x168(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x308c
callq 0x2160
leaq -0x418(%rbp), %rdi
callq 0x30e6
movq -0xd8(%rbp), %rdi
testq %rdi, %rdi
je 0x28a8
callq 0x21a0
leaq -0x6c8(%rbp), %rdi
callq 0x30e6
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 0x28dc
movq %rax, %rbx
jmp 0x28eb
jmp 0x28d5
movq %rax, %rbx
jmp 0x28fc
jmp 0x28dc
movq %rax, %rbx
leaq -0x418(%rbp), %rdi
callq 0x30e6
movq -0xd8(%rbp), %rdi
testq %rdi, %rdi
je 0x28fc
callq 0x21a0
leaq -0x6c8(%rbp), %rdi
callq 0x30e6
movq %rbx, %rdi
callq 0x2330