// File: /workspace/github_cpp_makefile_star2_O3/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 0x56d2
movq 0x218(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
movq 0x3917(%rip), %rdx      # 0x8ff0
movq 0x38b0(%rip), %r8       # 0x8f90
movq %r15, %rdi
movl $0x1, %esi
xorl %ecx, %ecx
callq 0x2060
movl (%rbx), %esi
movq 0x220(%rbx), %rdx
leaq 0x14f4(%rip), %rdi      # 0x6bf3
xorl %eax, %eax
callq 0x2050
movq 0x386b(%rip), %rax      # 0x8f78
movq (%rax), %rdi
callq 0x22e0
movl (%rbx), %eax
movl 0x278(%rbx), %edi
cltd
idivl %edi
testl %edx, %edx
je 0x5740
pxor %xmm0, %xmm0
movdqu %xmm0, 0x228(%rbx)
movq $0x0, 0x238(%rbx)
jmp 0x58eb
movl %eax, %ecx
movq %r14, 0x8(%rsp)
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, %r14d           # imm = 0x12C
cmpq %r14, %r12
cmovaeq %r14, %r12
movq 0x218(%rbx), %rdi
leaq 0x260(%rbx), %rbp
movq 0x37c5(%rip), %r8       # 0x8f80
leaq 0x10(%rsp), %r13
movq %r13, %rdx
movl %r12d, %ecx
movq %rbp, %r9
callq 0x21b0
cmpb $0x3e, (%r13)
movq 0x220(%rbx), %r13
je 0x5829
movq 0x228(%rbx), %rax
leaq 0x1(%rax), %rdx
xorl %ecx, %ecx
cmpq %r12, %rcx
jae 0x580f
leaq (%rax,%rcx), %rsi
cmpq %r13, %rsi
jge 0x580f
leaq (%rdx,%rcx), %rsi
movq %rsi, 0x228(%rbx)
cmpb $0x3e, 0x11(%rsp,%rcx)
leaq 0x1(%rcx), %rcx
jne 0x57e9
jmp 0x5829
movq %r13, %rdx
subq %rax, %rdx
cmpq %rcx, %rdx
sete %al
cmpq %rcx, %r12
sete %cl
orb %al, %cl
je 0x58fd
movq 0x218(%rbx), %rdi
movq 0x230(%rbx), %rsi
subq %rsi, %r13
cmpq %r14, %r13
cmovgeq %r14, %r13
movq 0x3738(%rip), %r8       # 0x8f80
leaq 0x10(%rsp), %r12
movq %r12, %rdx
movl %r13d, %ecx
movq %rbp, %r9
callq 0x21b0
cmpb $0x3e, (%r12)
movq 0x230(%rbx), %rax
jne 0x5873
movq %rax, %rsi
movq 0x8(%rsp), %r14
jmp 0x58ad
movq (%r15), %rcx
xorl %edx, %edx
movq 0x8(%rsp), %r14
leaq (%rax,%rdx), %rsi
cmpq %r13, %rdx
jae 0x58ad
cmpq %rcx, %rsi
jge 0x58ad
leaq 0x1(%rdx), %rsi
leaq (%rax,%rdx), %rdi
incq %rdi
movq %rdi, 0x230(%rbx)
cmpb $0x3e, 0x11(%rsp,%rdx)
movq %rsi, %rdx
jne 0x587d
addq %rsi, %rax
movq %rax, %rsi
movq 0x228(%rbx), %rax
subq %rax, %rsi
movq %rsi, 0x238(%rbx)
movq %rax, 0x240(%rbx)
callq 0x2180
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 $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1312(%rip), %rdi      # 0x6c16
leaq 0x127c(%rip), %rsi      # 0x6b87
leaq 0x132c(%rip), %rcx      # 0x6c3e
movl $0x63, %edx
callq 0x2170