Skip to main content

Post-processing tools 2023 R2

test_dvs_client.c

Last update: 17.04.2023
Go to the documentation of this file.
1 /* *************************************************************
2  * Copyright 2017-2018 ANSYS, Inc.
3  * All Rights Reserved.
4  *
5  * Restricted Rights Legend
6  *
7  * Use, duplication, or disclosure of this
8  * software and its documentation by the
9  * Government is subject to restrictions as
10  * set forth in subdivision [(b)(3)(ii)] of
11  * the Rights in Technical Data and Computer
12  * Software clause at 52.227-7013.
13  * *************************************************************
14  */
15 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <stdint.h>
28 #include <stdarg.h>
29 
32 #include "test_dynamic_data.h"
33 
34 #ifdef _WIN32
35 #include <Windows.h>
36 #else
37 #include <unistd.h>
38 #endif
39 
40 static void logging_function(void* user_data, const char* message)
41 {
42  fprintf(stderr, message);
43 }
44 
52 int main(int argc, char** argv)
53 {
54  uint32_t port = 50055;
55  uint32_t msec_delay = 0;
56  char host[512] = {0};
57  strcpy(host, "127.0.0.1");
58  char protocol[10] = {0};
59  strcpy(protocol, "grpc");
60  uint32_t width = 50;
61  uint32_t height = 50;
62  uint32_t depth = 50;
63  uint32_t max_timesteps = 10;
64  uint32_t current_rank = 0;
65  uint32_t total_ranks = 1;
66  uint8_t create_ghosts = 1;
67  uint8_t block_for_server = 1;
68  uint8_t block_for_reinit = 1;
69  uint32_t starting_timestep = 0;
70  uint32_t dedup = 1;
71  uint32_t send_case_vars = 1;
72  uint32_t send_structured_parts = 0;
73  char dataset_id[255] = {0};
74  strcpy(dataset_id, "Test-C-API");
75  char secret[255] = {0};
76  uint32_t plot_rank = 0;
77  uint32_t server_number = 0;
78  uint32_t server_verbosity = 0;
79  uint32_t local_ranks = 0;
80  uint32_t all_defs = 0;
81  char cache_uri[512] = {0};
82  uint32_t log_all = 0;
83  uint32_t debug_wait = 0;
84  uint32_t start_server = 0;
85  uint32_t test_reinit = 0;
86  uint32_t reinit_parts = 0;
87  uint32_t reinit_plots = 0;
88  uint32_t reinit_vars = 0;
89  uint32_t time_period = 0;
90  uint32_t test_iblanking = 0;
91  char dvs_file_loc[1024] = {0};
92  uint32_t test_delete = 0;
93 
94  uint32_t i = 1;
95  while (i < argc)
96  {
97  if ((strcmp(argv[i], "-p") == 0 ) && (i < argc - 1))
98  {
99  i++;
100  port = atoi(argv[i]);
101  }
102  else if ((strcmp(argv[i], "-h") == 0) && (i < argc - 1))
103  {
104  i++;
105  strncpy(host, argv[i], sizeof(host)-1);
106  }
107  else if ((strcmp(argv[i], "-protocol") == 0) && (i < argc - 1))
108  {
109  i++;
110  strncpy(protocol, argv[i], sizeof(protocol)-1);
111  if (strcmp(protocol, "grpc") != 0 && strcmp(protocol, "null") != 0 )
112  {
113  fprintf(stderr, "protocol: %s invalid\n", protocol);
114  exit(1);
115  }
116  }
117  else if ((strcmp(argv[i], "-d") == 0) && (i < argc - 1))
118  {
119  i++;
120  msec_delay = atoi(argv[i]);
121  }
122  else if ((strcmp(argv[i], "-s") == 0) && (i < argc - 3))
123  {
124  i++;
125  width = atoi(argv[i++]);
126  height = atoi(argv[i++]);
127  depth = atoi(argv[i]);
128  }
129  else if ((strcmp(argv[i], "-t") == 0) && (i < argc - 1))
130  {
131  i++;
132  max_timesteps = atoi(argv[i]);
133  }
134  else if ((strcmp(argv[i], "-r") == 0) && (i < argc - 2))
135  {
136  i++;
137  current_rank = atoi(argv[i++]);
138  total_ranks = atoi(argv[i]);
139  }
140  else if (strcmp(argv[i], "-noghost") == 0)
141  {
142  create_ghosts = 0;
143  }
144  else if (strcmp(argv[i], "-nowait") == 0)
145  {
146  block_for_server = 0;
147  }
148  else if ((strcmp(argv[i], "-start") == 0) && (i < argc - 1))
149  {
150  i++;
151  starting_timestep = atoi(argv[i]);
152  }
153  else if (strcmp(argv[i], "-nodedup") == 0)
154  {
155  dedup = 0;
156  }
157  else if (strcmp(argv[i], "-id") == 0)
158  {
159  i++;
160  memset(dataset_id, 0, 255);
161  strncpy(dataset_id, argv[i], sizeof(dataset_id)-1);
162  }
163  else if (strcmp(argv[i], "-secret") == 0)
164  {
165  i++;
166  strncpy(secret, argv[i], sizeof(secret)-1);
167  }
168  else if (strcmp(argv[i], "-case_constants") == 0)
169  {
170  send_case_vars = 1;
171  }
172  else if (strcmp(argv[i], "-structured") == 0)
173  {
174  send_structured_parts = 1;
175  }
176  else if (strcmp(argv[i], "-iblank") == 0)
177  {
178  test_iblanking = 1;
179  }
180  else if (strcmp(argv[i], "-plot_rank") == 0)
181  {
182  i++;
183  plot_rank = atoi(argv[i]);
184  }
185  else if (strcmp(argv[i], "-server") == 0 && (i < argc - 3))
186  {
187  i++;
188  start_server = 1;
189  server_number = atoi(argv[i++]);
190  local_ranks = atoi(argv[i++]);
191  server_verbosity = atoi(argv[i]);
192  }
193  else if (strcmp(argv[i], "-cache_uri") == 0)
194  {
195  i++;
196  strncpy(cache_uri, argv[i], sizeof(cache_uri)-1);
197  }
198  else if (strcmp(argv[i], "-all_defs") == 0)
199  {
200  all_defs = 1;
201  }
202  else if (strcmp(argv[i], "-log_all") == 0)
203  {
204  log_all = 1;
205  }
206  else if (strcmp(argv[i], "-debug_wait") == 0)
207  {
208  i++;
209  debug_wait = atoi(argv[i]);
210  }
211  else if (strcmp(argv[i], "-reinit_vars") == 0)
212  {
213  test_reinit = 1;
214  reinit_vars = 1;
215  }
216  else if (strcmp(argv[i], "-reinit_parts") == 0)
217  {
218  test_reinit = 1;
219  reinit_parts = 1;
220  }
221  else if (strcmp(argv[i], "-reinit_plots") == 0)
222  {
223  test_reinit = 1;
224  reinit_plots = 1;
225  }
226  else if (strcmp(argv[i], "-reinit_all") == 0)
227  {
228  test_reinit = 1;
229  reinit_parts = 1;
230  reinit_vars = 1;
231  reinit_plots = 1;
232  }
233  else if (strcmp(argv[i], "-time_period") == 0)
234  {
235  i++;
236  time_period = atoi(argv[i]);
237  }
238  else if (strcmp(argv[i], "-dvs_file") == 0)
239  {
240  i++;
241  strncpy(dvs_file_loc, argv[i], sizeof(dvs_file_loc)-1);
242  }
243  else if (strcmp(argv[i], "-test_delete") == 0)
244  {
245  test_delete = 1;
246  }
247  else
248  {
249  fprintf(stderr, "Unknown option: %s\n", argv[i]);
250  fprintf(stderr, "Usage: %s [-p port] [-h host] [-d msec_delay] [-t num_timesteps] [-s dx dy dz] [-noghost] [-nowait] [-start t]\n", argv[0]);
251  fprintf(stderr, "Options:\n");
252  fprintf(stderr, " -t timesteps Number of timesteps to generate. Default: %u\n", max_timesteps);
253  fprintf(stderr, " -p port Server port to connect to. Default: %u\n", port);
254  fprintf(stderr, " -h host Server hostname to connect to. Default: %s\n", host);
255  fprintf(stderr, " -protocol str Server protocol. I.E. grpc or null. Default: grpc");
256  fprintf(stderr, " -d delay Number of milliseconds to delay between timestep pushes. Default: %u\n", msec_delay);
257  fprintf(stderr, " -s dx dy dz Size of 3D hex grid (width height depth) Default: %u %u %u\n", width, height, depth);
258  fprintf(stderr, " -r x y Rank information x=current rank (0 based), y=total number of ranks. Default: %u %u\n", current_rank, total_ranks);
259  fprintf(stderr, " -noghost Do not create ghost elements\n");
260  fprintf(stderr, " -nowait Do not wait for server to be available\n");
261  fprintf(stderr, " -start t Begin timesteps with timestep Default: %u\n", starting_timestep);
262  fprintf(stderr, " -nodedup Do not de-duplicate data on the client side Default: deduplicate\n");
263  fprintf(stderr, " -id string Set an id/name for the dataset Default: TestID\n");
264  fprintf(stderr, " -secret string Shared secret to use when talking with server Default: no shared secret\n");
265  fprintf(stderr, " -case_constants Turn on sending case constants Defaults: Don't send case constants\n");
266  fprintf(stderr, " -structured Turn on sending structured part data Default: Don't send structured part data\n");
267  fprintf(stderr, " -plot_rank Set the rank which should send plot data to EnSight (zero based) Default: %u\n", plot_rank);
268  fprintf(stderr, " -server n r v Start a server using server number [n], expecting [r] local ranks for DVS connections to connect to with verbosity [v]. Local Rank Min/Max: 1/1000\n");
269  fprintf(stderr, " -cache_uri str The URI for the server to use for the cache. Default: No cache\n");
270  fprintf(stderr, " -all_defs Send all part/var definitions no matter the current rank. Default: No\n");
271  fprintf(stderr, " -log_all Print out all client logging information\n. Default: No client logs");
272  fprintf(stderr, " -debug_wait ms Wait for [ms] for debugging\n");
273  fprintf(stderr, " -reinit_vars Test reinit vars\n");
274  fprintf(stderr, " -reinit_parts Test reinit parts\n");
275  fprintf(stderr, " -reinit_plots Test reinit plots\n");
276  fprintf(stderr, " -reinit_all Test all reinit\n");
277  fprintf(stderr, " -time_period p Set modulus for time value to test timestep overwrite\n");
278  fprintf(stderr, " -dvs_file str Set a location for the dvs files to be created Default :./\n");
279  fprintf(stderr, " -test_delete Test deleting all timesteps before each update Default: Do not test\n");
280  exit(1);
281  }
282  i++;
283  }
284 
285  if (debug_wait > 0)
286  {
287  #ifdef _WIN32
288  Sleep(debug_wait);
289  #else
290  usleep(debug_wait*1000);
291  #endif
292  }
293 
294  fprintf(stderr, "Current Library Version: %s\n", dvs_get_version());
295  char uri[512] = {0};
296  sprintf(uri, "%s://%s:%u", protocol, host, port);
297  fprintf(stderr, "Connecting to: %s\n", uri);
298  fprintf(stderr, "Timestep delay: %u\n", msec_delay);
299 
300  uint32_t send_vars = 1;
301  uint32_t send_elems = 1;
302  uint32_t send_hex_elems = 1;
303  uint32_t send_nfaced_elems = 1;
304  uint32_t send_pnt_elems = 1;
305  uint32_t send_tri_quad_elems = 1;
306  uint32_t send_nsided_elems = 0;
307  uint32_t send_plots = 1;
308 
309  enum dvs_client_flags flags;
310  if (block_for_server) flags |= BLOCK_FOR_SERVER;
311  if (dedup) flags |= DEDUP;
312  if (block_for_reinit) flags |= BEGIN_INIT_WAIT_ON_REINIT;
313 
314  fprintf(stderr, "Client Flags: Blocking: %d, Dedup: %u\n", (BLOCK_FOR_SERVER & flags) > 0, (DEDUP & flags) > 0);
315 
316  int32_t server_id = -1;
317  dvs_server_create(uri, &server_id);
318  if (start_server)
319  {
320  //The below calls are only needed if creating the server locally in this process
321  char temp[10];
322  snprintf(temp, 10, "%u", server_verbosity);
323  dvs_server_set_option(server_id, "VERBOSE",temp);
324  if (strlen(cache_uri) > 0) dvs_server_set_option(server_id, "CACHE_URI",cache_uri);
325  if (strlen(dvs_file_loc) > 0) dvs_server_set_option(server_id, "DVS_FILE_LOCATION", dvs_file_loc);
326  if (strlen(secret) > 0) dvs_server_set_option(server_id, "SERVER_SECURITY_SECRET", secret);
327  //Non-default values to make sure they are being set
328  dvs_server_set_option(server_id, "GRPC_MAX_NUM_RETRIES", "2");
329  dvs_server_set_option(server_id, "GRPC_BACKOFF_MIN_MS", "120");
330  dvs_server_set_option(server_id, "GRPC_BACKOFF_MAX_MS", "300");
331  dvs_server_set_option(server_id, "GRPC_BACKOFF_LINEAR_MS", "150");
332  dvs_server_start(server_id, server_number, local_ranks);
333  }
334 
335  int32_t session_id = -1;
336  if (dvs_connect(server_id, flags, secret, &session_id) != 0)
337  {
338  fprintf(stderr, "Error making connection to server\n");
339  exit(1);
340  }
341 
342  enum dvs_log_flags log_flags = log_all == 0 ? LOG_UPDATE_BEG_END : LOG_ALL;
343  dvs_register_log_func(session_id, NULL, &logging_function, log_flags);
344 
345  {
346  if (part_info_num != 7 || var_info_num != 7)
347  {
348  fprintf(stderr, "This pseudo client code relies on part infos == 7 and var infos == 7, needs modified otherwise\n");
349  exit(1);
350  }
351 
352  struct TestDynamicData test;
353  test_dynamic_data_init(&test, 0, current_rank, total_ranks);
354  dvs_begin_init(session_id, dataset_id, test.current_rank, test.total_ranks, test.num_chunks);
355  dvs_set_unit_system(session_id, test.unit_system);
356  dvs_add_metadata(session_id, test.metadata_keys, test.metadata_vals, test.metadata_num_pairs);
357 
358  //TODO: Have this done in only the 0th rank once merging definitions is finished
359  if (send_plots && current_rank == plot_rank) dvs_add_plot_info(session_id, test.plots, plot_info_num);
360 
361  if ((total_ranks == 1) || (total_ranks == 2) || all_defs != 0)
362  {
363  //If one rank or two ranks and first rank send everything (tests second rank having no definitions)
364  if (current_rank == 0 || all_defs != 0)
365  {
366  dvs_add_part_info(session_id, test.parts, part_info_num);
367  dvs_add_var_info(session_id, test.vars, send_case_vars ? var_info_num : var_info_num - 1);
368  }
369  }
370  else if (total_ranks == 3)
371  {
372  //If 3 ranks splitup definition data between first 2 ranks
373  //the last rank will not have any (will receive data from others)
374  if (current_rank == 0)
375  {
376  //Send part 0
377  dvs_add_part_info(session_id, test.parts, 1);
378  //Send vars 0->1
379  dvs_add_var_info(session_id, test.vars, 2);
380  }
381  else if (current_rank == 1)
382  {
383  //Send parts 1->2
384  dvs_add_part_info(session_id, &test.parts[1], part_info_num-1);
385  //Send vars 2->5
386  dvs_add_var_info(session_id, &test.vars[2], send_case_vars ? 5 : 4);
387  }
388  //Third rank will have empty definitions which should be filled in
389  }
390  else if (total_ranks > 3)
391  {
392  //If more than 3 ranks splitup data between first 3 ranks
393  //other 3 ranks will not have any (will receive data from others)
394  if (current_rank == 0)
395  {
396  //Send part 0
397  dvs_add_part_info(session_id, test.parts, 1);
398  //Send vars 0->1
399  dvs_add_var_info(session_id, test.vars, 2);
400  }
401  else if (current_rank == 1)
402  {
403  //Send part 1
404  dvs_add_part_info(session_id, &test.parts[1], 1);
405  //Send parts 2->3
406  dvs_add_var_info(session_id, &test.vars[2], 2);
407  }
408  else if (current_rank == 2)
409  {
410  //Send part 2
411  dvs_add_part_info(session_id, &test.parts[2], part_info_num-2);
412  //Send parts 4->5
413  dvs_add_var_info(session_id, &test.vars[4], send_case_vars ? 3 : 2);
414  }
415  }
416  else
417  {
418  //Situation not currently handled exit out
419  fprintf(stderr, "Bad Initialization of Ranks\n");
420  exit(1);
421  }
422 
423  {
424  uint32_t num_part_info = dvs_get_num_part_info(session_id);
425  for (uint32_t i = 0; i < num_part_info; i++)
426  {
427  const struct dvs_part_info* part_info = dvs_get_part_info(session_id, i);
428  if (part_info) fprintf(stderr, "Part: %s ID: %u\n", part_info->_name, part_info->_id);
429  }
430 
431  uint32_t num_var_info = dvs_get_num_var_info(session_id);
432  for (uint32_t i = 0; i < num_var_info; i++)
433  {
434  const struct dvs_var_info* var_info = dvs_get_var_info(session_id, i);
435  if (var_info) fprintf(stderr, "Var: %s ID: %u\n", var_info->_name, var_info->_id);
436  }
437 
438  uint32_t num_plot_info = dvs_get_num_plot_info(session_id);
439  for (uint32_t i = 0; i < num_plot_info; i++)
440  {
441  const struct dvs_plot_info* plot_info = dvs_get_plot_info(session_id, i);
442  if (plot_info) fprintf(stderr, "Plot: %s ID: %u\n", plot_info->_name, plot_info->_id);
443  }
444  }
445 
446  dvs_end_init(session_id);
447  }
448 
449  uint32_t update_num = 0;
450 
451  for (uint32_t i = starting_timestep; i < max_timesteps; i++)
452  {
453  if (i > 1 + starting_timestep && msec_delay)
454  {
455  #ifdef _WIN32
456  Sleep(msec_delay);
457  #else
458  usleep(msec_delay*1000);
459  #endif
460  }
461  if (test_delete && i != starting_timestep) {
462  fprintf(stderr, "Rank: %i of %i Deleting Item\n", (current_rank+1), total_ranks);
463  dvs_delete_item(session_id, update_num++, current_rank, "/timestep.time/gte/0.0");
464  }
465  fprintf(stderr, "Rank: %i of %i Sending Timestep: %i of %i\n", (current_rank), total_ranks, (i), max_timesteps-1);
466 
467  struct TestDynamicData test;
468  test_dynamic_data_init(&test, i, current_rank, total_ranks);
469  test.ghosts = create_ghosts;
470  test_dynamic_data_create_mesh_and_elements(&test, width, height, depth);
471 
472  float solution_time = test.time;
473  if (time_period > 0) {
474  solution_time = (float)(i%time_period);
475  }
476  dvs_begin_update(session_id, update_num++, current_rank, test.current_chunk, solution_time);
477 
478  if (send_structured_parts)
479  {
481  (
482  session_id,
483  test.parts[5]._id,
484  test.pp_global_ijk_max,
485  test.pp_local_ijk_min,
486  test.pp_local_ijk_max,
487  test.pp_origin,
488  test.pp_unit_vec_i,
489  test.pp_unit_vec_j,
490  test.pp_unit_vec_k,
491  test.pp_i_vals,
492  test.pp_j_vals,
493  test.pp_k_vals
494  );
495 
497  (
498  session_id,
499  test.parts[6]._id,
500  test.curv_global_ijk_max,
501  test.curv_local_ijk_min,
502  test.curv_local_ijk_max,
503  test.curv_x_vals,
504  test.curv_y_vals,
505  test.curv_z_vals
506  );
507  }
508 
509  if (send_hex_elems) dvs_update_nodes(session_id, test.parts[0]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
510  if (send_pnt_elems) dvs_update_nodes(session_id, test.parts[1]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
511  if (send_nfaced_elems) dvs_update_nodes(session_id, test.parts[2]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
512  if (send_tri_quad_elems) dvs_update_nodes(session_id, test.parts[3]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
513  if (send_nsided_elems) dvs_update_nodes(session_id, test.parts[4]._id, test.polymesh_x_coords, test.polymesh_y_coords, test.polymesh_z_coords, test.polymesh_coords_size);
514 
515  if (send_elems)
516  {
517  if (send_hex_elems)
518  {
519  dvs_update_elements(session_id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_coords, test.mesh_hex_elem_coords_size);
520  if (test.mesh_hex_ghost_elem_coords_size > 0)
521  {
522  dvs_update_elements(session_id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_coords, test.mesh_hex_ghost_elem_coords_size);
523  }
524  }
525 
526  if (send_nfaced_elems)
527  {
529  (
530  session_id,
531  test.parts[2]._id,
532  CONVEX_POLYHEDRON,
533  test.mesh_nfaced_hex_elem_faces_per_elem,
534  test.mesh_nfaced_hex_elem_faces_per_elem_size,
535  test.mesh_nfaced_hex_elem_nodes_per_face,
536  test.mesh_nfaced_hex_elem_nodes_per_face_size,
537  test.mesh_nfaced_hex_elem_coords,
538  test.mesh_nfaced_hex_elem_coords_size
539  );
540  if (test.mesh_nfaced_hex_ghost_elem_coords_size > 0)
541  {
543  (
544  session_id,
545  test.parts[2]._id,
546  CONVEX_POLYHEDRON_GHOST,
547  test.mesh_nfaced_hex_ghost_elem_faces_per_elem,
548  test.mesh_nfaced_hex_ghost_elem_faces_per_elem_size,
549  test.mesh_nfaced_hex_ghost_elem_nodes_per_face,
550  test.mesh_nfaced_hex_ghost_elem_nodes_per_face_size,
551  test.mesh_nfaced_hex_ghost_elem_coords,
552  test.mesh_nfaced_hex_ghost_elem_coords_size
553  );
554  }
555  }
556 
557  if (send_nsided_elems && current_rank == 0)
558  {
559  //Only send if current rank is 0 as we aren't
560  //splitting this part up based on rank
562  (
563  session_id,
564  test.parts[4]._id,
565  N_SIDED_POLYGON,
566  test.polymesh_elem_nodes_per_face,
567  test.polymesh_elem_nodes_per_face_size,
568  test.polymesh_elem_nodes,
569  test.polymesh_elem_nodes_size
570  );
571  }
572 
573  if (send_pnt_elems) dvs_update_elements(session_id, test.parts[1]._id, PNT, test.mesh_point_elem_coords, test.mesh_point_elem_coords_size);
574 
575  if (send_tri_quad_elems)
576  {
577  dvs_update_elements(session_id, test.parts[3]._id, QUADRANGLE, test.mesh_quad_elem_coords, test.mesh_quad_elem_coords_size);
578  dvs_update_elements(session_id, test.parts[3]._id, TRIANGLE, test.mesh_tri_elem_coords, test.mesh_tri_elem_coords_size);
579  }
580  }
581 
582  if (send_vars)
583  {
584  //Case vars not working correctly with DVS
585  if (send_case_vars) dvs_update_var_case_scalar(session_id, test.vars[6]._id, test.case_var_value);
586  dvs_update_var_part_scalar(session_id, test.vars[4]._id, test.parts[0]._id, test.part_scalar[0]);
587  dvs_update_var_part_scalar(session_id, test.vars[4]._id, test.parts[1]._id, test.part_scalar[1]);
588  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_var_scalar, test.mesh_hex_elem_var_scalar_size);
589  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_var_rank_scalar, test.mesh_hex_elem_var_rank_scalar_size);
590 
591  //N-FACED Elements use the same elemental vars for now as hex elements
592  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[2]._id, CONVEX_POLYHEDRON, test.mesh_hex_elem_var_scalar, test.mesh_hex_elem_var_scalar_size);
593  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[2]._id, CONVEX_POLYHEDRON, test.mesh_hex_elem_var_rank_scalar, test.mesh_hex_elem_var_rank_scalar_size);
594 
595  if (send_structured_parts)
596  {
597  dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[5]._id, STRUCTURED, test.structured_elem_var_scalar, test.structured_elem_var_scalar_size);
598  dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[5]._id, STRUCTURED, test.structured_elem_var_scalar_rank, test.structured_elem_var_scalar_rank_size);
599 
600  dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[6]._id, STRUCTURED, test.structured_elem_var_scalar, test.structured_elem_var_scalar_size);
601  dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[6]._id, STRUCTURED, test.structured_elem_var_scalar_rank, test.structured_elem_var_scalar_rank_size);
602 
603  if (test.structured_elem_ghosts_size > 0)
604  {
605  dvs_update_var_element_scalar(session_id, DVS_STRUCTURED_GHOST_ELEMENTS, test.parts[5]._id, STRUCTURED, test.structured_elem_ghosts, test.structured_elem_ghosts_size);
606  dvs_update_var_element_scalar(session_id, DVS_STRUCTURED_GHOST_ELEMENTS, test.parts[6]._id, STRUCTURED, test.structured_elem_ghosts, test.structured_elem_ghosts_size);
607  }
608  }
609 
610  if (test.mesh_hex_ghost_elem_var_scalar_size > 0)
611  {
612  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_var_scalar, test.mesh_hex_ghost_elem_var_scalar_size);
613  //N-FACED Elements use the same elemental vars for now as hex elements
614  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[2]._id, CONVEX_POLYHEDRON_GHOST, test.mesh_hex_ghost_elem_var_scalar, test.mesh_hex_ghost_elem_var_scalar_size);
615  }
616  if (test.mesh_hex_ghost_elem_var_rank_scalar_size > 0)
617  {
618  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_var_rank_scalar, test.mesh_hex_ghost_elem_var_rank_scalar_size);
619  //N-FACED Elements use the same elemental vars for now as hex elements
620  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[2]._id, CONVEX_POLYHEDRON_GHOST, test.mesh_hex_ghost_elem_var_rank_scalar, test.mesh_hex_ghost_elem_var_rank_scalar_size);
621  }
622 
623  if (send_pnt_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[1]._id, PNT, test.mesh_point_elem_var_rank_scalar, test.mesh_point_elem_var_rank_scalar_size);
624 
625  if (send_nfaced_elems) dvs_update_var_element_vector(session_id, test.vars[3]._id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_var_vector, test.mesh_hex_elem_var_vector_size);
626  if (test.mesh_hex_ghost_elem_var_vector_size > 0)
627  {
628  if (send_nfaced_elems) dvs_update_var_element_vector(session_id, test.vars[3]._id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_var_vector, test.mesh_hex_ghost_elem_var_vector_size);
629  }
630 
631  if (send_tri_quad_elems)
632  {
633  dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[3]._id, QUADRANGLE, test.mesh_quad_elem_var_scalar, test.mesh_quad_elem_var_scalar_size);
634  dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[3]._id, QUADRANGLE, test.mesh_quad_elem_var_rank_scalar, test.mesh_quad_elem_var_rank_scalar_size);
635  dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[3]._id, TRIANGLE, test.mesh_tri_elem_var_scalar, test.mesh_tri_elem_var_scalar_size);
636  dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[3]._id, TRIANGLE, test.mesh_tri_elem_var_rank_scalar, test.mesh_tri_elem_var_rank_scalar_size);
637  }
638 
639  dvs_update_var_node_scalar(session_id, test.vars[0]._id, test.parts[0]._id, test.mesh_node_var_scalar, test.mesh_node_var_scalar_size);
640  dvs_update_var_node_vector(session_id, test.vars[1]._id, test.parts[0]._id, test.mesh_node_var_vector, test.mesh_node_var_vector_size);
641  dvs_update_var_node_scalar(session_id, test.vars[0]._id, test.parts[2]._id, test.mesh_node_var_scalar, test.mesh_node_var_scalar_size);
642  dvs_update_var_node_vector(session_id, test.vars[1]._id, test.parts[2]._id, test.mesh_node_var_vector, test.mesh_node_var_vector_size);
643 
644  if (send_structured_parts)
645  {
646  dvs_update_var_node_scalar(session_id, test.vars[0]._id, test.parts[5]._id, test.structured_nodal_scalar, test.structured_nodal_scalar_size);
647  dvs_update_var_node_scalar(session_id, test.vars[0]._id, test.parts[6]._id, test.structured_nodal_scalar, test.structured_nodal_scalar_size);
648  if (test_iblanking)
649  {
650  dvs_update_var_node_scalar(session_id, DVS_STRUCTURED_IBLANKED_NODES, test.parts[5]._id, test.structured_nodal_iblanked, test.structured_nodal_iblanked_size);
651  dvs_update_var_node_scalar(session_id, DVS_STRUCTURED_IBLANKED_NODES, test.parts[6]._id, test.structured_nodal_iblanked, test.structured_nodal_iblanked_size);
652  }
653  }
654  }
655 
656  if (send_plots && current_rank == plot_rank)
657  {
658  dvs_update_plot(session_id, test.plots[0]._id, test.plot_x_values[0], test.plot_y_values[0], test.plot_num_values);
659  dvs_update_plot(session_id, test.plots[1]._id, test.plot_x_values[1], test.plot_y_values[1], test.plot_num_values);
660  dvs_update_plot(session_id, test.plots[2]._id, test.plot_x_values[2], test.plot_y_values[2], test.plot_num_values);
661  }
662  dvs_end_update(session_id);
663 
664  test_dynamic_data_free(&test);
665  }
666 
667  //Can do 1 timestep at a time with previous changes now
668  int reinit_num_timesteps = 1;
669  if (test_reinit)
670  {
671  for (uint32_t reinit_iter = 0; reinit_iter < 3; reinit_iter++)
672  {
673  fprintf(stderr, "Rank: %i beginning reinit iter: %i\n", current_rank, reinit_iter);
674  struct TestDynamicData test;
675  test_dynamic_data_init(&test, 0, current_rank, total_ranks);
676  dvs_begin_init(session_id, dataset_id, test.current_rank, test.total_ranks, test.num_chunks);
677  dvs_set_unit_system(session_id, test.unit_system);
678  //TODO: Have this done in only the 0th rank once merging definitions is finished
679  if (send_plots && current_rank == plot_rank) dvs_add_plot_info(session_id, test.plots, plot_info_num);
680  if (send_plots && current_rank == plot_rank && reinit_plots) dvs_add_plot_info(session_id, test.reinit_plots, reinit_iter+1);
681 
682  if (reinit_parts) dvs_add_part_info(session_id, test.reinit_parts, reinit_iter+1);
683 
684  if ((total_ranks == 1) || (total_ranks == 2) || all_defs != 0)
685  {
686  //If one rank or two ranks and first rank send everything (tests second rank having no definitions)
687  if (current_rank == 0 || all_defs != 0)
688  {
689  dvs_add_part_info(session_id, test.parts, part_info_num);
690  //Don't send the last var as it is to test re-initializing
691  dvs_add_var_info(session_id, test.vars, send_case_vars ? var_info_num : var_info_num - 1);
692 
693  if (send_case_vars && reinit_vars) dvs_add_var_info(session_id, test.reinit_case_vars, reinit_iter+1);
694  if (send_vars && reinit_vars) dvs_add_var_info(session_id, test.reinit_part_vars, reinit_iter+1);
695  if (send_vars && reinit_vars) dvs_add_var_info(session_id, test.reinit_vars, reinit_iter+1);
696  }
697  }
698  else if (total_ranks == 3)
699  {
700  //If 3 ranks splitup definition data between first 2 ranks
701  //the last rank will not have any (will receive data from others)
702  if (current_rank == 0)
703  {
704  //Send part 0
705  dvs_add_part_info(session_id, test.parts, 1);
706  //Send vars 0->1
707  dvs_add_var_info(session_id, test.vars, 2);
708 
709  if (send_case_vars && reinit_vars) dvs_add_var_info(session_id, test.reinit_case_vars, 1);
710  if (send_vars && reinit_vars) dvs_add_var_info(session_id, test.reinit_vars, reinit_iter+1);
711  }
712  else if (current_rank == 1)
713  {
714  //Send parts 1->2
715  dvs_add_part_info(session_id, &test.parts[1], 4);
716  //Send vars 2->5
717  dvs_add_var_info(session_id, &test.vars[2], send_case_vars ? 6 : 5);
718 
719  if (send_case_vars && reinit_vars) dvs_add_var_info(session_id, test.reinit_case_vars, reinit_iter+2);
720  if (send_vars && reinit_vars) dvs_add_var_info(session_id, test.reinit_part_vars, reinit_iter+1);
721  }
722  //Third rank will have empty definitions which should be filled in
723  }
724  else if (total_ranks > 3)
725  {
726  //If more than 3 ranks splitup data between first 3 ranks
727  //other 3 ranks will not have any (will receive data from others)
728  if (current_rank == 0)
729  {
730  //Send part 0
731  dvs_add_part_info(session_id, test.parts, 1);
732  //Send vars 0->1
733  dvs_add_var_info(session_id, test.vars, 2);
734 
735  if (send_vars && reinit_vars && reinit_iter >= 0) dvs_add_var_info(session_id, &test.reinit_part_vars[0], 1);
736  if (send_vars && reinit_vars) dvs_add_var_info(session_id, test.reinit_vars, reinit_iter+1);
737  }
738  else if (current_rank == 1)
739  {
740  //Send part 1
741  dvs_add_part_info(session_id, &test.parts[1], 1);
742  //Send parts 2->3
743  dvs_add_var_info(session_id, &test.vars[2], 2);
744 
745  if (send_vars && reinit_vars && reinit_iter >= 1) dvs_add_var_info(session_id, &test.reinit_part_vars[1], 1);
746  }
747  else if (current_rank == 2)
748  {
749  //Send part 2
750  dvs_add_part_info(session_id, &test.parts[2], 3);
751  //Send parts 4->5
752  dvs_add_var_info(session_id, &test.vars[4], send_case_vars ? 3 : 2);
753 
754  if (send_case_vars && reinit_vars) dvs_add_var_info(session_id, test.reinit_case_vars, reinit_iter+1);
755  if (send_vars && reinit_vars && reinit_iter >= 2) dvs_add_var_info(session_id, &test.reinit_part_vars[2], 1);
756  }
757  }
758  else
759  {
760  //Situation not currently handled exit out
761  fprintf(stderr, "Bad Initialization of Ranks\n");
762  exit(1);
763  }
764 
765  dvs_end_init(session_id);
766  //Push 2 more timesteps
767  for (uint32_t i = max_timesteps + (reinit_iter * reinit_num_timesteps); i < max_timesteps + ((reinit_iter+1) * reinit_num_timesteps); i++)
768  {
769  if (i > 1 + starting_timestep && msec_delay)
770  {
771  #ifdef _WIN32
772  Sleep(msec_delay);
773  #else
774  usleep(msec_delay*1000);
775  #endif
776  }
777  fprintf
778  (
779  stderr, "Rank: %i of %i Sending Timestep: %i of %i, Reinit: %i\n",
780  (current_rank),
781  total_ranks,
782  i,
783  max_timesteps + ((reinit_iter+1) * reinit_num_timesteps)-1,
784  reinit_iter
785  );
786 
787  struct TestDynamicData test;
788  test_dynamic_data_init(&test, i, current_rank, total_ranks);
789  test.ghosts = create_ghosts;
790  test_dynamic_data_create_mesh_and_elements(&test, width, height, depth);
791 
792  dvs_begin_update(session_id, update_num++, current_rank, test.current_chunk, test.time);
793 
794  if (send_hex_elems) dvs_update_nodes(session_id, test.parts[0]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
795  if (send_pnt_elems) dvs_update_nodes(session_id, test.parts[1]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
796  if (send_nfaced_elems) dvs_update_nodes(session_id, test.parts[2]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
797  if (send_tri_quad_elems) dvs_update_nodes(session_id, test.parts[3]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
798  if (send_nsided_elems) dvs_update_nodes(session_id, test.parts[4]._id, test.polymesh_x_coords, test.polymesh_y_coords, test.polymesh_z_coords, test.polymesh_coords_size);
799 
800  if (send_elems)
801  {
802  if (send_hex_elems)
803  {
804  dvs_update_elements(session_id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_coords, test.mesh_hex_elem_coords_size);
805  if (test.mesh_hex_ghost_elem_coords_size > 0)
806  {
807  dvs_update_elements(session_id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_coords, test.mesh_hex_ghost_elem_coords_size);
808  }
809  }
810 
811  if (send_nfaced_elems)
812  {
814  (
815  session_id,
816  test.parts[2]._id,
817  CONVEX_POLYHEDRON,
818  test.mesh_nfaced_hex_elem_faces_per_elem,
819  test.mesh_nfaced_hex_elem_faces_per_elem_size,
820  test.mesh_nfaced_hex_elem_nodes_per_face,
821  test.mesh_nfaced_hex_elem_nodes_per_face_size,
822  test.mesh_nfaced_hex_elem_coords,
823  test.mesh_nfaced_hex_elem_coords_size
824  );
825  if (test.mesh_nfaced_hex_ghost_elem_coords_size > 0)
826  {
828  (
829  session_id,
830  test.parts[2]._id,
831  CONVEX_POLYHEDRON_GHOST,
832  test.mesh_nfaced_hex_ghost_elem_faces_per_elem,
833  test.mesh_nfaced_hex_ghost_elem_faces_per_elem_size,
834  test.mesh_nfaced_hex_ghost_elem_nodes_per_face,
835  test.mesh_nfaced_hex_ghost_elem_nodes_per_face_size,
836  test.mesh_nfaced_hex_ghost_elem_coords,
837  test.mesh_nfaced_hex_ghost_elem_coords_size
838  );
839  }
840  }
841 
842  if (send_nsided_elems && current_rank == 0)
843  {
844  //Only send if current rank is 0 as we aren't
845  //splitting this part up based on rank
847  (
848  session_id,
849  test.parts[4]._id,
850  N_SIDED_POLYGON,
851  test.polymesh_elem_nodes_per_face,
852  test.polymesh_elem_nodes_per_face_size,
853  test.polymesh_elem_nodes,
854  test.polymesh_elem_nodes_size
855  );
856  }
857 
858  if (send_pnt_elems) dvs_update_elements(session_id, test.parts[1]._id, PNT, test.mesh_point_elem_coords, test.mesh_point_elem_coords_size);
859 
860  if (send_tri_quad_elems)
861  {
862  dvs_update_elements(session_id, test.parts[3]._id, QUADRANGLE, test.mesh_quad_elem_coords, test.mesh_quad_elem_coords_size);
863  dvs_update_elements(session_id, test.parts[3]._id, TRIANGLE, test.mesh_tri_elem_coords, test.mesh_tri_elem_coords_size);
864  }
865  }
866 
867  if (send_vars)
868  {
869  //Case vars not working correctly with DVS
870  if (send_case_vars) dvs_update_var_case_scalar(session_id, test.vars[6]._id, test.case_var_value);
871  if (send_case_vars && reinit_vars && reinit_iter >= 0) dvs_update_var_case_scalar(session_id, test.reinit_case_vars[0]._id, (test.case_var_value*-1.f));
872  if (send_case_vars && reinit_vars && reinit_iter >= 1) dvs_update_var_case_scalar(session_id, test.reinit_case_vars[1]._id, (test.case_var_value*-1.f)-10.f);
873  if (send_case_vars && reinit_vars && reinit_iter >= 2) dvs_update_var_case_scalar(session_id, test.reinit_case_vars[2]._id, (test.case_var_value*-1.f)-20.f);
874  dvs_update_var_part_scalar(session_id, test.vars[4]._id, test.parts[0]._id, test.part_scalar[0]);
875  dvs_update_var_part_scalar(session_id, test.vars[4]._id, test.parts[1]._id, test.part_scalar[1]);
876  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_var_scalar, test.mesh_hex_elem_var_scalar_size);
877  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_var_rank_scalar, test.mesh_hex_elem_var_rank_scalar_size);
878 
879  //N-FACED Elements use the same elemental vars for now as hex elements
880  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[2]._id, CONVEX_POLYHEDRON, test.mesh_hex_elem_var_scalar, test.mesh_hex_elem_var_scalar_size);
881  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[2]._id, CONVEX_POLYHEDRON, test.mesh_hex_elem_var_rank_scalar, test.mesh_hex_elem_var_rank_scalar_size);
882 
883  if (test.mesh_hex_ghost_elem_var_scalar_size > 0)
884  {
885  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_var_scalar, test.mesh_hex_ghost_elem_var_scalar_size);
886  //N-FACED Elements use the same elemental vars for now as hex elements
887  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[2]._id, CONVEX_POLYHEDRON_GHOST, test.mesh_hex_ghost_elem_var_scalar, test.mesh_hex_ghost_elem_var_scalar_size);
888  }
889  if (test.mesh_hex_ghost_elem_var_rank_scalar_size > 0)
890  {
891  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_var_rank_scalar, test.mesh_hex_ghost_elem_var_rank_scalar_size);
892  //N-FACED Elements use the same elemental vars for now as hex elements
893  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[2]._id, CONVEX_POLYHEDRON_GHOST, test.mesh_hex_ghost_elem_var_rank_scalar, test.mesh_hex_ghost_elem_var_rank_scalar_size);
894  }
895 
896  if (send_pnt_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[1]._id, PNT, test.mesh_point_elem_var_rank_scalar, test.mesh_point_elem_var_rank_scalar_size);
897 
898  if (send_nfaced_elems) dvs_update_var_element_vector(session_id, test.vars[3]._id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_var_vector, test.mesh_hex_elem_var_vector_size);
899  if (test.mesh_hex_ghost_elem_var_vector_size > 0)
900  {
901  if (send_nfaced_elems) dvs_update_var_element_vector(session_id, test.vars[3]._id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_var_vector, test.mesh_hex_ghost_elem_var_vector_size);
902  }
903 
904  if (send_tri_quad_elems)
905  {
906  dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[3]._id, QUADRANGLE, test.mesh_quad_elem_var_scalar, test.mesh_quad_elem_var_scalar_size);
907  dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[3]._id, QUADRANGLE, test.mesh_quad_elem_var_rank_scalar, test.mesh_quad_elem_var_rank_scalar_size);
908  dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[3]._id, TRIANGLE, test.mesh_tri_elem_var_scalar, test.mesh_tri_elem_var_scalar_size);
909  dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[3]._id, TRIANGLE, test.mesh_tri_elem_var_rank_scalar, test.mesh_tri_elem_var_rank_scalar_size);
910  }
911 
912  dvs_update_var_node_scalar(session_id, test.vars[0]._id, test.parts[0]._id, test.mesh_node_var_scalar, test.mesh_node_var_scalar_size);
913  dvs_update_var_node_vector(session_id, test.vars[1]._id, test.parts[0]._id, test.mesh_node_var_vector, test.mesh_node_var_vector_size);
914  dvs_update_var_node_scalar(session_id, test.vars[0]._id, test.parts[2]._id, test.mesh_node_var_scalar, test.mesh_node_var_scalar_size);
915  dvs_update_var_node_vector(session_id, test.vars[1]._id, test.parts[2]._id, test.mesh_node_var_vector, test.mesh_node_var_vector_size);
916  }
917 
918  if (send_plots && current_rank == plot_rank)
919  {
920  dvs_update_plot(session_id, test.plots[0]._id, test.plot_x_values[0], test.plot_y_values[0], test.plot_num_values);
921  dvs_update_plot(session_id, test.plots[1]._id, test.plot_x_values[1], test.plot_y_values[1], test.plot_num_values);
922  dvs_update_plot(session_id, test.plots[2]._id, test.plot_x_values[2], test.plot_y_values[2], test.plot_num_values);
923  if (reinit_plots && reinit_iter >= 0) dvs_update_plot(session_id, test.reinit_plots[0]._id, test.plot_x_values[0], test.plot_y_values[0], test.plot_num_values);
924  if (reinit_plots && reinit_iter >= 1) dvs_update_plot(session_id, test.reinit_plots[1]._id, test.plot_x_values[1], test.plot_y_values[1], test.plot_num_values);
925  if (reinit_plots && reinit_iter >= 2) dvs_update_plot(session_id, test.reinit_plots[2]._id, test.plot_x_values[2], test.plot_y_values[2], test.plot_num_values);
926  }
927  dvs_end_update(session_id);
928 
929  test_dynamic_data_free(&test);
930  }
931  }
932  }
933 
934  //Don't look below here, thar be dragons (this whole thing needs moved to python)
935  /*
936  if (test_reinit)
937  {
938  reinit_num_timesteps = 1;
939  uint32_t current_part_id = 1000;
940  uint32_t current_plot_id = 2000;
941  uint32_t current_var_id = 3000;
942  for (uint32_t reinit_iter = 3; reinit_iter < 50; reinit_iter++)
943  {
944  fprintf(stderr, "Rank: %i beginning reinit iter: %i\n", current_rank, reinit_iter);
945  struct TestDynamicData test;
946  test_dynamic_data_init(&test, 0, current_rank, total_ranks);
947  dvs_begin_init(session_id, dataset_id, test.current_rank, test.total_ranks, test.num_chunks);
948  dvs_set_unit_system(session_id, test.unit_system);
949 
950  if (send_plots && current_rank == plot_rank && reinit_plots)
951  {
952  struct dvs_plot_info plot_info;
953  memset(&plot_info, 0, sizeof(plot_info));
954  plot_info._id = current_plot_id++;
955  char plot_name[1000];
956  sprintf(plot_name, "Reinit-Plot-%u\0", current_plot_id-1);
957  plot_info._name = strdup(plot_name);
958 
959  dvs_add_plot_info(session_id, &plot_info, 1);
960  free(plot_info._name);
961  }
962 
963  if (reinit_parts)
964  {
965  struct dvs_part_info part_info;
966  memset(&part_info, 0, sizeof(part_info));
967  part_info._id = current_part_id++;
968  char part_name[1000];
969  sprintf(part_name, "Reinit-Part-%u\0", current_part_id-1);
970  part_info._name = strdup(part_name);
971  dvs_add_part_info(session_id, &part_info, 1);
972  free(part_info._name);
973  }
974 
975  if (reinit_vars)
976  {
977  struct dvs_var_info var_info;
978  memset(&var_info, 0, sizeof(var_info));
979 
980  var_info._id = current_var_id++;
981  char var_name[1000];
982  sprintf(var_name, "Reinit-Var-%u\0", current_var_id-1);
983  var_info._name = strdup(var_name);
984  var_info._location = NODE;
985  var_info._type = SCALAR;
986  dvs_add_var_info(session_id, &var_info, 1);
987  free(var_info._name);
988  }
989 
990  dvs_end_init(session_id);
991  //Push 2 more timesteps
992  for (uint32_t i = max_timesteps + (reinit_iter * reinit_num_timesteps); i < max_timesteps + ((reinit_iter+1) * reinit_num_timesteps); i++)
993  {
994  if (i > 1 + starting_timestep && msec_delay)
995  {
996  #ifdef _WIN32
997  Sleep(msec_delay);
998  #else
999  usleep(msec_delay*1000);
1000  #endif
1001  }
1002  fprintf
1003  (
1004  stderr, "Rank: %i of %i Sending Timestep: %i of %i, Reinit: %i\n",
1005  (current_rank),
1006  total_ranks,
1007  i,
1008  max_timesteps + ((reinit_iter+1) * reinit_num_timesteps)-1,
1009  reinit_iter
1010  );
1011 
1012  struct TestDynamicData test;
1013  test_dynamic_data_init(&test, i, current_rank, total_ranks);
1014  test.ghosts = create_ghosts;
1015  test_dynamic_data_create_mesh_and_elements(&test, width, height, depth);
1016 
1017  dvs_begin_update(session_id, update_num++, current_rank, test.current_chunk, test.time);
1018 
1019  if (send_hex_elems) dvs_update_nodes(session_id, test.parts[0]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
1020  if (send_pnt_elems) dvs_update_nodes(session_id, test.parts[1]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
1021  if (send_nfaced_elems) dvs_update_nodes(session_id, test.parts[2]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
1022  if (send_tri_quad_elems) dvs_update_nodes(session_id, test.parts[3]._id, test.mesh_x_coords, test.mesh_y_coords, test.mesh_z_coords, test.mesh_coords_size);
1023  if (send_nsided_elems) dvs_update_nodes(session_id, test.parts[4]._id, test.polymesh_x_coords, test.polymesh_y_coords, test.polymesh_z_coords, test.polymesh_coords_size);
1024 
1025  if (send_elems)
1026  {
1027  if (send_hex_elems)
1028  {
1029  dvs_update_elements(session_id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_coords, test.mesh_hex_elem_coords_size);
1030  if (test.mesh_hex_ghost_elem_coords_size > 0)
1031  {
1032  dvs_update_elements(session_id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_coords, test.mesh_hex_ghost_elem_coords_size);
1033  }
1034  }
1035 
1036  if (send_nfaced_elems)
1037  {
1038  dvs_update_elements_polyhedral
1039  (
1040  session_id,
1041  test.parts[2]._id,
1042  CONVEX_POLYHEDRON,
1043  test.mesh_nfaced_hex_elem_faces_per_elem,
1044  test.mesh_nfaced_hex_elem_faces_per_elem_size,
1045  test.mesh_nfaced_hex_elem_nodes_per_face,
1046  test.mesh_nfaced_hex_elem_nodes_per_face_size,
1047  test.mesh_nfaced_hex_elem_coords,
1048  test.mesh_nfaced_hex_elem_coords_size
1049  );
1050  if (test.mesh_nfaced_hex_ghost_elem_coords_size > 0)
1051  {
1052  dvs_update_elements_polyhedral
1053  (
1054  session_id,
1055  test.parts[2]._id,
1056  CONVEX_POLYHEDRON_GHOST,
1057  test.mesh_nfaced_hex_ghost_elem_faces_per_elem,
1058  test.mesh_nfaced_hex_ghost_elem_faces_per_elem_size,
1059  test.mesh_nfaced_hex_ghost_elem_nodes_per_face,
1060  test.mesh_nfaced_hex_ghost_elem_nodes_per_face_size,
1061  test.mesh_nfaced_hex_ghost_elem_coords,
1062  test.mesh_nfaced_hex_ghost_elem_coords_size
1063  );
1064  }
1065  }
1066 
1067  if (send_nsided_elems && current_rank == 0)
1068  {
1069  //Only send if current rank is 0 as we aren't
1070  //splitting this part up based on rank
1071  dvs_update_elements_polygon
1072  (
1073  session_id,
1074  test.parts[4]._id,
1075  N_SIDED_POLYGON,
1076  test.polymesh_elem_nodes_per_face,
1077  test.polymesh_elem_nodes_per_face_size,
1078  test.polymesh_elem_nodes,
1079  test.polymesh_elem_nodes_size
1080  );
1081  }
1082 
1083  if (send_pnt_elems) dvs_update_elements(session_id, test.parts[1]._id, PNT, test.mesh_point_elem_coords, test.mesh_point_elem_coords_size);
1084 
1085  if (send_tri_quad_elems)
1086  {
1087  dvs_update_elements(session_id, test.parts[3]._id, QUADRANGLE, test.mesh_quad_elem_coords, test.mesh_quad_elem_coords_size);
1088  dvs_update_elements(session_id, test.parts[3]._id, TRIANGLE, test.mesh_tri_elem_coords, test.mesh_tri_elem_coords_size);
1089  }
1090  }
1091 
1092  if (send_vars)
1093  {
1094  //Case vars not working correctly with DVS
1095  if (send_case_vars) dvs_update_var_case_scalar(session_id, test.vars[6]._id, test.case_var_value);
1096  if (send_case_vars && reinit_vars && reinit_iter >= 0) dvs_update_var_case_scalar(session_id, test.reinit_case_vars[0]._id, (test.case_var_value*-1.f));
1097  if (send_case_vars && reinit_vars && reinit_iter >= 1) dvs_update_var_case_scalar(session_id, test.reinit_case_vars[1]._id, (test.case_var_value*-1.f)-10.f);
1098  if (send_case_vars && reinit_vars && reinit_iter >= 2) dvs_update_var_case_scalar(session_id, test.reinit_case_vars[2]._id, (test.case_var_value*-1.f)-20.f);
1099  dvs_update_var_part_scalar(session_id, test.vars[4]._id, test.parts[0]._id, test.part_scalar[0]);
1100  dvs_update_var_part_scalar(session_id, test.vars[4]._id, test.parts[1]._id, test.part_scalar[1]);
1101  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_var_scalar, test.mesh_hex_elem_var_scalar_size);
1102  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_var_rank_scalar, test.mesh_hex_elem_var_rank_scalar_size);
1103 
1104  //N-FACED Elements use the same elemental vars for now as hex elements
1105  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[2]._id, CONVEX_POLYHEDRON, test.mesh_hex_elem_var_scalar, test.mesh_hex_elem_var_scalar_size);
1106  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[2]._id, CONVEX_POLYHEDRON, test.mesh_hex_elem_var_rank_scalar, test.mesh_hex_elem_var_rank_scalar_size);
1107 
1108  if (test.mesh_hex_ghost_elem_var_scalar_size > 0)
1109  {
1110  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_var_scalar, test.mesh_hex_ghost_elem_var_scalar_size);
1111  //N-FACED Elements use the same elemental vars for now as hex elements
1112  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[2]._id, CONVEX_POLYHEDRON_GHOST, test.mesh_hex_ghost_elem_var_scalar, test.mesh_hex_ghost_elem_var_scalar_size);
1113  }
1114  if (test.mesh_hex_ghost_elem_var_rank_scalar_size > 0)
1115  {
1116  if (send_hex_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_var_rank_scalar, test.mesh_hex_ghost_elem_var_rank_scalar_size);
1117  //N-FACED Elements use the same elemental vars for now as hex elements
1118  if (send_nfaced_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[2]._id, CONVEX_POLYHEDRON_GHOST, test.mesh_hex_ghost_elem_var_rank_scalar, test.mesh_hex_ghost_elem_var_rank_scalar_size);
1119  }
1120 
1121  if (send_pnt_elems) dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[1]._id, PNT, test.mesh_point_elem_var_rank_scalar, test.mesh_point_elem_var_rank_scalar_size);
1122 
1123  if (send_nfaced_elems) dvs_update_var_element_vector(session_id, test.vars[3]._id, test.parts[0]._id, HEXAHEDRON, test.mesh_hex_elem_var_vector, test.mesh_hex_elem_var_vector_size);
1124  if (test.mesh_hex_ghost_elem_var_vector_size > 0)
1125  {
1126  if (send_nfaced_elems) dvs_update_var_element_vector(session_id, test.vars[3]._id, test.parts[0]._id, HEXAHEDRON_GHOST, test.mesh_hex_ghost_elem_var_vector, test.mesh_hex_ghost_elem_var_vector_size);
1127  }
1128 
1129  if (send_tri_quad_elems)
1130  {
1131  dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[3]._id, QUADRANGLE, test.mesh_quad_elem_var_scalar, test.mesh_quad_elem_var_scalar_size);
1132  dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[3]._id, QUADRANGLE, test.mesh_quad_elem_var_rank_scalar, test.mesh_quad_elem_var_rank_scalar_size);
1133  dvs_update_var_element_scalar(session_id, test.vars[2]._id, test.parts[3]._id, TRIANGLE, test.mesh_tri_elem_var_scalar, test.mesh_tri_elem_var_scalar_size);
1134  dvs_update_var_element_scalar(session_id, test.vars[5]._id, test.parts[3]._id, TRIANGLE, test.mesh_tri_elem_var_rank_scalar, test.mesh_tri_elem_var_rank_scalar_size);
1135  }
1136 
1137  dvs_update_var_node_scalar(session_id, test.vars[0]._id, test.parts[0]._id, test.mesh_node_var_scalar, test.mesh_node_var_scalar_size);
1138  dvs_update_var_node_vector(session_id, test.vars[1]._id, test.parts[0]._id, test.mesh_node_var_vector, test.mesh_node_var_vector_size);
1139  dvs_update_var_node_scalar(session_id, test.vars[0]._id, test.parts[2]._id, test.mesh_node_var_scalar, test.mesh_node_var_scalar_size);
1140  dvs_update_var_node_vector(session_id, test.vars[1]._id, test.parts[2]._id, test.mesh_node_var_vector, test.mesh_node_var_vector_size);
1141  }
1142 
1143  if (send_plots && current_rank == plot_rank)
1144  {
1145  dvs_update_plot(session_id, test.plots[0]._id, test.plot_x_values[0], test.plot_y_values[0], test.plot_num_values);
1146  dvs_update_plot(session_id, test.plots[1]._id, test.plot_x_values[1], test.plot_y_values[1], test.plot_num_values);
1147  dvs_update_plot(session_id, test.plots[2]._id, test.plot_x_values[2], test.plot_y_values[2], test.plot_num_values);
1148  if (reinit_plots && reinit_iter >= 0) dvs_update_plot(session_id, test.reinit_plots[0]._id, test.plot_x_values[0], test.plot_y_values[0], test.plot_num_values);
1149  if (reinit_plots && reinit_iter >= 1) dvs_update_plot(session_id, test.reinit_plots[1]._id, test.plot_x_values[1], test.plot_y_values[1], test.plot_num_values);
1150  if (reinit_plots && reinit_iter >= 2) dvs_update_plot(session_id, test.reinit_plots[2]._id, test.plot_x_values[2], test.plot_y_values[2], test.plot_num_values);
1151  }
1152  dvs_end_update(session_id);
1153 
1154  test_dynamic_data_free(&test);
1155  }
1156  }
1157  }*/
1158  dvs_print_stats(session_id);
1159  if (start_server)
1160  {
1161  //If we started our own server wait for the pending timesteps to clear before tearing everything down
1162  //in case it was writing stuff.
1163 
1164  //Not waiting isn't a problem but if we had another process connecting to this
1165  //process' server and sending data we might lose the last timestep since it won't be
1166  //fully complete and we would not have written it yet.
1167  uint32_t num_pending = 1;
1168  uint32_t num_complete = 0;
1169  while (num_pending > 0) {
1170  dvs_ret error = dvs_server_timestep_count(server_id, &num_pending, &num_complete);
1171  if (error != DVS_NONE) break;
1172  // Avoid burning up a CPU waiting for the I/O to complete
1173  const uint32_t temp_delay_ms = 50;
1174 #ifdef _WIN32
1175  Sleep(temp_delay_ms);
1176 #else
1177  usleep(temp_delay_ms * 1000);
1178 #endif
1179  }
1180  }
1181  dvs_shutdown();
1182  return 0;
1183 }
C API for using Dynamic Visualization Store.
DVS_DLL_EXPORT const struct dvs_var_info * dvs_get_var_info(int32_t session_id, uint32_t index)
Get the dvs_var_info object for this index.
DVS_DLL_EXPORT dvs_ret dvs_update_elements(int32_t session_id, uint32_t part_id, enum dvs_element_type type, const uint32_t *indices, uint32_t num_indices)
Update elements for a specific part and element type.
DVS_DLL_EXPORT dvs_ret dvs_server_create(const char *server_uri, int32_t *server_id)
Create a Dynamic Visualization Store server instance for the client to connect.
DVS_DLL_EXPORT dvs_ret dvs_add_var_info(int32_t session_id, const struct dvs_var_info *vars, uint32_t num_vars)
Add var info for simulation.
DVS_DLL_EXPORT dvs_ret dvs_update_nodes_parallelepiped(int32_t session_id, uint32_t part_id, const uint32_t global_ijk_max[3], const uint32_t local_ijk_min[3], const uint32_t local_ijk_max[3], const float origin[3], const float dir_i[3], const float dir_j[3], const float dir_k[3], const float *i_vals, const float *j_vals, const float *k_vals)
Update the nodes for a parallelepiped structured part.
DVS_DLL_EXPORT const struct dvs_plot_info * dvs_get_plot_info(int32_t session_id, uint32_t index)
Get the dvs_plot_info object for this index.
DVS_DLL_EXPORT dvs_ret dvs_set_unit_system(int32_t session_id, const char *system)
Set a unit system (optional but recommended)
DVS_DLL_EXPORT const char * dvs_get_version()
Get the current version of the built library.
DVS_DLL_EXPORT dvs_ret dvs_print_stats(int32_t session_id)
This will be deprecated, just placeholder for printing out stats that the client is collecting for pr...
DVS_DLL_EXPORT dvs_ret dvs_begin_init(int32_t session_id, const char *dataset_name, uint32_t current_rank, uint32_t total_ranks, uint32_t num_chunks)
begin setup of rank
DVS_DLL_EXPORT dvs_ret dvs_update_plot(int32_t session_id, uint32_t plot_id, const float *x_values, const float *y_values, uint32_t num_values)
Update the data for a plot.
DVS_DLL_EXPORT dvs_ret dvs_add_part_info(int32_t session_id, const struct dvs_part_info *parts, uint32_t num_parts)
Add part info for simulation.
DVS_DLL_EXPORT dvs_ret dvs_delete_item(int32_t session_id, uint32_t update_num, uint32_t rank, const char *filter)
Delete an item.
DVS_DLL_EXPORT uint32_t dvs_get_num_part_info(int32_t session_id)
Get the number of dvs_part_info objects for this client session.
DVS_DLL_EXPORT dvs_ret dvs_update_elements_polygon(int32_t session_id, uint32_t part_id, enum dvs_element_type type, const uint32_t *nodes_per_polygon, uint32_t nodes_per_polygon_size, const uint32_t *indices, uint32_t indices_size)
Update N-SIDED elements.
DVS_DLL_EXPORT dvs_ret dvs_update_nodes(int32_t session_id, uint32_t part_id, const float *x, const float *y, const float *z, uint32_t num_values)
Update nodes for a specific part.
DVS_DLL_EXPORT void dvs_shutdown()
Shuts down the api, performing any necessary cleanup, also calls dvs_server_shutdown_all() if any ser...
DVS_DLL_EXPORT dvs_ret dvs_update_var_part_scalar(int32_t session_id, uint32_t var_id, uint32_t part_id, float scalar)
Update value of part scalar.
DVS_DLL_EXPORT dvs_ret dvs_update_var_node_vector(int32_t session_id, uint32_t var_id, uint32_t part_id, const float *values, uint32_t num_values)
Update a field of vectors on nodes.
DVS_DLL_EXPORT uint32_t dvs_get_num_plot_info(int32_t session_id)
Get the number of dvs_plot_info objects for this client session.
DVS_DLL_EXPORT dvs_ret dvs_server_start(int32_t server_id, uint32_t server_number, uint32_t local_ranks)
Start a Dynamic Visualization Store server in a separate thread to receive data from solver node.
DVS_DLL_EXPORT dvs_ret dvs_begin_update(int32_t session_id, uint32_t update_num, uint32_t rank, uint32_t chunk, float time)
Method to begin an update.
DVS_DLL_EXPORT dvs_ret dvs_update_var_element_scalar(int32_t session_id, uint32_t var_id, uint32_t part_id, enum dvs_element_type type, const float *scalars, uint32_t num_vals)
Update a field of scalars on elements.
DVS_DLL_EXPORT const struct dvs_part_info * dvs_get_part_info(int32_t session_id, uint32_t index)
Get the dvs_part_info object for this index.
DVS_DLL_EXPORT dvs_ret dvs_connect(int32_t server_id, enum dvs_client_flags flags, const char *secret, int32_t *session_id)
Connect to dvs server.
DVS_DLL_EXPORT dvs_ret dvs_end_init(int32_t session_id)
end the initialization of the rank
DVS_DLL_EXPORT dvs_ret dvs_add_metadata(int32_t session_id, const char *const metadata_keys[], const char *const metadata_vals[], uint32_t num_metadata_pairs)
Add metadata for the current dataset.
DVS_DLL_EXPORT uint32_t dvs_get_num_var_info(int32_t session_id)
Get the number of dvs_var_info objects for this client session.
DVS_DLL_EXPORT dvs_ret dvs_update_var_case_scalar(int32_t session_id, uint32_t var_id, float scalar)
Update value of case scalar.
DVS_DLL_EXPORT dvs_ret dvs_server_timestep_count(int32_t server_id, uint32_t *num_pending, uint32_t *num_complete)
Query a Dynamic Visualization Store server as to the number of timesteps it contains.
DVS_DLL_EXPORT dvs_ret dvs_register_log_func(int32_t session_id, void *user_data, dvs_log_func func, enum dvs_log_flags flags)
Register logging function for client to call (optional but recommended)
DVS_DLL_EXPORT dvs_ret dvs_end_update(int32_t session_id)
Call to end the update for this timestep/rank/chunk.
DVS_DLL_EXPORT dvs_ret dvs_server_set_option(int32_t server_id, const char *key, const char *value)
Add an option to the server.
DVS_DLL_EXPORT dvs_ret dvs_update_var_node_scalar(int32_t session_id, uint32_t var_id, uint32_t part_id, const float *scalars, uint32_t num_vals)
Update a field of scalars on nodes.
DVS_DLL_EXPORT dvs_ret dvs_update_var_element_vector(int32_t session_id, uint32_t var_id, uint32_t part_id, enum dvs_element_type type, const float *values, uint32_t num_values)
Update a field of vectors on elements.
DVS_DLL_EXPORT dvs_ret dvs_update_nodes_curvilinear(int32_t session_id, uint32_t part_id, const uint32_t global_ijk_max[3], const uint32_t local_ijk_min[3], const uint32_t local_ijk_max[3], const float *x_vals, const float *y_vals, const float *z_vals)
Update the nodes for a curvilinear structured part.
DVS_DLL_EXPORT dvs_ret dvs_add_plot_info(int32_t session_id, const struct dvs_plot_info *plots, uint32_t num_plots)
Add plot info for simulation.
DVS_DLL_EXPORT dvs_ret dvs_update_elements_polyhedral(int32_t session_id, uint32_t part_id, enum dvs_element_type type, const uint32_t *faces_per_element, uint32_t faces_per_element_size, const uint32_t *nodes_per_face, uint32_t nodes_per_face_size, const uint32_t *indices, uint32_t indices_size)
Update N-FACED Elements.
Contains enums used in C/C++ API.
#define DVS_STRUCTURED_GHOST_ELEMENTS
dvs_log_flags
Flags to control logging filters.
@ LOG_UPDATE_BEG_END
Log messages related to begin and end of updates.
@ LOG_ALL
Log all messages.
#define DVS_STRUCTURED_IBLANKED_NODES
dvs_client_flags
Flags for specific server setup.
@ DEDUP
Do not send duplicate data to server.
@ BEGIN_INIT_WAIT_ON_REINIT
Blocking wait on reinitialization to complete before reinitializing again.
@ BLOCK_FOR_SERVER
Clients should block for servers to be initialized before sending data.
int32_t dvs_ret
Return value of methods, TODO.
#define DVS_NONE
No detected error has occurred.
Struct holding information for a part's definition.
char * _name
UTF-8 Compatible name of part [null terminated], max name length visible in GUI == 79,...
uint32_t _id
Unique identifier for part, MUST BE > 0.
Struct holding information for a plot's definition.
char * _name
UTF-8 Compatible name for plot, must be unique from other plot names.
uint32_t _id
Unique id for plot.
Struct holding information for a variable's definiton.
uint32_t _id
Unique id for variable.
char * _name
UTF-8 Compatible name of variable [null terminated], max name length visible in the GUI == 49,...
int main(int argc, char **argv)
Main method of test client application.