// File: /workspace/github_c_makefile_star2_O3/USArmyResearchLab[P]ARL_OpenSHMEM/test/put64.c
// Function: main
int main (void)
{
	int i, nelement;
	static unsigned int t, tsum;
	static int pWrk[SHMEM_REDUCE_MIN_WRKDATA_SIZE];
	static long pSync[SHMEM_REDUCE_SYNC_SIZE];
	for (i = 0; i < SHMEM_REDUCE_SYNC_SIZE; i++) {
		pSync[i] = SHMEM_SYNC_VALUE;
	}

	shmem_init();
	int me = shmem_my_pe();
	int npes = shmem_n_pes();

	int nxtpe = me + 1;
	if (nxtpe >= npes) nxtpe -= npes;

	long long* source 
		= (long long*)shmem_align(8192, NELEMENT * sizeof(long long));
	long long* target 
		= (long long*)shmem_align(8192, NELEMENT * sizeof(long long));

	for (i = 0; i < NELEMENT; i++) {
		source[i] = i + 1;
	}

	if (me == 0) {
		printf("# SHMEM Put64 times for variable message size\n" \
			"# Bytes\tLatency (nanoseconds)\n");
	}

	/* For int put we take average of all the times realized by a pair of PEs,
	thus reducing effects of physical location of PEs */
	for (nelement = 1; nelement <= NELEMENT; nelement <<= 1) {

		shmem_barrier_all();
		// reset values for each iteration
		for (i = 0; i < NELEMENT; i++) {
			target[i] = -90;
		}
		shmem_barrier_all();
		ctimer_start();

		t = ctimer();

		for (i = 0; i < NLOOP; i++) {
			shmem_put64(target, source, nelement, nxtpe);
		}

		t -= ctimer();

		shmem_int_sum_to_all(&tsum, &t, 1, 0, 0, npes, pWrk, pSync);

		if (me == 0) {
			int bytes = nelement * sizeof(*source);
			unsigned int nsec = ctimer_nsec(tsum / (npes * NLOOP));
			printf("%6d %7u\n", bytes, nsec);
		}

		shmem_barrier_all();

		int err = 0;

		for (i = 0; i < nelement; i++) if (target[i] != source[i]) err++;

		for (i = nelement; i < NELEMENT; i++) if (target[i] != -90) err++;

		if (err) { 
			printf("# %d: ERROR: %d incorrect value(s) copied\n",
				me, err);
			fflush(stdout);
//		} else {
//			printf("# %d: NO incorrect value(s) copied\n", me);
//			fflush(stdout);
		}
		shmem_barrier_all();
		fflush(stdout);
	}

	shmem_free(target);
	shmem_free(source);

	shmem_finalize();

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x4dd7(%rip)     # 0x61e0
movapd %xmm0, 0x4dbf(%rip)     # 0x61d0
movapd %xmm0, 0x4da7(%rip)     # 0x61c0
movapd %xmm0, 0x4d8f(%rip)     # 0x61b0
movapd %xmm0, 0x4d77(%rip)     # 0x61a0
callq 0x174c
leaq 0x4d1b(%rip), %rax      # 0x6150
movl (%rax), %ecx
leaq 0x4d16(%rip), %rax      # 0x6154
movl (%rax), %edx
movq %rcx, -0x30(%rbp)
leal 0x1(%rcx), %r15d
xorl %ebx, %ebx
cmpl %edx, %r15d
movq %rdx, -0x50(%rbp)
cmovgel %edx, %ebx
movl $0x2000, %edi           # imm = 0x2000
movl $0x2000, %esi           # imm = 0x2000
callq 0x16f0
movq %rax, %r12
movl $0x2000, %edi           # imm = 0x2000
movl $0x2000, %esi           # imm = 0x2000
callq 0x16f0
movq %rax, %r13
movl $0x1, %eax
movq %rax, -0x8(%r12,%rax,8)
incq %rax
cmpq $0x401, %rax            # imm = 0x401
jne 0x147d
cmpl $0x0, -0x30(%rbp)
jne 0x149f
leaq 0x2bba(%rip), %rdi      # 0x4054
callq 0x1080
subl %ebx, %r15d
movq -0x50(%rbp), %rax
addl %eax, %eax
leal (%rax,%rax,4), %eax
movl %eax, -0x34(%rbp)
movl $0x1, %ebx
leaq -0x48(%rbp), %r14
callq 0x1728
xorl %eax, %eax
movq $-0x5a, (%r13,%rax,8)
incq %rax
cmpq $0x400, %rax            # imm = 0x400
jne 0x14be
callq 0x1728
leaq 0x4d12(%rip), %rdi      # 0x61f0
xorl %esi, %esi
callq 0x1130
movq %r14, %rdi
xorl %esi, %esi
callq 0x1130
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq 0x4cf2(%rip), %rax      # 0x61f0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subq 0x4ceb(%rip), %rcx      # 0x61f8
cvtsi2sd %rcx, %xmm1
mulsd 0x2aee(%rip), %xmm1     # 0x4008
mulsd 0x2aee(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2ade(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
notl %eax
movl %eax, 0x4c25(%rip)      # 0x6170
movq %rbx, -0x58(%rbp)
movslq %ebx, %r14
movl $0xa, %ebx
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl %r15d, %ecx
callq 0x331c
decl %ebx
jne 0x1557
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x1130
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq 0x4c6a(%rip), %rax      # 0x61f0
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subq 0x4c63(%rip), %rcx      # 0x61f8
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0x2a63(%rip), %xmm1     # 0x4008
mulsd 0x2a63(%rip), %xmm0     # 0x4010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x2a53(%rip), %xmm0     # 0x4018
cvttsd2si %xmm0, %rdx
andl %ecx, %edx
orl %edx, %eax
movl 0x4b9c(%rip), %ecx      # 0x6170
addl %ecx, %eax
incl %eax
movl %eax, 0x4b92(%rip)      # 0x6170
leaq 0x4b8f(%rip), %rdi      # 0x6174
leaq 0x4b84(%rip), %rsi      # 0x6170
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq -0x50(%rbp), %r9
leaq 0x4b9f(%rip), %rax      # 0x61a0
pushq %rax
leaq 0x4b77(%rip), %rax      # 0x6180
pushq %rax
callq 0x3138
addq $0x10, %rsp
cmpl $0x0, -0x30(%rbp)
movq -0x58(%rbp), %rbx
jne 0x163f
leal (,%rbx,8), %esi
movl 0x4b4a(%rip), %eax      # 0x6174
xorl %edx, %edx
divl -0x34(%rbp)
leaq 0x29ea(%rip), %rdi      # 0x4020
movl %eax, %edx
xorl %eax, %eax
callq 0x1100
callq 0x1728
movl %ebx, %eax
xorl %ecx, %ecx
xorl %edx, %edx
movq (%r13,%rcx,8), %rsi
xorl %edi, %edi
cmpq (%r12,%rcx,8), %rsi
setne %dil
addl %edi, %edx
incq %rcx
cmpq %rcx, %rax
jne 0x164a
cmpl $0x3ff, %ebx            # imm = 0x3FF
ja 0x1683
xorl %ecx, %ecx
cmpq $-0x5a, (%r13,%rax,8)
setne %cl
addl %ecx, %edx
incq %rax
cmpq $0x400, %rax            # imm = 0x400
jne 0x166b
testl %edx, %edx
movq 0x494c(%rip), %r14      # 0x5fd8
je 0x16a8
leaq 0x2994(%rip), %rdi      # 0x4029
movq -0x30(%rbp), %rsi
xorl %eax, %eax
callq 0x1100
movq (%r14), %rdi
callq 0x11d0
callq 0x1728
movq (%r14), %rdi
callq 0x11d0
addl %ebx, %ebx
cmpl $0x401, %ebx            # imm = 0x401
leaq -0x48(%rbp), %r14
jl 0x14b7
movq %r13, %rdi
callq 0x1734
movq %r12, %rdi
callq 0x1734
callq 0x1d4d
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)