| 1 |
/* |
| 2 |
* Copyright(C) 1999-2021, 2023 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <exodusII.h> |
| 10 |
#include <pthread.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <stdlib.h> |
| 13 |
#include <string.h> |
| 14 |
|
| 15 |
/* |
| 16 |
* Create a separate exodus file on each thread (same file as written |
| 17 |
* by testwt.c) |
| 18 |
*/ |
| 19 |
|
| 20 |
#define NUM_THREADS 8 |
| 21 |
|
| 22 |
typedef struct |
| 23 |
{ |
| 24 |
long threadid; |
| 25 |
int exoid; |
| 26 |
} param; |
| 27 |
|
| 28 |
void *error_test(void *varg) |
| 29 |
{ |
| 30 |
param *arg = (param *)varg; |
| 31 |
int i = 0; |
| 32 |
char name[32]; |
| 33 |
const char *routine; |
| 34 |
const char *message; |
| 35 |
int err_num; |
| 36 |
/* ex_opts(EX_VERBOSE); */ |
| 37 |
snprintf(name, 32, "Thread%ld", arg->threadid); |
| 38 |
for (i = EX_MEMFAIL; i <= EX_INTERNAL; i++) { |
| 39 |
ex_err(name, "Testing thread-safe exodus", i); |
| 40 |
ex_get_err(&message, &routine, &err_num); |
| 41 |
if (err_num != i) { |
| 42 |
fprintf(stderr, "Thread %ld: ERROR: called error (%d) does not match stored value (%d)\n", |
| 43 |
arg->threadid, i, err_num); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/* Netcdf error codes... (negative) */ |
| 48 |
for (i = NC_EBADID; i >= NC4_LAST_ERROR; i--) { |
| 49 |
ex_err(name, "Testing thread-safe exodus", i); |
| 50 |
ex_get_err(&message, &routine, &err_num); |
| 51 |
if (err_num != i) { |
| 52 |
fprintf(stderr, "Thread %ld: ERROR: called error (%d) does not match stored value (%d)\n", |
| 53 |
arg->threadid, i, err_num); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
return arg; |
| 58 |
} |
| 59 |
|
| 60 |
int main(int argc, char *argv[]) |
| 61 |
{ |
| 62 |
pthread_t threads[NUM_THREADS]; |
| 63 |
param arg[NUM_THREADS]; |
| 64 |
|
| 65 |
printf("Running on %d threads\n", NUM_THREADS); |
| 66 |
for (long t = 0; t < NUM_THREADS; t++) { |
| 67 |
arg[t].threadid = t; |
| 68 |
int rc = pthread_create(&threads[t], NULL, error_test, (void *)(arg + t)); |
| 69 |
if (rc) { |
| 70 |
printf("ERROR; return code from pthread_create() is %d\n", rc); |
| 71 |
exit(-1); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
for (long t = 0; t < NUM_THREADS; t++) { |
| 76 |
pthread_join(threads[t], NULL); |
| 77 |
} |
| 78 |
} |