Thread private data support

## Functions

void | __kmpc_copyprivate (ident_t *loc, kmp_int32 gtid, size_t cpy_size, void *cpy_data, void(*cpy_func)(void *, void *), kmp_int32 didit)
void | __kmpc_threadprivate_register (ident_t *loc, void *data, kmpc_ctor ctor, kmpc_cctor cctor, kmpc_dtor dtor)
void * | __kmpc_threadprivate_cached (ident_t *loc, kmp_int32 global_tid, void *data, size_t size, void ***cache)
void | __kmpc_threadprivate_register_vec (ident_t *loc, void *data, kmpc_ctor_vec ctor, kmpc_cctor_vec cctor, kmpc_dtor_vec dtor, size_t vector_length)
typedef void *(* | kmpc_ctor) (void *)
typedef void(* | kmpc_dtor) (void *)
typedef void *(* | kmpc_cctor) (void *, void *)
typedef void *(* | kmpc_ctor_vec) (void *, size_t)
typedef void(* | kmpc_dtor_vec) (void *, size_t)
typedef void *(* | kmpc_cctor_vec) (void *, void *, size_t)

## Detailed Description

These functions support copyin/out and thread private data.

## Typedef Documentation

typedef void*(* kmpc_cctor) (void *, void *)

Pointer to an alternate constructor. The first argument is the `this` pointer.

Definition at line 1456 of file kmp.h.

typedef void*(* kmpc_cctor_vec) (void *, void *, size_t)

Array constructor. First argument is the `this` pointer Third argument the number of array elements.

Definition at line 1478 of file kmp.h.

typedef void*(* kmpc_ctor) (void *)

Pointer to the constructor function. The first argument is the `this` pointer

Definition at line 1443 of file kmp.h.

typedef void*(* kmpc_ctor_vec) (void *, size_t)

Array constructor. First argument is the `this` pointer Second argument the number of array elements.

Definition at line 1466 of file kmp.h.

typedef void(* kmpc_dtor) (void *)

Pointer to the destructor function. The first argument is the `this` pointer

Definition at line 1449 of file kmp.h.

typedef void(* kmpc_dtor_vec) (void *, size_t)

Pointer to the array destructor function. The first argument is the `this` pointer Second argument the number of array elements.

Definition at line 1472 of file kmp.h.

## Function Documentation

void __kmpc_copyprivate | ( | ident_t * | loc,
|  | kmp_int32 | gtid,
|  | size_t | cpy_size,
|  | void * | cpy_data,
|  | void(*)(void *, void *) | cpy_func,
|  | kmp_int32 | didit
| ) |  |

Parameters

  loc | source location information
  gtid | global thread number
  cpy_size | size of the cpy_data buffer
  cpy_data | pointer to data to be copied
  cpy_func | helper function to call for copying data
  didit | flag variable: 1=single thread; 0=not single thread

__kmpc_copyprivate implements the interface for the private data broadcast needed for the copyprivate clause associated with a single region in an OpenMP* program (both C and Fortran). All threads participating in the parallel region call this routine. One of the threads (called the single thread) should have the `didit` variable set to 1 and all other threads should have that variable set to 0. All threads pass a pointer to a data buffer (cpy_data) that they have built.

The OpenMP specification forbids the use of nowait on the single region when a copyprivate clause is present. However, __kmpc_copyprivate implements a barrier internally to avoid race conditions, so the code generation for the single region should avoid generating a barrier after the call to __kmpc_copyprivate.

The `gtid` parameter is the global thread id for the current thread. The `loc` parameter is a pointer to source location information.

Internal implementation: The single thread will first copy its descriptor address (cpy_data) to a team-private location, then the other threads will each call the function pointed to by the parameter cpy_func, which carries out the copy by copying the data using the cpy_data buffer.

The cpy_func routine used for the copy and the contents of the data area defined by cpy_data and cpy_size may be built in any fashion that will allow the copy to be done. For instance, the cpy_data buffer can hold the actual data to be copied or it may hold a list of pointers to the data. The cpy_func routine must interpret the cpy_data buffer appropriately.

The interface to cpy_func is as follows:

void cpy_func( void *destination, void *source )

where void *destination is the cpy_data pointer for the thread being copied to and void *source is the cpy_data pointer for the thread being copied from.

Definition at line 2039 of file kmp_csupport.cpp.

void* __kmpc_threadprivate_cached | ( | ident_t * | loc,
|  | kmp_int32 | global_tid,
|  | void * | data,
|  | size_t | size,
|  | void *** | cache
| ) |  |

Parameters

  loc | source location information
  global_tid | global thread number
  data | pointer to data to privatize
  size | size of data to privatize
  cache | pointer to cache

Returns
  pointer to private storage

Allocate private storage for threadprivate data.

Definition at line 616 of file kmp_threadprivate.cpp.

void __kmpc_threadprivate_register | ( | ident_t * | loc,
|  | void * | data,
|  | kmpc_ctor | ctor,
|  | kmpc_cctor | cctor,
|  | kmpc_dtor | dtor
| ) |  |

Parameters

  loc | source location information
  data | pointer to data being privatized
  ctor | pointer to constructor function for data
  cctor | pointer to copy constructor function for data
  dtor | pointer to destructor function for data

Register constructors and destructors for thread private data. This function is called when executing in parallel, when we know the thread id.

Definition at line 506 of file kmp_threadprivate.cpp.

void __kmpc_threadprivate_register_vec | ( | ident_t * | loc,
|  | void * | data,
|  | kmpc_ctor_vec | ctor,
|  | kmpc_cctor_vec | cctor,
|  | kmpc_dtor_vec | dtor,
|  | size_t | vector_length
| ) |  |

Parameters

  loc | source location information
  data | pointer to data being privatized
  ctor | pointer to constructor function for data
  cctor | pointer to copy constructor function for data
  dtor | pointer to destructor function for data
  vector_length | length of the vector (bytes or elements?) Register vector constructors and destructors for thread private data.

Definition at line 748 of file kmp_threadprivate.cpp.