1 /* ---------------------------------------------------------------- */
2 /* (C)Copyright IBM Corp. 2007, 2008 */
3 /* ---------------------------------------------------------------- */
9 /* -*- Mode: C; c-basic-offset:4 ; -*- */
11 * Copyright (C) 1997 University of Chicago.
12 * See COPYRIGHT notice in top-level directory.
17 /* returns the current location of the shared_fp in terms of the
18 no. of etypes relative to the current view, and also increments the
19 shared_fp by the number of etypes to be accessed (incr) in the read
20 or write following this function. */
22 void ADIOI_BGL_Get_shared_fp(ADIO_File fd
, int incr
, ADIO_Offset
*shared_fp
,
28 static char myname
[] = "ADIOI_BGL_GET_SHARED_FP";
30 if (fd
->shared_fp_fd
== ADIO_FILE_NULL
) {
31 MPI_Comm_dup(MPI_COMM_SELF
, &dupcommself
);
32 fd
->shared_fp_fd
= ADIO_Open(MPI_COMM_SELF
,
37 ADIO_CREATE
| ADIO_RDWR
| ADIO_DELETE_ON_CLOSE
,
44 if (*error_code
!= MPI_SUCCESS
) return;
46 ADIOI_WRITE_LOCK(fd
->shared_fp_fd
, 0, SEEK_SET
, sizeof(ADIO_Offset
));
47 err
= read(fd
->shared_fp_fd
->fd_sys
, shared_fp
, sizeof(ADIO_Offset
));
48 /* if the file is empty, the above read may return error
49 (reading beyond end of file). In that case, shared_fp = 0,
50 set above, is the correct value. */
53 ADIOI_WRITE_LOCK(fd
->shared_fp_fd
, 0, SEEK_SET
, sizeof(ADIO_Offset
));
55 err
= lseek(fd
->shared_fp_fd
->fd_sys
, 0, SEEK_SET
);
57 err
= read(fd
->shared_fp_fd
->fd_sys
, shared_fp
,
61 ADIOI_UNLOCK(fd
->shared_fp_fd
, 0, SEEK_SET
, sizeof(ADIO_Offset
));
62 *error_code
= MPIO_Err_create_code(MPI_SUCCESS
,
63 MPIR_ERR_RECOVERABLE
, myname
,
64 __LINE__
, MPI_ERR_IO
, "**io",
65 "**io %s", strerror(errno
));
70 new_fp
= *shared_fp
+ incr
;
72 err
= lseek(fd
->shared_fp_fd
->fd_sys
, 0, SEEK_SET
);
74 err
= write(fd
->shared_fp_fd
->fd_sys
, &new_fp
, sizeof(ADIO_Offset
));
76 ADIOI_UNLOCK(fd
->shared_fp_fd
, 0, SEEK_SET
, sizeof(ADIO_Offset
));
78 *error_code
= MPIO_Err_create_code(MPI_SUCCESS
, MPIR_ERR_RECOVERABLE
,
79 myname
, __LINE__
, MPI_ERR_IO
,
81 "**io %s", strerror(errno
));
83 else *error_code
= MPI_SUCCESS
;