// File: /workspace/github_c_makefile_star2_O2/baileywjohnson[P]mpi-matrix-mult/MyMPI.c
// Function: print_checkerboard_matrix
void print_checkerboard_matrix (
   void       **a,            /* IN -2D matrix */
   MPI_Datatype dtype,        /* IN -Matrix element type */
   int          m,            /* IN -Matrix rows */
   int          n,            /* IN -Matrix columns */
   MPI_Comm     grid_comm)    /* IN - Communicator */
{
   void      *buffer;         /* Room to hold 1 matrix row */
   int        coords[2];      /* Grid coords of process
                                 sending elements */
   int        datum_size;     /* Bytes per matrix element */
   int        els;            /* Elements received */
   int        grid_coords[2]; /* Coords of this process */
   int        grid_id;        /* Process rank in grid */
   int        grid_period[2]; /* Wraparound */
   int        grid_size[2];   /* Dims of process grid */
   int        i, j, k;
   void      *laddr;          /* Where to put subrow */
   int        local_cols;     /* Matrix cols on this proc */
   int        p;              /* Number of processes */
   int        src;            /* ID of proc with subrow */
   MPI_Status status;         /* Result of receive */

   MPI_Comm_rank (grid_comm, &grid_id);
   MPI_Comm_size (grid_comm, &p);
   datum_size = get_size (dtype);

   MPI_Cart_get (grid_comm, 2, grid_size, grid_period,
      grid_coords);
   local_cols = BLOCK_SIZE(grid_coords[1],grid_size[1],n);

   if (!grid_id)
      buffer = my_malloc (grid_id, n*datum_size);

   /* For each row of the process grid */
   for (i = 0; i < grid_size[0]; i++) {
      coords[0] = i;

      /* For each matrix row controlled by the process row */
      for (j = 0; j < BLOCK_SIZE(i,grid_size[0],m); j++) {

         /* Collect the matrix row on grid process 0 and
            print it */
         if (!grid_id) {
            for (k = 0; k < grid_size[1]; k++) {
               coords[1] = k;
               MPI_Cart_rank (grid_comm, coords, &src);
               els = BLOCK_SIZE(k,grid_size[1],n);
               laddr = buffer +
                  BLOCK_LOW(k,grid_size[1],n) * datum_size;
               if (src == 0) {
                  memcpy (laddr, a[j], els * datum_size);
               } else {
                  MPI_Recv(laddr, els, dtype, src, 0,
                     grid_comm, &status);
               }
            }
            print_subvector (buffer, dtype, n);
            putchar ('\n');
         } else if (grid_coords[0] == i) {
            MPI_Send (a[j], local_cols, dtype, 0, 0,
               grid_comm);
         }
      }
   }
   if (!grid_id) {
      free (buffer);
      putchar ('\n');
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r8, %rbx
movl %ecx, %r14d
movl %edx, 0x38(%rsp)
movq %rsi, %r12
movq %rdi, 0x50(%rsp)
leaq 0x14(%rsp), %rsi
movq %r8, %rdi
callq 0x1170
leaq 0x6c(%rsp), %rsi
movq %rbx, %rdi
callq 0x1100
movq %r12, 0x20(%rsp)
movq %r12, %rdi
callq 0x1b5c
movl %eax, %r13d
pushq $0x2
popq %rsi
leaq 0x18(%rsp), %r12
leaq 0x78(%rsp), %rcx
leaq 0x70(%rsp), %rbp
movq %rbx, %rdi
movq %r12, %rdx
movq %rbp, %r8
callq 0x1110
movl 0x4(%rbp), %ecx
leal 0x1(%rcx), %eax
imull %r14d, %eax
movl 0x4(%r12), %esi
cltd
idivl %esi
movl %eax, %r15d
movq %r14, 0x30(%rsp)
imull %r14d, %ecx
movl %ecx, %eax
cltd
idivl %esi
movl %eax, %r12d
leaq 0x14(%rsp), %rax
cmpl $0x0, (%rax)
jne 0x2bcd
movl %r13d, %esi
imull 0x30(%rsp), %esi
xorl %edi, %edi
callq 0x1bc5
movq %rax, 0x28(%rsp)
subl %r12d, %r15d
xorl %r14d, %r14d
movl 0x18(%rsp), %esi
movl %r15d, 0x40(%rsp)
cmpl %esi, %r14d
jge 0x2d47
movl %r14d, 0x58(%rsp)
leal 0x1(%r14), %r15d
movl %r15d, 0x3c(%rsp)
movl 0x38(%rsp), %eax
imull %eax, %r15d
movl %r14d, %ecx
imull %eax, %ecx
movl %ecx, 0x48(%rsp)
xorl %edi, %edi
movq %r14, 0x60(%rsp)
movl %r15d, 0x44(%rsp)
movl %r15d, %eax
cltd
idivl %esi
movl %eax, %ecx
movl 0x48(%rsp), %eax
cltd
idivl %esi
subl %eax, %ecx
movslq %ecx, %rax
cmpq %rax, %rdi
jge 0x2d3b
movq %rdi, %rbp
cmpl $0x0, 0x14(%rsp)
je 0x2c6a
cmpl %r14d, 0x70(%rsp)
movq %rbp, %rdi
jne 0x2d2f
movq 0x50(%rsp), %rax
movq (%rax,%rdi,8), %rdi
movl 0x40(%rsp), %esi
movq 0x20(%rsp), %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x1040
jmp 0x2d2c
xorl %r15d, %r15d
xorl %r14d, %r14d
cmpl 0x1c(%rsp), %r14d
jge 0x2d06
movl %r14d, 0x5c(%rsp)
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
leaq 0x4c(%rsp), %rdx
callq 0x11d0
movq 0x30(%rsp), %rax
leal (%rax,%r15), %r12d
movl 0x1c(%rsp), %ecx
movl %r12d, %eax
cltd
idivl %ecx
movl %eax, %r8d
movl %r15d, %eax
cltd
idivl %ecx
subl %eax, %r8d
imull %r13d, %eax
movslq %eax, %rdi
addq 0x28(%rsp), %rdi
movl 0x4c(%rsp), %ecx
testl %ecx, %ecx
je 0x2ce6
leaq 0x80(%rsp), %rax
movq %rax, (%rsp)
movl %r8d, %esi
movq 0x20(%rsp), %rdx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x1140
jmp 0x2cfb
movq 0x50(%rsp), %rax
movq (%rax,%rbp,8), %rsi
imull %r13d, %r8d
movslq %r8d, %rdx
callq 0x1220
incl %r14d
movl %r12d, %r15d
jmp 0x2c70
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x2a95
pushq $0xa
popq %rdi
callq 0x1090
movq 0x60(%rsp), %r14
movl 0x44(%rsp), %r15d
movq %rbp, %rdi
incq %rdi
movl 0x18(%rsp), %esi
jmp 0x2c11
movl 0x3c(%rsp), %eax
movl %eax, %r14d
jmp 0x2bdc
cmpl $0x0, 0x14(%rsp)
jne 0x2d60
movq 0x28(%rsp), %rdi
callq 0x10f0
pushq $0xa
popq %rdi
callq 0x1090
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq