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_iwrite_shared = PMPI_File_iwrite_shared
14 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
15 #pragma _HP_SECONDARY_DEF PMPI_File_iwrite_shared MPI_File_iwrite_shared
16 #elif defined(HAVE_PRAGMA_CRI_DUP)
17 #pragma _CRI duplicate MPI_File_iwrite_shared as PMPI_File_iwrite_shared
18 /* end of weak pragmas */
19 #elif defined(HAVE_WEAK_ATTRIBUTE)
20 int MPI_File_iwrite_shared(MPI_File fh, const void *buf, int count, MPI_Datatype datatype,
21                            MPIO_Request *request) __attribute__((weak,alias("PMPI_File_iwrite_shared")));
22 #endif
23 
24 /* Include mapping from MPI->PMPI */
25 #define MPIO_BUILD_PROFILING
26 #include "mpioprof.h"
27 #endif
28 
29 /*@
30     MPI_File_iwrite_shared - Nonblocking write using shared file pointer
31 
32 Input Parameters:
33 . fh - file handle (handle)
34 . buf - initial address of buffer (choice)
35 . count - number of elements in buffer (nonnegative integer)
36 . datatype - datatype of each buffer element (handle)
37 
38 Output Parameters:
39 . request - request object (handle)
40 
41 .N fortran
42 @*/
43 #ifdef HAVE_MPI_GREQUEST
44 #include "mpiu_greq.h"
45 #endif
46 
MPI_File_iwrite_shared(MPI_File fh,ROMIO_CONST void * buf,int count,MPI_Datatype datatype,MPIO_Request * request)47 int MPI_File_iwrite_shared(MPI_File fh, ROMIO_CONST void *buf, int count,
48 			   MPI_Datatype datatype, MPIO_Request *request)
49 {
50     int error_code, buftype_is_contig, filetype_is_contig;
51     ADIO_File adio_fh;
52     ADIO_Offset incr, bufsize;
53     MPI_Count datatype_size;
54     ADIO_Status status;
55     ADIO_Offset off, shared_fp;
56     static char myname[] = "MPI_FILE_IWRITE_SHARED";
57 
58     MPIU_THREAD_CS_ENTER(ALLFUNC,);
59 
60     adio_fh = MPIO_File_resolve(fh);
61 
62     /* --BEGIN ERROR HANDLING-- */
63     MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code);
64     MPIO_CHECK_COUNT(adio_fh, count, myname, error_code);
65     MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code);
66     /* --END ERROR HANDLING-- */
67 
68     MPI_Type_size_x(datatype, &datatype_size);
69 
70     /* --BEGIN ERROR HANDLING-- */
71     MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code);
72     MPIO_CHECK_FS_SUPPORTS_SHARED(adio_fh, myname, error_code);
73     MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code);
74     /* --END ERROR HANDLING-- */
75 
76     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
77     ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig);
78 
79     ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code);
80 
81     incr = (count*datatype_size)/adio_fh->etype_size;
82     ADIO_Get_shared_fp(adio_fh, incr, &shared_fp, &error_code);
83     if (error_code != MPI_SUCCESS) {
84 	/* note: ADIO_Get_shared_fp should have set up error code already? */
85 	MPIO_Err_return_file(adio_fh, error_code);
86     }
87 
88     /* contiguous or strided? */
89     if (buftype_is_contig && filetype_is_contig) {
90     /* convert sizes to bytes */
91 	bufsize = datatype_size * count;
92 	off = adio_fh->disp + adio_fh->etype_size * shared_fp;
93         if (!(adio_fh->atomicity))
94 	    ADIO_IwriteContig(adio_fh, buf, count, datatype, ADIO_EXPLICIT_OFFSET,
95 		            off, request, &error_code);
96 	else {
97             /* to maintain strict atomicity semantics with other concurrent
98               operations, lock (exclusive) and call blocking routine */
99 
100             if (adio_fh->file_system != ADIO_NFS)
101                 ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize);
102 
103             ADIO_WriteContig(adio_fh, buf, count, datatype, ADIO_EXPLICIT_OFFSET,
104 			     off, &status, &error_code);
105 
106             if (adio_fh->file_system != ADIO_NFS)
107                 ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize);
108 
109 	    MPIO_Completed_request_create(&adio_fh, bufsize, &error_code, request);
110 	}
111     }
112     else
113 	ADIO_IwriteStrided(adio_fh, buf, count, datatype, ADIO_EXPLICIT_OFFSET,
114 			   shared_fp, request, &error_code);
115 
116 fn_exit:
117     MPIU_THREAD_CS_EXIT(ALLFUNC,);
118 
119     return error_code;
120 }
121