1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3 *
4 * Copyright (C) 1997 University of Chicago.
5 * See COPYRIGHT notice in top-level directory.
6 */
7
8 #include "mpioimpl.h"
9
10 #ifdef HAVE_WEAK_SYMBOLS
11
12 #if defined(HAVE_PRAGMA_WEAK)
13 #pragma weak MPI_File_write_shared = PMPI_File_write_shared
14 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
15 #pragma _HP_SECONDARY_DEF PMPI_File_write_shared MPI_File_write_shared
16 #elif defined(HAVE_PRAGMA_CRI_DUP)
17 #pragma _CRI duplicate MPI_File_write_shared as PMPI_File_write_shared
18 /* end of weak pragmas */
19 #elif defined(HAVE_WEAK_ATTRIBUTE)
20 int MPI_File_write_shared(MPI_File fh, const void *buf, int count, MPI_Datatype datatype,
21 MPI_Status *status) __attribute__((weak,alias("PMPI_File_write_shared")));
22 #endif
23
24 /* Include mapping from MPI->PMPI */
25 #define MPIO_BUILD_PROFILING
26 #include "mpioprof.h"
27 #endif
28
29 /* status object not filled currently */
30
31 /*@
32 MPI_File_write_shared - Write using shared file pointer
33
34 Input Parameters:
35 . fh - file handle (handle)
36 . buf - initial address of buffer (choice)
37 . count - number of elements in buffer (nonnegative integer)
38 . datatype - datatype of each buffer element (handle)
39
40 Output Parameters:
41 . status - status object (Status)
42
43 .N fortran
44 @*/
MPI_File_write_shared(MPI_File fh,ROMIO_CONST void * buf,int count,MPI_Datatype datatype,MPI_Status * status)45 int MPI_File_write_shared(MPI_File fh, ROMIO_CONST void *buf, int count,
46 MPI_Datatype datatype, MPI_Status *status)
47 {
48 int error_code, buftype_is_contig, filetype_is_contig;
49 ADIO_Offset bufsize;
50 static char myname[] = "MPI_FILE_READ_SHARED";
51 MPI_Count datatype_size, incr;
52 ADIO_Offset off, shared_fp;
53 ADIO_File adio_fh;
54 void *e32buf = NULL;
55 const void *xbuf = NULL;
56
57 MPIU_THREAD_CS_ENTER(ALLFUNC,);
58
59 adio_fh = MPIO_File_resolve(fh);
60
61 /* --BEGIN ERROR HANDLING-- */
62 MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code);
63 MPIO_CHECK_COUNT(adio_fh, count, myname, error_code);
64 MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code);
65 /* --END ERROR HANDLING-- */
66
67 MPI_Type_size_x(datatype, &datatype_size);
68
69 /* --BEGIN ERROR HANDLING-- */
70 MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code);
71 /* --END ERROR HANDLING-- */
72
73 if (count*datatype_size == 0) {
74 #ifdef HAVE_STATUS_SET_BYTES
75 MPIR_Status_set_bytes(status, datatype, 0);
76 #endif
77 error_code = MPI_SUCCESS;
78 goto fn_exit;
79 }
80
81 /* --BEGIN ERROR HANDLING-- */
82 MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code);
83 MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code);
84 /* --END ERROR HANDLING-- */
85
86 ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
87 ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig);
88
89 ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code);
90
91 incr = (count*datatype_size)/adio_fh->etype_size;
92
93 ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code);
94 /* --BEGIN ERROR HANDLING-- */
95 if (error_code != MPI_SUCCESS)
96 {
97 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_FATAL,
98 myname, __LINE__, MPI_ERR_INTERN,
99 "**iosharedfailed", 0);
100 error_code = MPIO_Err_return_file(adio_fh, error_code);
101 goto fn_exit;
102 }
103 /* --END ERROR HANDLING-- */
104
105 xbuf = buf;
106 if (adio_fh->is_external32) {
107 error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf);
108 if (error_code != MPI_SUCCESS)
109 goto fn_exit;
110
111 xbuf = e32buf;
112 }
113
114 if (buftype_is_contig && filetype_is_contig)
115 {
116 /* convert bufocunt and shared_fp to bytes */
117 bufsize = datatype_size * count;
118 off = adio_fh->disp + adio_fh->etype_size * shared_fp;
119
120 /* if atomic mode requested, lock (exclusive) the region, because there
121 could be a concurrent noncontiguous request. On NFS, locking is
122 done in the ADIO_WriteContig.*/
123
124 if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS))
125 ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize);
126
127 ADIO_WriteContig(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET,
128 off, status, &error_code);
129
130 if ((adio_fh->atomicity) && (adio_fh->file_system != ADIO_NFS))
131 ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize);
132 }
133 else
134 {
135 ADIO_WriteStrided(adio_fh, xbuf, count, datatype, ADIO_EXPLICIT_OFFSET,
136 shared_fp, status, &error_code);
137 /* For strided and atomic mode, locking is done in ADIO_WriteStrided */
138 }
139
140 /* --BEGIN ERROR HANDLING-- */
141 if (error_code != MPI_SUCCESS)
142 error_code = MPIO_Err_return_file(adio_fh, error_code);
143 /* --END ERROR HANDLING-- */
144
145 fn_exit:
146 if (e32buf != NULL) ADIOI_Free(e32buf);
147 MPIU_THREAD_CS_EXIT(ALLFUNC,);
148 return error_code;
149 }
150