// File: 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
subq $0xf10, %rsp            # imm = 0xF10
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x400, -0x1c(%rbp)     # imm = 0x400
movl -0x1c(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x28(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xee8(%rbp)
movq %rcx, %rsp
movq %rax, -0x30(%rbp)
leaq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x88e0
movq 0x1217b(%rip), %rdi     # 0x1afa8
movq %rdi, -0xef0(%rbp)
leaq -0x14(%rbp), %rsi
callq 0x88d0
movq -0xef0(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x86f0
movq -0xee8(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x86d0
movq 0x1216c(%rip), %rdi     # 0x1afd0
leaq 0xa1d5(%rip), %rsi      # 0x13040
callq 0x85e0
movq -0xee8(%rbp), %rsi
movq %rax, %rdi
callq 0x85e0
movq %rax, %rdi
leaq 0xa1c2(%rip), %rsi      # 0x1304b
callq 0x85e0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x8b00
movq %rax, %rdi
movq 0x120f5(%rip), %rsi     # 0x1af98
callq 0x8610
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x89a0
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x89a0
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x8770
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x8770
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x8770
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x8770
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x8770
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rcx
movl -0x14(%rbp), %r8d
leaq 0xa10e(%rip), %rdx      # 0x13057
movq %rdx, -0xed8(%rbp)
xorl %eax, %eax
movb %al, -0xec9(%rbp)
leaq -0x450(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rsi, -0xee0(%rbp)
callq 0x89f0
movq -0xee0(%rbp), %rsi
movq -0xed8(%rbp), %rdx
movb -0xec9(%rbp), %al
movq -0x10(%rbp), %rcx
movq 0x50(%rcx), %rcx
movl -0x14(%rbp), %r8d
leaq -0x850(%rbp), %rdi
movq %rdi, -0xec8(%rbp)
callq 0x89f0
movq -0xec8(%rbp), %rsi
leaq -0xb00(%rbp), %rdi
movq %rdi, -0xec0(%rbp)
callq 0x9910
movq -0xec0(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x9a90
jmp 0x8fd1
movl -0x18(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq -0xb78(%rbp), %rdi
leaq -0xb00(%rbp), %rsi
callq 0x9d40
jmp 0x8fec
leaq -0xe28(%rbp), %rdi
leaq -0x450(%rbp), %rsi
callq 0x9910
jmp 0x9001
movl -0x18(%rbp), %esi
movl -0x14(%rbp), %edx
leaq -0xe28(%rbp), %rdi
callq 0x9a90
jmp 0x9015
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xa03b(%rip), %rsi      # 0x1305f
callq 0x88a0
cmpl $0x0, %eax
jne 0x91ed
movl -0x18(%rbp), %ecx
movl -0x14(%rbp), %r8d
leaq -0xeb0(%rbp), %rdi
leaq -0xe28(%rbp), %rsi
leaq -0xb78(%rbp), %rdx
callq 0x9e80
jmp 0x9055
movl -0x34(%rbp), %eax
movl %eax, -0xea8(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0xea4(%rbp)
movss -0x3c(%rbp), %xmm0
movss %xmm0, -0xea0(%rbp)
movss -0x40(%rbp), %xmm0
movss %xmm0, -0xe9c(%rbp)
movss -0x44(%rbp), %xmm0
movss %xmm0, -0xe98(%rbp)
movss -0x48(%rbp), %xmm0
movss %xmm0, -0xe94(%rbp)
movss -0x4c(%rbp), %xmm0
movss %xmm0, -0xe90(%rbp)
leaq -0xeb0(%rbp), %rdi
callq 0x9ed0
jmp 0x90b6
movl $0x0, -0xeb4(%rbp)
movslq -0xeb4(%rbp), %rax
cmpq -0xb88(%rbp), %rax
jge 0x914b
jmp 0x90d2
movl -0xeb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xeb4(%rbp)
jmp 0x90c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb08(%rbp)
movl %eax, -0xb0c(%rbp)
jmp 0x9246
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb08(%rbp)
movl %eax, -0xb0c(%rbp)
jmp 0x923a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb08(%rbp)
movl %eax, -0xb0c(%rbp)
jmp 0x922e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb08(%rbp)
movl %eax, -0xb0c(%rbp)
leaq -0xeb0(%rbp), %rdi
callq 0xa250
jmp 0x922e
movq 0x11e7e(%rip), %rdi     # 0x1afd0
leaq 0x9f0b(%rip), %rsi      # 0x13064
callq 0x85e0
movq %rax, -0xef8(%rbp)
jmp 0x9167
movq -0xef8(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x8b00
movq %rax, -0xf00(%rbp)
jmp 0x917f
movq -0xf00(%rbp), %rdi
leaq 0x9edd(%rip), %rsi      # 0x1306a
callq 0x85e0
movq %rax, -0xf08(%rbp)
jmp 0x919b
movq -0xee8(%rbp), %rsi
movq -0xf08(%rbp), %rdi
callq 0x85e0
movq %rax, -0xf10(%rbp)
jmp 0x91b7
movq -0xf10(%rbp), %rdi
movq 0x11dd3(%rip), %rsi     # 0x1af98
callq 0x8610
jmp 0x91cc
movq -0xeb0(%rbp), %rsi
leaq -0xb78(%rbp), %rdi
callq 0xa1c0
jmp 0x91e1
leaq -0xeb0(%rbp), %rdi
callq 0xa250
callq 0xa260
jmp 0x91f4
movl $0x0, -0x4(%rbp)
leaq -0xe28(%rbp), %rdi
callq 0xa270
leaq -0xb78(%rbp), %rdi
callq 0xa340
leaq -0xb00(%rbp), %rdi
callq 0xa270
movq -0x28(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
leaq -0xe28(%rbp), %rdi
callq 0xa270
leaq -0xb78(%rbp), %rdi
callq 0xa340
leaq -0xb00(%rbp), %rdi
callq 0xa270
movq -0xb08(%rbp), %rdi
callq 0x8b40
nop