1 |
|
2 |
/******************************************************* |
3 |
* |
4 |
* Copyright (c) 2003-2008 by University of Queensland |
5 |
* Earth Systems Science Computational Center (ESSCC) |
6 |
* http://www.uq.edu.au/esscc |
7 |
* |
8 |
* Primary Business: Queensland, Australia |
9 |
* Licensed under the Open Software License version 3.0 |
10 |
* http://www.opensource.org/licenses/osl-3.0.php |
11 |
* |
12 |
*******************************************************/ |
13 |
|
14 |
|
15 |
/**************************************************************/ |
16 |
|
17 |
/* Paso finite element solver */ |
18 |
|
19 |
/**************************************************************/ |
20 |
|
21 |
/* Copyrights by ACcESS Australia, 2003 */ |
22 |
/* Version: $Id$ */ |
23 |
|
24 |
/**************************************************************/ |
25 |
|
26 |
#include "Paso.h" |
27 |
|
28 |
#ifdef _OPENMP |
29 |
#include <omp.h> |
30 |
#endif |
31 |
|
32 |
#ifdef PASO_MPI |
33 |
#include "mpi_C.h" |
34 |
#else |
35 |
#include <time.h> |
36 |
#endif |
37 |
|
38 |
Paso_ErrorCodeType Paso_ErrorCode_=NO_ERROR; |
39 |
char Paso_ErrorMsg_[LenErrorMsg_MAX]={'\0'}; |
40 |
|
41 |
/* reset the error to NO_ERROR */ |
42 |
void Paso_resetError(void) { |
43 |
Paso_ErrorCode_=NO_ERROR; |
44 |
} |
45 |
|
46 |
/* sets an error */ |
47 |
void Paso_setError(Paso_ErrorCodeType err,__const char* msg) { |
48 |
size_t lenMsg=strlen(msg); |
49 |
if (Paso_noError()) { |
50 |
printf("error set = %d %s\n",err,msg); |
51 |
Paso_ErrorCode_=err; |
52 |
strncpy(Paso_ErrorMsg_,msg,MIN(LenErrorMsg_MAX,lenMsg)); |
53 |
Paso_ErrorMsg_[MIN(LenErrorMsg_MAX,lenMsg)]='\0'; |
54 |
} |
55 |
} |
56 |
|
57 |
/* checks if there is no error */ |
58 |
bool_t Paso_noError(void) { |
59 |
Paso_ErrorCodeType err=Paso_getErrorType(); |
60 |
/* return (err==NO_ERROR || err==WARNING);*/ |
61 |
return (err==NO_ERROR); |
62 |
} |
63 |
/* This function checks if the pointer ptr has a target. If not an |
64 |
error is raised and TRUE is returned. */ |
65 |
|
66 |
bool_t Paso_checkPtr(void* ptr) { |
67 |
if (ptr==NULL) { |
68 |
Paso_setError(MEMORY_ERROR,"Out of memory."); |
69 |
return TRUE; |
70 |
} else { |
71 |
return FALSE; |
72 |
} |
73 |
} |
74 |
|
75 |
/* This function returns a timer */ |
76 |
double Paso_timer(void) { |
77 |
double out; |
78 |
|
79 |
#ifdef PASO_MPI |
80 |
out = MPI_Wtime(); |
81 |
#else |
82 |
#ifdef _OPENMP |
83 |
out=omp_get_wtime(); |
84 |
#else |
85 |
out=((double) clock())/CLOCKS_PER_SEC; |
86 |
#endif |
87 |
#endif |
88 |
return out; |
89 |
} |
90 |
#ifndef _OPENMP |
91 |
int omp_get_max_threads(void) { |
92 |
return 1; |
93 |
} |
94 |
#endif |
95 |
|
96 |
|
97 |
/* return the error code */ |
98 |
Paso_ErrorCodeType Paso_getErrorType(void) { |
99 |
return Paso_ErrorCode_; |
100 |
} |
101 |
|
102 |
/* return the error message */ |
103 |
char* Paso_getErrorMessage(void) { |
104 |
return Paso_ErrorMsg_; |
105 |
} |
106 |
/**************************************************************/ |