7.4.1. Reading Files in Parallel

To copy a file from the host to nodes, before reading it within parallel UDFs, use the following function:

host_to_node_sync_file(const char* filename); 

This handles the situation (for example, within ANSYS Fluent UDFs) when the current working directory is not shared between the host and the nodes. For the host, the input argument filename is the path to the file that is to be copied to the nodes. For the nodes, the input argument is the directory on the nodes under which the file is copied. Upon successful completion, host_to_node_sync_file() returns the number of bytes copied, otherwise, -1 is returned.

Example

In the following example, the host process on Windows copies the file from its local directory e:\udfs\test.bat to the directory /tmp on the remote Linux nodes.

DEFINE_ON_DEMAND(host_to_node_sync)
{
#if PARALLEL
#if RP_HOST
  int total_bytes_copied = host_to_node_sync_file("e:\\udfs\\test.dat");
#endif
#if RP_NODE
  int total_bytes_copied = host_to_node_sync_file("/tmp");
  /* The file /tmp/test.dat can be opened now */
#endif
  printf("Total number of bytes copied is %d\n", total_bytes_copied);
#endif
}

Release 18.2 - © ANSYS, Inc. All rights reserved.