1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
2 /*
3  *
4  *   Copyright (C) 1997 University of Chicago.
5  *   See COPYRIGHT notice in top-level directory.
6  */
7 
8 #include "ad_pfs.h"
9 
ADIOI_PFS_IwriteContig(ADIO_File fd,void * buf,int count,MPI_Datatype datatype,int file_ptr_type,ADIO_Offset offset,ADIO_Request * request,int * error_code)10 void ADIOI_PFS_IwriteContig(ADIO_File fd, void *buf, int count,
11                 MPI_Datatype datatype, int file_ptr_type,
12                 ADIO_Offset offset, ADIO_Request *request, int *error_code)
13 {
14     long *id_sys;
15     ADIO_Offset off;
16     int len, typesize, err;
17     static char myname[] = "ADIOI_PFS_IWRITECONTIG";
18 
19     *request = ADIOI_Malloc_request();
20     (*request)->optype = ADIOI_WRITE;
21     (*request)->fd = fd;
22     (*request)->datatype = datatype;
23 
24     MPI_Type_size(datatype, &typesize);
25     len = count * typesize;
26 
27     id_sys = (long *) ADIOI_Malloc(sizeof(long));
28     (*request)->handle = (void *) id_sys;
29 
30     off = (file_ptr_type == ADIO_INDIVIDUAL) ? fd->fp_ind : offset;
31 
32     lseek(fd->fd_sys, off, SEEK_SET);
33     *id_sys = _iwrite(fd->fd_sys, buf, len);
34 
35     if ((*id_sys == -1) && (errno == EQNOMID)) {
36      /* the man pages say EMREQUEST, but in reality errno is set to EQNOMID! */
37 
38         /* exceeded the max. no. of outstanding requests. */
39 
40         /* complete all previous async. requests */
41         ADIOI_Complete_async(error_code);
42 	if (error_code != MPI_SUCCESS) return;
43 
44         /* try again */
45 	*id_sys = _iwrite(fd->fd_sys, buf, len);
46 
47         if ((*id_sys == -1) && (errno == EQNOMID)) {
48 	    *error_code = MPIO_Err_create_code(MPI_SUCCESS,
49 					       MPIR_ERR_RECOVERABLE, myname,
50 					       __LINE__, MPI_ERR_IO, "**io",
51 					       "**io %s", strerror(errno));
52 	    return;
53         }
54     }
55     else if (*id_sys == -1) {
56 	*error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
57 					   myname, __LINE__, MPI_ERR_IO,
58 					   "**io",
59 					   "**io %s", strerror(errno));
60 	return;
61     }
62 
63     if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += len;
64 
65     (*request)->queued = 1;
66     (*request)->nbytes = len;
67     ADIOI_Add_req_to_list(request);
68     fd->async_count++;
69 
70     fd->fp_sys_posn = -1;   /* set it to null. */
71 
72     if (*id_sys == -1) {
73 	*error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
74 					   myname, __LINE__, MPI_ERR_IO,
75 					   "**io",
76 					   "**io %s", strerror(errno));
77     }
78     else *error_code = MPI_SUCCESS;
79 }
80