#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 8
#define NUM_NODES 64
#define NUM_NODAL_VAR 4
typedef struct
{
long threadid;
int exoid;
int timestep;
} param;
void *output_nodal_var(void *varg)
{
param *arg = (param *)varg;
int segment = num_node / NUM_THREADS;
int begin = arg->threadid * segment;
float *data = malloc(segment * sizeof(float));
int i, var;
if (arg->timestep == 1) {
for (i = 0; i < segment; i++) {
data[i] = (float)(begin + i) / 100.0;
}
}
if (arg->threadid < NUM_NODAL_VAR) {
char name[33];
snprintf(name, 33, "NodalVar%ld", arg->threadid + 1);
}
for (var = 1; var <= NUM_NODAL_VAR; var++) {
for (i = 0; i < segment; i++) {
data[i] = (arg->timestep - 1) * 10 + var + (float)(begin + i) / 100.0;
}
}
free(data);
return NULL;
}
int init_file(int num_nodal_vars)
{
int CPU_word_size = 0;
int IO_word_size = 4;
&CPU_word_size,
&IO_word_size);
printf("after ex_create for test.exo, exoid = %d\n", exoid);
printf(" cpu word size: %d io word size: %d\n", CPU_word_size, IO_word_size);
fprintf(stderr,
"ERROR: This exodus library is not compiled to allow thread-safe operations.\n");
exit(1);
}
int num_dim = 3;
int num_nodes = NUM_NODES;
int num_elem = 0;
int num_elem_blk = 0;
int num_node_sets = 0;
int num_side_sets = 0;
int error =
ex_put_init(exoid,
"This is a test", num_dim, num_nodes, num_elem, num_elem_blk,
num_node_sets, num_side_sets);
printf("after ex_put_init, error = %d\n", error);
printf("after ex_put_variable_param, error = %d\n", error);
if (error) {
exit(-1);
}
float time_value = 0.0;
printf("after ex_put_time, error = %d\n", error);
return exoid;
}
int main(int argc, char *argv[])
{
int exoid = init_file(NUM_NODAL_VAR);
param arg[NUM_THREADS];
pthread_t threads[NUM_THREADS];
printf("Running on %d threads\n", NUM_THREADS);
for (long t = 0; t < NUM_THREADS; t++) {
arg[t].exoid = exoid;
arg[t].threadid = t;
arg[t].timestep = 1;
int rc = pthread_create(&threads[t], NULL, output_nodal_var, (void *)(arg + t));
if (rc) {
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
}
for (long t = 0; t < NUM_THREADS; t++) {
pthread_join(threads[t], NULL);
}
}
@ EX_NODAL
Definition exodusII.h:268
@ EX_VERBOSE
Definition exodusII.h:390
@ EX_INQ_NODES
Definition exodusII.h:149
@ EX_INQ_THREADSAFE
Definition exodusII.h:205
#define EX_CLOBBER
Definition exodusII.h:101
int ex_put_init(int exoid, const char *title, int64_t num_dim, int64_t num_nodes, int64_t num_elem, int64_t num_elem_blk, int64_t num_node_sets, int64_t num_side_sets)
Definition ex_put_init.c:53
int ex_put_partial_coord(int exoid, int64_t start_node_num, int64_t num_nodes, const void *x_coor, const void *y_coor, const void *z_coor)
Definition ex_put_partial_coord.c:45
int ex_put_time(int exoid, int time_step, const void *time_value)
Definition ex_put_time.c:51
int ex_put_variable_name(int exoid, ex_entity_type obj_type, int var_num, const char *var_name)
Definition ex_put_variable_name.c:39
int ex_put_partial_var(int exoid, int time_step, ex_entity_type var_type, int var_index, ex_entity_id obj_id, int64_t start_index, int64_t num_entities, const void *var_vals)
Definition ex_put_partial_var.c:184
int ex_put_variable_param(int exoid, ex_entity_type obj_type, int num_vars)
Definition ex_put_variable_param.c:124
int64_t ex_inquire_int(int exoid, ex_inquiry req_info)
Definition ex_inquire.c:1029
#define ex_create(path, mode, comp_ws, io_ws)
Definition exodusII.h:591
int ex_opts(int options)
Definition ex_opts.c:56
int ex_close(int exoid)
Definition ex_close.c:47