// File: btbujiangjun[P]abcdl/src/algebra/MatrixHelper.cpp
// Function: abcdl::algebra::MatrixHelper<int>::expand(abcdl::algebra::Matrix<int>&, abcdl::algebra::Matrix<int> const&, unsigned long, unsigned long)
void MatrixHelper<T>::expand(Matrix<T>& result,
                             const Matrix<T>& mat,
                             const size_t row_dim,
                             const size_t col_dim){

    CHECK(row_dim * col_dim > 1);
   
    size_t col_a = mat.cols();
    size_t row   = mat.rows() * row_dim;
    size_t col   = col_a * col_dim;
    size_t size  = row * col;

    size_t num_thread = _po.get_num_thread(size, _po.get_block_size(size));
    size_t block_size = row / num_thread;
    if(row % num_thread != 0){
        block_size += 1;
    }

    std::vector<std::thread> threads(num_thread);
    T* data = mat.data();
    T* new_data = new T[size];
    memset(new_data, 0, sizeof(T) * size);

    for(size_t i = 0; i != num_thread; i++){
        threads[i] = std::thread(
            [&data, &new_data,&col, &col_a, &row_dim, &col_dim](size_t start_idx, size_t end_idx){
				for(size_t ti = start_idx; ti < end_idx; ti++){
					for(size_t tj = 0; tj != col; tj++){
                        new_data[ti * col + tj] = data[ti / row_dim * col_a + tj / col_dim];
					}
				}
            }, i * block_size , std::min(row, (i + 1) * block_size)
        );
    }

    for(auto& thread : threads){
        thread.join();
    }

    result.set_shallow_data(new_data, row, col);
}

// Assembly:
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdi, 0x2d0(%rsp)
movq %rsi, 0x2c8(%rsp)
movq %rdx, 0x2c0(%rsp)
movq %rcx, 0x2b8(%rsp)
movq %r8, 0x2b0(%rsp)
movq 0x2d0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x2b8(%rsp), %rax
imulq 0x2b0(%rsp), %rax
cmpq $0x1, %rax
seta %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x68e7c
jmp 0x68ee7
leaq 0x297a5(%rip), %rsi     # 0x92628
leaq 0x128(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movl $0x101, %edx            # imm = 0x101
movl $0x3, %ecx
callq 0x89860
movq 0x38(%rsp), %rdi
leaq 0x297b7(%rip), %rsi     # 0x92662
callq 0x692c0
jmp 0x68eb2
leaq 0x128(%rsp), %rdi
callq 0x89c20
jmp 0x68ee7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x89c20
jmp 0x692ae
movq 0x2c0(%rsp), %rdi
callq 0x31a20
movq %rax, 0x110(%rsp)
movq 0x2c0(%rsp), %rdi
callq 0x31a10
movq 0x40(%rsp), %rdi
imulq 0x2b8(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x110(%rsp), %rax
imulq 0x2b0(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x108(%rsp), %rax
imulq 0x100(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0xf8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xf8(%rsp), %rsi
callq 0xa8e0
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rax, %rdx
callq 0xa970
movq %rax, 0xf0(%rsp)
movq 0x108(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0xf0(%rsp)
movq %rax, 0xe8(%rsp)
movq 0x108(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0xf0(%rsp)
cmpq $0x0, %rdx
je 0x68fcf
movq 0xe8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xe8(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xcf(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0xa9f0
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
leaq 0xd0(%rsp), %rdi
callq 0xaa00
jmp 0x69007
leaq 0xcf(%rsp), %rdi
callq 0xaa80
movq 0x2c0(%rsp), %rdi
callq 0x31a30
movq %rax, 0x18(%rsp)
jmp 0x69028
movq 0x18(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xf8(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x9030
movq %rax, 0x10(%rsp)
jmp 0x6905f
movq 0x10(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
movq 0xf8(%rsp), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x9210
movq $0x0, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
cmpq 0xf0(%rsp), %rax
je 0x69209
leaq 0xc0(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0xb8(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x100(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x110(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x2b8(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x2b0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0xb0(%rsp), %rax
movq 0xe8(%rsp), %rcx
imulq %rcx, %rax
movq %rax, 0x70(%rsp)
movq 0xb0(%rsp), %rax
incq %rax
movq 0xe8(%rsp), %rcx
imulq %rcx, %rax
movq %rax, 0x68(%rsp)
leaq 0x108(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0xaa90
movq %rax, 0x8(%rsp)
jmp 0x69154
movq 0x8(%rsp), %rcx
leaq 0xa8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x692f0
jmp 0x69172
movq 0xb0(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
callq 0xaba0
movq %rax, %rdi
leaq 0xa8(%rsp), %rsi
callq 0xabc0
leaq 0xa8(%rsp), %rdi
callq 0xac00
movq 0xb0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xb0(%rsp)
jmp 0x69093
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0xcf(%rsp), %rdi
callq 0xaa80
jmp 0x692ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x120(%rsp)
movl %eax, 0x11c(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xacf0
jmp 0x692ae
leaq 0xd0(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
callq 0xac20
movq %rax, 0x58(%rsp)
movq 0x60(%rsp), %rdi
callq 0xac50
movq %rax, 0x50(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xac80
testb $0x1, %al
jne 0x69249
jmp 0x69272
leaq 0x58(%rsp), %rdi
callq 0xacc0
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
callq 0x96c0
jmp 0x69264
jmp 0x69266
leaq 0x58(%rsp), %rdi
callq 0xacd0
jmp 0x69234
movq 0x2c8(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movq 0x108(%rsp), %rdx
movq 0x100(%rsp), %rcx
callq 0x31fe0
jmp 0x69299
leaq 0xd0(%rsp), %rdi
callq 0xacf0
addq $0x2d8, %rsp            # imm = 0x2D8
retq
movq 0x120(%rsp), %rdi
callq 0x9700
nopl (%rax,%rax)