// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x130, %rsp            # imm = 0x130
movq %rdi, %rbx
callq 0x2170
orq $-0x1, 0x220(%rbx)
movq %rax, %r14
leaq 0x220(%rbx), %r15
cmpl $0x0, (%rbx)
jne 0x53a4
movq 0x218(%rbx), %rdi
movq %r15, %rsi
callq 0x21f0
movq 0x3c45(%rip), %rdx      # 0x8ff0
movq 0x3be6(%rip), %r8       # 0x8f98
pushq $0x1
popq %rsi
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x2050
movl (%rbx), %esi
movq 0x220(%rbx), %rdx
leaq 0x1824(%rip), %rdi      # 0x6bf3
xorl %eax, %eax
callq 0x2040
movq 0x3ba3(%rip), %rax      # 0x8f80
movq (%rax), %rdi
callq 0x22a0
movl (%rbx), %eax
movl 0x278(%rbx), %edi
cltd
idivl %edi
testl %edx, %edx
je 0x540d
pxor %xmm0, %xmm0
movdqu %xmm0, 0x228(%rbx)
andq $0x0, 0x238(%rbx)
jmp 0x5572
movl %eax, %ecx
movq 0x220(%rbx), %r12
leaq -0x1(%r12), %rsi
movl 0x4(%rbx), %eax
cltd
idivl %edi
movslq %eax, %rdi
movq %rsi, %rax
cqto
idivq %rdi
incq %rax
movslq %ecx, %rcx
movq %rax, %rsi
imulq %rcx, %rsi
cmpq %r12, %rsi
cmovgeq %r12, %rsi
movq %rsi, 0x228(%rbx)
incl %ecx
movslq %ecx, %rcx
imulq %rax, %rcx
cmpq %r12, %rcx
cmovgeq %r12, %rcx
movq %rcx, 0x230(%rbx)
subq %rsi, %r12
movl $0x12c, %eax            # imm = 0x12C
cmpq %rax, %r12
cmovaeq %rax, %r12
movq 0x218(%rbx), %rdi
leaq 0x260(%rbx), %r13
movq 0x3b06(%rip), %r8       # 0x8f88
movq %rsp, %rdx
movl %r12d, %ecx
movq %r13, %r9
callq 0x2190
movq 0x220(%rbx), %r15
movq 0x228(%rbx), %rcx
xorl %eax, %eax
cmpb $0x3e, (%rsp,%rax)
je 0x54d3
cmpq %r12, %rax
jae 0x54bf
cmpq %r15, %rcx
jge 0x54bf
incq %rax
incq %rcx
movq %rcx, 0x228(%rbx)
jmp 0x54a0
cmpq %rcx, %r15
sete %cl
cmpq %rax, %r12
sete %al
orb %cl, %al
je 0x5583
movq 0x218(%rbx), %rdi
movq 0x230(%rbx), %rsi
subq %rsi, %r15
movl $0x12c, %eax            # imm = 0x12C
cmpq %rax, %r15
cmovgeq %rax, %r15
movq 0x3a91(%rip), %r8       # 0x8f88
movq %rsp, %rdx
movl %r15d, %ecx
movq %r13, %r9
callq 0x2190
movq 0x220(%rbx), %rcx
movq 0x230(%rbx), %rax
xorl %edx, %edx
cmpb $0x3e, (%rsp,%rdx)
je 0x5534
cmpq %r15, %rdx
jae 0x5534
cmpq %rcx, %rax
jge 0x5534
incq %rdx
incq %rax
movq %rax, 0x230(%rbx)
jmp 0x5515
movq 0x228(%rbx), %rcx
subq %rcx, %rax
movq %rax, 0x238(%rbx)
movq %rcx, 0x240(%rbx)
callq 0x2170
subq %r14, %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 $0x130, %rsp            # imm = 0x130
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x168c(%rip), %rdi      # 0x6c16
leaq 0x15f6(%rip), %rsi      # 0x6b87
leaq 0x16a6(%rip), %rcx      # 0x6c3e
pushq $0x63
popq %rdx
callq 0x2160