1 /*
2  *
3  *  This file is part of MUMPS 4.10.0, built on Tue May 10 12:56:32 UTC 2011
4  *
5  *
6  *  This version of MUMPS is provided to you free of charge. It is public
7  *  domain, based on public domain software developed during the Esprit IV
8  *  European project PARASOL (1996-1999). Since this first public domain
9  *  version in 1999, research and developments have been supported by the
10  *  following institutions: CERFACS, CNRS, ENS Lyon, INPT(ENSEEIHT)-IRIT,
11  *  INRIA, and University of Bordeaux.
12  *
13  *  The MUMPS team at the moment of releasing this version includes
14  *  Patrick Amestoy, Maurice Bremond, Alfredo Buttari, Abdou Guermouche,
15  *  Guillaume Joslin, Jean-Yves L'Excellent, Francois-Henry Rouet, Bora
16  *  Ucar and Clement Weisbecker.
17  *
18  *  We are also grateful to Emmanuel Agullo, Caroline Bousquet, Indranil
19  *  Chowdhury, Philippe Combes, Christophe Daniel, Iain Duff, Vincent Espirat,
20  *  Aurelia Fevre, Jacko Koster, Stephane Pralet, Chiara Puglisi, Gregoire
21  *  Richard, Tzvetomila Slavova, Miroslav Tuma and Christophe Voemel who
22  *  have been contributing to this project.
23  *
24  *  Up-to-date copies of the MUMPS package can be obtained
25  *  from the Web pages:
26  *  http://mumps.enseeiht.fr/  or  http://graal.ens-lyon.fr/MUMPS
27  *
28  *
29  *   THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY
30  *   EXPRESSED OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
31  *
32  *
33  *  User documentation of any code that uses this software can
34  *  include this complete notice. You can acknowledge (using
35  *  references [1] and [2]) the contribution of this package
36  *  in any scientific publication dependent upon the use of the
37  *  package. You shall use reasonable endeavours to notify
38  *  the authors of the package of this publication.
39  *
40  *   [1] P. R. Amestoy, I. S. Duff, J. Koster and  J.-Y. L'Excellent,
41  *   A fully asynchronous multifrontal solver using distributed dynamic
42  *   scheduling, SIAM Journal of Matrix Analysis and Applications,
43  *   Vol 23, No 1, pp 15-41 (2001).
44  *
45  *   [2] P. R. Amestoy and A. Guermouche and J.-Y. L'Excellent and
46  *   S. Pralet, Hybrid scheduling for the parallel solution of linear
47  *   systems. Parallel Computing Vol 32 (2), pp 136-156 (2006).
48  *
49  */
50 #ifndef MUMPS_IO_BASIC_H
51 #define MUMPS_IO_BASIC_H
52 #include "mumps_compat.h"
53 #if ! defined(WITHOUT_PTHREAD) && defined(MUMPS_WIN32)
54 # define WITHOUT_PTHREAD 1
55 #endif
56 #if defined(_AIX)
57 # if ! defined(_ALL_SOURCE)
58 /* Macro needed for direct I/O on IBM AIX */
59 #  define _ALL_SOURCE 1
60 # endif
61 #endif
62 #if ! defined (MUMPS_WIN32)
63 # if ! defined(_XOPEN_SOURCE)
64 /* Setting this macro avoids the warnings ("missing
65  * prototype") related to the use of pread /pwrite */
66 #  define _XOPEN_SOURCE 500
67 # endif
68 #endif
69 #define MAX_FILE_SIZE 1879048192 /* (2^31)-1-(2^27) */
70 /* #define MAX_FILE_SIZE 1000000 */  /* (2^31)-1-(2^27) */
71 /*                                                      */
72 /* Important Note :                                     */
73 /* ================                                     */
74 /* On GNU systems, __USE_GNU must be defined to have    */
75 /* access to the O_DIRECT I/O flag.                     */
76 /*                                                      */
77 #include <stdio.h>
78 #include <stdlib.h>
79 #include <string.h>
80 #include <math.h>
81 #if ! defined (MUMPS_WIN32)
82 # include <unistd.h>
83 # include <sys/types.h>
84 # include <sys/stat.h>
85 # include <fcntl.h>
86 # include <sys/time.h>
87 # include <time.h>
88 #endif
89 #if ! defined (MUMPS_WIN32)
90 # define MUMPS_IO_FLAG_O_DIRECT 0
91 #endif
92 /* Force WITH_PFUNC on architectures where we know that it should work */
93 #if (defined (sgi) || defined (__sgi)) || defined(_AIX) || (defined(sun) || defined(__sun)) || defined(_GNU_SOURCE)
94 # undef WITH_PFUNC
95 # define WITH_PFUNC
96 #endif
97 #define IO_SYNC      0
98 #define IO_ASYNC_TH  1
99 #define IO_ASYNC_AIO 2
100 #define IO_READ 1
101 #define IO_WRITE 0
102 #define UNITIALIZED "NAME_NOT_INITIALIZED"
103 #define MUMPS_OOC_DEFAULT_DIR "/tmp"
104 #ifdef MUMPS_WIN32
105 # define SEPARATOR "\\"
106 #else
107 # define SEPARATOR "/"
108 #endif
109 /* #define NB_FILE_TYPE_FACTO 1 */
110 /* #define NB_FILE_TYPE_SOLVE 1 */
111 #define my_max(x,y) ( (x) > (y) ? (x) : (y) )
112 #define my_ceil(x) ( (int)(x) >= (x) ? (int)(x) : ( (int)(x) + 1 ) )
113 typedef struct __mumps_file_struct{
114   int write_pos;
115   int current_pos;
116   int is_opened;
117 #if ! defined (MUMPS_WIN32)
118   int file;
119 #else
120   FILE* file;
121 #endif
122   char name[351]; /* Should be large enough to hold tmpdir, prefix, suffix */
123 }mumps_file_struct;
124 typedef struct __mumps_file_type{
125 #if ! defined (MUMPS_WIN32)
126   int mumps_flag_open;
127 #else
128   char mumps_flag_open[6];
129 #endif
130   int mumps_io_current_file_number;
131   int mumps_io_last_file_opened;
132   int mumps_io_nb_file_opened;
133   int mumps_io_nb_file;
134   mumps_file_struct* mumps_io_pfile_pointer_array;
135   mumps_file_struct* mumps_io_current_file;
136 }mumps_file_type;
137 /* Exported global variables */
138 #if ! defined (MUMPS_WIN32)
139 # if defined (WITH_PFUNC) && ! defined (WITHOUT_PTHREAD)
140 #  include <pthread.h>
141 extern pthread_mutex_t mumps_io_pwrite_mutex;
142 # endif
143 /* extern int* mumps_io_pfile_pointer_array; */
144 /* extern int* mumps_io_current_file; */
145 /* #else /\*_WIN32*\/ */
146 /* extern FILE** mumps_io_current_file; */
147 /* extern FILE** mumps_io_pfile_pointer_array; */
148 #endif /* MUMPS_WIN32 */
149 /*extern mumps_file_struct* mumps_io_pfile_pointer_array;
150   extern mumps_file_struct* mumps_io_current_file;*/
151 extern mumps_file_type* mumps_files;
152 /* extern int mumps_io_current_file_number; */
153 extern char* mumps_ooc_file_prefix;
154 /* extern char** mumps_io_pfile_name; */
155 /* extern int mumps_io_current_file_position; */
156 /* extern int mumps_io_write_pos; */
157 /* extern int mumps_io_last_file_opened; */
158 extern int mumps_elementary_data_size;
159 extern int mumps_io_is_init_called;
160 extern int mumps_io_myid;
161 extern int mumps_io_max_file_size;
162 /* extern int mumps_io_nb_file; */
163 extern int mumps_io_flag_async;
164 extern int mumps_io_k211;
165 /* extern int mumps_flag_open; */
166 extern int directio_flag;
167 extern int mumps_directio_flag;
168 extern int mumps_io_nb_file_type;
169 /* Exported functions */
170 int mumps_set_file(int type,int file_number_arg);
171 void mumps_update_current_file_position(mumps_file_struct* file_arg);
172 int mumps_compute_where_to_write(const double to_be_written,const int type,long long vaddr,size_t already_written);
173 int mumps_prepare_pointers_for_write(double to_be_written,int * pos_in_file, int * file_number,const int type,long long vaddr,size_t already_written);
174 int mumps_io_do_write_block(void * address_block,long long block_size,int * type,long long vaddr,int * ierr);
175 int mumps_io_do_read_block(void * address_block,long long block_size,int * type,long long vaddr,int * ierr);
176 int mumps_compute_nb_concerned_files(long long block_size,int * nb_concerned_files,long long vaddr);
177 MUMPS_INLINE int mumps_gen_file_info(long long vaddr, int * pos, int * file);
178 int mumps_free_file_pointers(int* step);
179 int mumps_init_file_structure(int *_myid, long long *total_size_io,int *size_element,int *nb_file_type,int *flag_tab);
180 int mumps_init_file_name(char* mumps_dir,char* mumps_file,int* mumps_dim_dir,int* mumps_dim_file,int* _myid);
181 void mumps_io_init_file_struct(int* nb,int which);
182 int mumps_io_alloc_file_struct(int* nb,int which);
183 int mumps_io_get_nb_files(int* nb_files, const int* type);
184 int mumps_io_get_file_name(int* indice,char* name,int* length,int* type);
185 int mumps_io_alloc_pointers(int * nb_file_type, int * dim);
186 int mumps_io_init_vars(int* myid_arg,int* size_element,int* async_arg);
187 int mumps_io_set_file_name(int* indice,char* name,int* length,int* type);
188 int mumps_io_open_files_for_read();
189 int mumps_io_set_last_file(int* dim,int* type);
190 int mumps_io_write__(void *file, void *loc_add, size_t write_size, int where,int type);
191 #if ! defined (MUMPS_WIN32)
192 int mumps_io_write_os_buff__(void *file, void *loc_add, size_t write_size, int where);
193 int mumps_io_write_direct_io__(void *file, void *loc_addr, size_t write_size, int where,int type);
194 int mumps_io_flush_write__(int type);
195 #else
196 int mumps_io_write_win32__(void *file, void *loc_add, size_t write_size, int where);
197 #endif
198 int mumps_io_read__(void * file,void * loc_addr,size_t size,int local_offset,int type);
199 #if ! defined (MUMPS_WIN32)
200 int mumps_io_read_os_buff__(void * file,void * loc_addr,size_t size,int local_offset);
201 int mumps_io_read_direct_io__(void * file,void * loc_addr,size_t size,int local_offset,int type);
202 #else
203 int mumps_io_read_win32__(void * file,void * loc_addr,size_t size,int local_offset);
204 #endif
205 int mumps_compute_file_size(void *file,size_t *size);
206 #if ! defined (MUMPS_WIN32) && ! defined (WITHOUT_PTHREAD)
207 # ifdef WITH_PFUNC
208 int mumps_io_protect_pointers();
209 int mumps_io_unprotect_pointers();
210 int mumps_io_init_pointers_lock();
211 int mumps_io_destroy_pointers_lock();
212 # endif /* WITH_PFUNC */
213 #endif /* MUMPS_WIN32 */
214 #endif /* MUMPS_IO_BASIC_H */
215