!*====================================================================*/
!* This software is delivered "as-is", with no warranties             */
!* expressed or implied.  This software is not supported by IBM.      */
!*====================================================================*/
!* (C) COPYRIGHT International Business Machines Corp. 2001           */
!* All Rights Reserved                                                */
!*                                                                    */
!* US Government Users Restricted Rights - Use, duplication or        */
!* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.  */
!*====================================================================*/

	implicit none

!*-------------------------------------------------------
!* Declarations for getshrseg routine
!*	segsize = passed value == segment size in doubles
!*      pa = returned value == pointer to shared segment
!*	lpage = passed value == 1 for large page segment
!*				0 for small page segment
!*
	real*8 a(*)
	pointer (pa,a)
	integer*8 lpage,segsize
!*-------------------------------------------------------

	integer*8 N,M
	parameter (N=256*1024*1024)
	parameter (M=N/4)
	integer*8 i,j,inc,ioff
	real*8 rtc,t0,t1,q

!$	integer omp_get_num_threads
!$	external omp_get_num_threads


        open (unit=2,file='lpage',form='formatted',status='old')
        read (2,'(i10)') lpage
	if (lpage .eq. 0) then
	    print *,'Requesting Small Pages'
	else if (lpage .eq. 1) then
	    print *,'Requesting Large Pages'
	else
	    print *,'Illegal Page Size Request'
	    stop 
	endif
	segsize = N
	call getshrseg(segsize,pa,lpage)
	print *,'Shared Segment Pointer = ',pa
	print *,'Segment Size (DW) = ',N,' (MB = ',8*N/1024/1024,')'
	print *,'Vector  Size (DW) = ',M,' (MB = ',8*M/1024/1024,')'

!$OMP PARALLEL
!$	print *,'Num_threads = ',omp_get_num_threads()
!$OMP END PARALLEL

	call mybindthreads

	print *,'Starting Initialization'
!$OMP PARALLEL DO
	do i=1,N
	a(i) = 1.0d0
	end do
	print *,'Done With Initialization'
	print *,'a(1)',a(1)
	print *,'a(N)',a(N)

	q = 1.0d0
	do ioff = 2048,3072,256
	    print *,'Base Offset = ',N/4
	    print *,'Incremental Offset = ',ioff
	    call stream(M,a(1),a(N/4+ioff),a(2*N/4+2*ioff))
	end do

  100	format (1x,i6,2x,f8.1)

	call  release_shm_segs()
	end
