Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
SWcommon.h
Go to the documentation of this file.
1 
9 /*
10  * <license>
11  *
12  * Hitmap v1.2
13  *
14  * This software is provided to enhance knowledge and encourage progress in the scientific
15  * community. It should be used only for research and educational purposes. Any reproduction
16  * or use for commercial purpose, public redistribution, in source or binary forms, with or
17  * without modifications, is NOT ALLOWED without the previous authorization of the copyright
18  * holder. The origin of this software must not be misrepresented; you must not claim that you
19  * wrote the original software. If you use this software for any purpose (e.g. publication),
20  * a reference to the software package and the authors must be included.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY
23  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25  * THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Copyright (c) 2007-2015, Trasgo Group, Universidad de Valladolid.
33  * All rights reserved.
34  *
35  * More information on http://trasgo.infor.uva.es/
36  *
37  * </license>
38 */
39 
40 #ifndef _SW_COMMON_
41 #define _SW_COMMON_
42 
43 
44 
48 #define DEBUG
49 
50 
51 
52 // **********************************************************************
53 // Data types for the amino acids, H matrix and traceback matrices
54 // This types can be changed for all the benchmarks.
55 // You must change the parallel types accordingly.
56 // **********************************************************************
57 
59 typedef short aa_t;
61 typedef double h_t;
63 typedef short trace_t;
64 
65 
66 
67 // **********************************************************************
68 // Parallel types
69 // **********************************************************************
70 #if defined(REFPAR) || defined(HITPAR)
71 #include <mpi.h>
72 
74 #define MPI_AA MPI_SHORT
75 
76 #define MPI_H MPI_DOUBLE
77 
78 #endif
79 
80 
81 
82 // **********************************************************************
83 // Constants and Default values
84 // **********************************************************************
85 
87 #define MAX_NUM_AA 30
88 
89 #define DEFAULT_SIZE 8
90 
91 #define DEFAULT_GAPPENALTY -1.0
92 
93 #define DEFAULT_ITERATIONS 1
94 
95 
96 
97 // **********************************************************************
98 // Standard library includes
99 // **********************************************************************
100 
101 #include <stdio.h>
102 #include <stdlib.h>
103 #include <ctype.h>
104 
105 
106 
107 
108 // **********************************************************************
109 // is_root() function
110 // **********************************************************************
111 #if defined(REFPAR) || defined(HITPAR)
112 
116 int is_root();
117 
118 #else // defined(REFSEQ) || defined(HITSEQ)
119 
123 #define is_root() (1)
124 
125 #endif
126 
127 
128 
129 // **********************************************************************
130 // Root print functions
131 // **********************************************************************
135 #define printfroot(...) if( is_root() ) { printf(__VA_ARGS__); }
136 
140 #define fprintfroot(...) if( is_root() ) { fprintf(__VA_ARGS__); }
141 
142 
143 
144 
145 
146 
147 
148 
149 
150 
151 
152 
153 
154 
155 
156 
157 
158 // **********************************************************************
159 // PAM matrix definition and functions
160 // **********************************************************************
161 
165 typedef struct {
167  int num_aa;
168 
171 } PAM;
172 
176 extern PAM pam_matrix;
177 
181 #define pam(a,b) (pam_matrix.data[(a)*(pam_matrix.num_aa)+(b)])
182 
188 void initPAM(char * file);
189 
190 
191 
192 
193 
194 // **********************************************************************
195 // Protein file definition and functions
196 // **********************************************************************
197 // - The read functions are different for the C and Hitmap versions.
198 
203 typedef struct {
204  FILE * file;
205  int rewind;
206 } ProteinFile;
207 
211 void openProtein(ProteinFile * fprotein, char * filename);
212 
216 void closeProtein(ProteinFile * fprotein);
217 
218 
219 
220 
221 // **********************************************************************
222 // Amino acid name values and functions.
223 // **********************************************************************
224 
229 typedef struct {
230 
232  aa_t char2AA[256];
234  char AA2char[MAX_NUM_AA+1]; // +1 is for the GAP
235 
236 } AAName;
237 
239 #define NOTFOUND_AA -2
240 
241 #define NOTFOUND_CHAR '!'
242 
243 #define GAP_AA MAX_NUM_AA
244 
245 #define GAP_CHAR '-'
246 
248 extern AAName aa_names;
249 
254 static inline aa_t char2AA(char c){ return aa_names.char2AA[(int)c]; }
255 
260 static inline char AA2char(aa_t aa){ return aa_names.AA2char[aa]; }
261 
262 
263 
264 
265 
266 // **********************************************************************
267 // Other utilities
268 // **********************************************************************
269 
271 #define NOT_USED(p) ((void)(p))
272 
273 
275 #define CHECK_NULL(check){\
276  if ((check)==NULL) \
277  exit_error("Null Pointer allocating memory\n");\
278  }
279 
280 
284 void exit_error(const char * s);
285 
286 
287 
288 // **********************************************************************
289 // Global variables
290 // **********************************************************************
291 
292 // Protein and PAM matrix names
293 extern char * prot_name1;
294 extern char * prot_name2;
295 extern char * pam_name ;
296 
297 // Gap penalty
298 extern double gapPenalty;
299 
300 // Size of the input proteins
301 extern int size[2];
302 
303 // Number of iterations
304 extern int iterations;
305 
306 // Protein files.
307 extern ProteinFile pfile1;
308 extern ProteinFile pfile2;
309 
310 
311 
312 
313 // **********************************************************************
314 // Common benchmark functions
315 // **********************************************************************
316 
320 static inline h_t MAX4(h_t a, h_t b, h_t c, h_t d, int * idx){
321 
322  *idx = 0;
323  h_t max = a;
324 
325  if(b > max){
326  max = b;
327  *idx = 1;
328  }
329 
330  if(c > max){
331  max = c;
332  *idx = 2;
333  }
334 
335  if(d > max){
336  max = d;
337  *idx = 3;
338  }
339 
340  return max;
341 }
342 
343 
347 void input_parameters(int argc, char * argv[]);
348 
349 
350 
351 
352 
353 
354 
355 // **********************************************************************
356 // Parallel types and functions
357 // **********************************************************************
358 
359 #if defined(REFPAR) || defined(HITPAR)
360 
365 typedef struct {
366  double val;
367  int rank;
368  int i;
369  int j;
370 } double_3int;
371 
375 MPI_Datatype MPI_DOUBLE_3INT;
376 
381 void HMaxLoc(void * in, void * inout, int *len, MPI_Datatype * dptr);
382 
383 
384 
385 
386 
387 #endif
388 
389 
390 
391 
392 
393 /*
394  * Macros to force the processor to print the output
395  * in order based on the rank number.
396  * This is used for debug.
397  */
398 #ifdef DEBUG
399 
400 #include <time.h>
401 
402 
403 #if defined(REFPAR)
404 
405 
406 #define ALL_SEQUENTIAL_BEGIN(var) \
407  struct timespec var ## ts = {0,1000000}; \
408  fflush(stdout); \
409  int var = 0; \
410  for(var=-1;var<nProcs+1;var++){ \
411  if(rank == var){
412 
413 #define ALL_SEQUENTIAL_END(var) \
414  } else { \
415  nanosleep(&(var ## ts),NULL); \
416  } \
417  fflush(stdout); \
418  MPI_Barrier(comm); \
419  }
420 
421 #elif defined(HITPAR)
422 
423 
424 #define ALL_SEQUENTIAL_BEGIN(var) \
425  struct timespec var ## ts = {0,1000000}; \
426  fflush(stdout); \
427  int var = 0; \
428  for(var=-1;var<hit_NProcs+1;var++){ \
429  if(hit_Rank == var){
430 
431 #define ALL_SEQUENTIAL_END(var) \
432  } else { \
433  nanosleep(&(var ## ts),NULL); \
434  } \
435  fflush(stdout); \
436  MPI_Barrier(MPI_COMM_WORLD); \
437  }
438 
439 
440 #endif
441 #endif
442 
443 
444 
445 
446 #endif // _SW_COMMON_
double h_t
Definition: SWcommon.h:61
int num_aa
Definition: SWcommon.h:167
Definition: SWcommon.h:165
void closeProtein(ProteinFile *fprotein)
Definition: SWcommon.c:255
int rewind
Definition: SWcommon.h:205
AAName aa_names
Definition: SWcommon.c:69
void openProtein(ProteinFile *fprotein, char *filename)
Definition: SWcommon.c:241
char * prot_name1
Definition: SWcommon.c:49
PAM pam_matrix
Definition: SWcommon.c:67
double gapPenalty
Definition: SWcommon.c:54
int rank
Definition: SWpar_ref.c:181
#define MAX_NUM_AA
Definition: SWcommon.h:87
void exit_error(const char *s)
Definition: SWcommon.c:263
void input_parameters(int argc, char *argv[])
Definition: SWcommon.c:75
ProteinFile pfile1
Definition: SWcommon.c:63
void initPAM(char *filename)
Definition: SWcommon.c:128
int size[2]
Definition: SWcommon.c:57
ProteinFile pfile2
Definition: SWcommon.c:64
short aa_t
Definition: SWcommon.h:59
#define s
#define iterations
Definition: mg.c:119
char * pam_name
Definition: SWcommon.c:51
#define is_root()
Definition: SWcommon.h:123
char AA2char[MAX_NUM_AA+1]
Definition: SWcommon.h:234
short trace_t
Definition: SWcommon.h:63
#define max(a, b)
Definition: cannonAsync.c:47
char * prot_name2
Definition: SWcommon.c:50
aa_t char2AA[256]
Definition: SWcommon.h:232
FILE * file
Definition: SWcommon.h:204