ASCOT5
Loading...
Searching...
No Matches
offload.c
Go to the documentation of this file.
1
16#include <stdlib.h>
17#include <string.h>
18#include "ascot5.h"
19#include "offload.h"
20
31void offload_init_offload(offload_package* o, real** offload_array,
32 int** int_offload_array) {
33 *offload_array = NULL;
34 *int_offload_array = NULL;
37 o->unpack_pos = 0;
38 o->int_unpack_pos = 0;
39}
40
41
49void offload_free_offload(offload_package* o, real** offload_array,
50 int** int_offload_array) {
51 free(*offload_array);
52 free(*int_offload_array);
53 *offload_array = NULL;
54 *int_offload_array = NULL;
57 o->unpack_pos = 0;
58 o->int_unpack_pos = 0;
59}
60
61
78void offload_pack(offload_package* o, real** offload_array, real* pack_array,
79 size_t pack_length, int** int_offload_array,
80 int* int_pack_array, size_t int_pack_length) {
81
82 /* Float array */
83 if( pack_length > 0 ) {
84 size_t new_length = o->offload_array_length + pack_length;
85 real* new_array = (real*) malloc(new_length * sizeof(real));
86
87 if(o->offload_array_length > 0) {
88 memcpy(new_array, *offload_array,
89 o->offload_array_length*sizeof(real));
90 }
91
92 memcpy(new_array+o->offload_array_length, pack_array,
93 pack_length*sizeof(real));
94
95 free(*offload_array);
96
97 *offload_array = new_array;
98 o->offload_array_length = new_length;
99 }
100
101 /* Int array */
102 if( int_pack_length > 0 ) {
103 size_t int_new_length = o->int_offload_array_length + int_pack_length;
104 int* int_new_array = (int*) malloc(int_new_length * sizeof(int));
105
106 if(o->int_offload_array_length > 0) {
107 memcpy(int_new_array, *int_offload_array,
108 o->int_offload_array_length*sizeof(int));
109 }
110
111 memcpy(int_new_array+o->int_offload_array_length, int_pack_array,
112 int_pack_length*sizeof(int));
113
114 free(*int_offload_array);
115
116 *int_offload_array = int_new_array;
117 o->int_offload_array_length = int_new_length;
118 }
119}
120
121
137void offload_unpack(offload_package* o, real* offload_array,
138 size_t pack_length, int* int_offload_array,
139 size_t int_pack_length, real** ptr, int** intptr) {
140 *ptr = offload_array + o->unpack_pos;
141 o->unpack_pos += pack_length;
142
143 *intptr = int_offload_array + o->int_unpack_pos;
144 o->int_unpack_pos += int_pack_length;
145}
Main header file for ASCOT5.
double real
Definition ascot5.h:85
void offload_free_offload(offload_package *o, real **offload_array, int **int_offload_array)
Free offload array and set offload_package to clean state.
Definition offload.c:49
void offload_unpack(offload_package *o, real *offload_array, size_t pack_length, int *int_offload_array, size_t int_pack_length, real **ptr, int **intptr)
Unpack offload array from the package.
Definition offload.c:137
void offload_init_offload(offload_package *o, real **offload_array, int **int_offload_array)
Initialize offload package.
Definition offload.c:31
void offload_pack(offload_package *o, real **offload_array, real *pack_array, size_t pack_length, int **int_offload_array, int *int_pack_array, size_t int_pack_length)
Pack an offload array to package array.
Definition offload.c:78
Header file for offload.h.
Struct to keep track of the offload array length and unpack status.
Definition offload.h:11
size_t int_offload_array_length
Definition offload.h:16
size_t unpack_pos
Definition offload.h:14
size_t offload_array_length
Definition offload.h:12
size_t int_unpack_pos
Definition offload.h:18