renamed GMX_THREADS to GMX_THREAD_MPI
[alexxy/gromacs.git] / src / gmxlib / gmxfio_int.h
1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
2  *
3  * 
4  *                This source code is part of
5  * 
6  *                 G   R   O   M   A   C   S
7  * 
8  *          GROningen MAchine for Chemical Simulations
9  * 
10  *                        VERSION 3.2.0
11  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13  * Copyright (c) 2001-2004, The GROMACS development team,
14  * check out http://www.gromacs.org for more information.
15
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  * 
21  * If you want to redistribute modifications, please consider that
22  * scientific software is very special. Version control is crucial -
23  * bugs must be traceable. We will be happy to consider code for
24  * inclusion in the official distribution, but derived work must not
25  * be called official GROMACS. Details are found in the README & COPYING
26  * files - if they are missing, get the official version at www.gromacs.org.
27  * 
28  * To help us fund GROMACS development, we humbly ask that you cite
29  * the papers on the package - you can find them in the top README file.
30  * 
31  * For more info, check our website at http://www.gromacs.org
32  * 
33  * And Hey:
34  * GROningen Mixture of Alchemy and Childrens' Stories
35  */
36
37
38
39 /* This is the new improved and thread safe version of gmxfio.  */
40
41
42 /* WARNING WARNING WARNING WARNING
43    The data types used here are PRIVATE to gmxfio routines. DO NOT use them
44    directly in your own code, but use the external functions provided in 
45    include/gmxfio.h 
46
47    If you don't heed this warning, your code will suddenly stop working 
48    at some point in the not-so-distant future. 
49
50    WARNING WARNING WARNING WARNING */
51
52
53 /* XDR should be available on all platforms now, 
54  * but we keep the possibility of turning it off...
55  */
56 #define USE_XDR
57
58
59
60 /* the reader/writer functions  for t_iotype */
61 typedef gmx_bool read_func(t_fileio *fio, void *item, int nitem, int eio,
62                        const char *desc,const char *srcfile,int line);
63 typedef gmx_bool write_func(t_fileio *fio, const void *item, int nitem, int eio,
64                         const char *desc,const char *srcfile,int line);
65
66
67 /* these are pointers to the actual reading & writing functions */
68 typedef struct
69 {
70     read_func *nread;
71     write_func *nwrite;
72 } t_iotype;
73
74
75
76 struct t_fileio
77 {
78     FILE *fp; /* the file pointer */
79     const t_iotype *iotp;  /* file type */
80     gmx_bool bOpen,  /* the file is open */
81          bRead,  /* the file is open for reading */
82          bDouble, /* write doubles instead of floats */
83          bDebug, /* the file ops should come with debug info */
84          bStdio, /* the file is actually stdin or stdout */
85          bLargerThan_off_t,  /* if the file position is largen than off_t 
86                                 could hold */
87          bReadWrite; /* the file is open for reading and writing */
88     char *fn; /* the file name */
89     XDR *xdr; /* the xdr data pointer */
90     enum xdr_op xdrmode; /* the xdr mode */
91     int iFTP; /* the file type identifier */
92
93     const char *comment; /* a comment string for debugging */
94
95     t_fileio *next, *prev; /* next and previous file pointers in the
96                               linked list */
97 #ifdef GMX_THREAD_MPI
98     tMPI_Lock_t  mtx;  /* content locking mutex. This is a fast lock
99                           for performance reasons: in some cases every
100                           single byte that gets read/written requires
101                           a lock */
102 #endif
103 }; 
104
105
106
107 extern const t_iotype asc_iotype;
108 extern const t_iotype bin_iotype;
109 extern const t_iotype xdr_iotype;
110 extern const t_iotype dummy_iotype;
111
112 extern const char *eioNames[eioNR];
113
114
115
116 #define GMX_FIO_BUFLEN 256
117
118 /* make a debug string if that is requested in the fio */
119 const char *gmx_fio_dbgstr(t_fileio *fio, const char *desc, char *buf);
120 /* check the number of items against the allowed number of items */
121 void gmx_fio_check_nitem(t_fileio *fio, int eio, int nitem, const char *file, 
122                          int line);
123 /* check the output type against allowed values */
124 void gmx_fio_fe(t_fileio *fio, int eio, const char *desc, const char *srcfile, 
125                 int line);
126
127 /* lock/unlock the mutex associated with a fio  */
128 void gmx_fio_lock(t_fileio *fio);
129 void gmx_fio_unlock(t_fileio *fio);
130
131
132