// File: /workspace/github_cpp_makefile_star2_O1/Mengjintao[P]SWAPCounter/src/mympi.cpp
// Function: MPIEnviroment::File_locate()
void MPIEnviroment::File_locate()
{
	clock_t startTime, endTime;
	startTime = clock();		

        size = -1;
        if(rank==0)	MPI_File_get_size(cFile, &size);
	MPI_Bcast(&size,1,MPI_UNSIGNED_LONG_LONG, 0, MPI_COMM_WORLD);	
	printf("Proc:%d size of file is: %lld ...\n", rank,  size);
	fflush(stdout);

	if(rank%this->groupProc)	{
		start_pos = end_pos = 0;
		datasize = 0;
//        	printf("Proc:%d file start at %llu and end at %llu...\n", rank,  start_pos, end_pos);
		return;
	}
        unsigned long long step = (size-1)/(nprocs/groupProc)+1;
	int groupRank = rank/groupProc;
	//set start position and end position for file pointer
	start_pos = groupRank*step;
	start_pos = start_pos<size?start_pos:size;
	end_pos   = (groupRank+1)*step;
	end_pos   = end_pos<size?end_pos:size;

	//Find the start position for one read.
	char str[PreReadLen+2];
	unsigned long long  preLen = size-start_pos;
	if(preLen>PreReadLen)	preLen=PreReadLen;	
	MPI_File_read_at(cFile, start_pos, str, preLen, MPI_CHAR, &status);
	unsigned long long i=0;	
	while(str[i]!='>' && start_pos<size && i<preLen) {i++; start_pos++;}
	assert(str[i]=='>'||start_pos==size||i==preLen);
	
	//Find the end position for one read.
	preLen = min(size-end_pos, (long long int) PreReadLen);
	MPI_File_read_at(cFile,end_pos,str,preLen, MPI_CHAR, &status);
	i=0;
        while(str[i]!='>' && end_pos<size && i<preLen) {i++; end_pos++;}

	datasize = end_pos-start_pos;
//        printf("Proc:%d file start at %llu and end at %llu...\n", rank,  start_pos, end_pos);
	read_offset = start_pos;

	endTime = clock();
	elapsedTime += endTime-startTime;
	locateTime  += endTime-startTime;	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, %rbx
callq 0x2180
movq %rax, %r14
leaq 0x220(%rbx), %r15
movq $-0x1, 0x220(%rbx)
cmpl $0x0, (%rbx)
jne 0x561e
movq 0x218(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
movq 0x39cb(%rip), %rdx      # 0x8ff0
movq 0x3964(%rip), %r8       # 0x8f90
movq %r15, %rdi
movl $0x1, %esi
xorl %ecx, %ecx
callq 0x2060
movl (%rbx), %esi
movq 0x220(%rbx), %rdx
leaq 0x15a8(%rip), %rdi      # 0x6bf3
xorl %eax, %eax
callq 0x2050
movq 0x391f(%rip), %rax      # 0x8f78
movq (%rax), %rdi
callq 0x22e0
movl (%rbx), %eax
movl 0x278(%rbx), %edi
cltd
idivl %edi
testl %edx, %edx
je 0x568c
pxor %xmm0, %xmm0
movdqu %xmm0, 0x228(%rbx)
movq $0x0, 0x238(%rbx)
jmp 0x5884
movl %eax, %ecx
movq %r14, 0x8(%rsp)
movq 0x220(%rbx), %r14
leaq -0x1(%r14), %rsi
movl 0x4(%rbx), %eax
cltd
idivl %edi
movslq %eax, %rdi
movq %rsi, %rax
cqto
idivq %rdi
incq %rax
movslq %ecx, %rcx
movq %rax, %rbp
imulq %rcx, %rbp
cmpq %r14, %rbp
movq %r14, %rsi
cmovlq %rbp, %rsi
movq %rsi, 0x228(%rbx)
incl %ecx
movslq %ecx, %rcx
imulq %rax, %rcx
cmpq %r14, %rcx
cmovgeq %r14, %rcx
movq %rcx, 0x230(%rbx)
movq %r14, %r12
subq %rsi, %r12
movl $0x12c, %eax            # imm = 0x12C
cmpq %rax, %r12
cmovaeq %rax, %r12
movq 0x218(%rbx), %rdi
leaq 0x260(%rbx), %r15
movq 0x3875(%rip), %r8       # 0x8f80
leaq 0x10(%rsp), %r13
movq %r13, %rdx
movl %r12d, %ecx
movq %r15, %r9
callq 0x21b0
cmpb $0x3e, (%r13)
sete %al
je 0x57c0
movq 0x220(%rbx), %rdx
movq 0x228(%rbx), %rcx
cmpq %rdx, %rcx
setge %sil
cmpq %rbp, %r14
setle %dil
orb %sil, %dil
jne 0x577c
movl $0x1, %edi
cmpb $0x3e, 0x10(%rsp,%rdi)
sete %al
je 0x57b6
incq %rcx
leaq 0x1(%rdi), %rsi
cmpq %r12, %rdi
jae 0x5770
movq %rsi, %rdi
cmpq %rdx, %rcx
jl 0x5752
movq %rcx, 0x228(%rbx)
decq %rsi
jmp 0x577e
xorl %esi, %esi
testb %al, %al
jne 0x57c0
cmpq %r12, %rsi
je 0x57c0
movq 0x220(%rbx), %rax
cmpq %rax, 0x228(%rbx)
je 0x57c0
leaq 0x1478(%rip), %rdi      # 0x6c16
leaq 0x13e2(%rip), %rsi      # 0x6b87
leaq 0x1492(%rip), %rcx      # 0x6c3e
movl $0x63, %edx
callq 0x2170
incq %rcx
movq %rcx, 0x228(%rbx)
movq 0x218(%rbx), %rdi
movq 0x220(%rbx), %r12
movq 0x230(%rbx), %rsi
subq %rsi, %r12
movl $0x12c, %eax            # imm = 0x12C
cmpq %rax, %r12
cmovgeq %rax, %r12
movq 0x3795(%rip), %r8       # 0x8f80
leaq 0x10(%rsp), %r13
movq %r13, %rdx
movl %r12d, %ecx
movq %r15, %r9
callq 0x21b0
cmpb $0x3e, (%r13)
je 0x583d
movq 0x220(%rbx), %rax
movq 0x230(%rbx), %rcx
leaq 0x1(%rcx), %rdx
xorl %esi, %esi
cmpq %r12, %rsi
jae 0x583d
leaq (%rcx,%rsi), %rdi
cmpq %rax, %rdi
jge 0x583d
leaq (%rdx,%rsi), %rdi
movq %rdi, 0x230(%rbx)
cmpb $0x3e, 0x11(%rsp,%rsi)
leaq 0x1(%rsi), %rsi
jne 0x5819
movq 0x228(%rbx), %rax
movq 0x230(%rbx), %rcx
subq %rax, %rcx
movq %rcx, 0x238(%rbx)
movq %rax, 0x240(%rbx)
callq 0x2180
subq 0x8(%rsp), %rax
movdqu 0x248(%rbx), %xmm0
movq %rax, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
paddq %xmm0, %xmm1
movdqu %xmm1, 0x248(%rbx)
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq