complete first draft of package
[epclust.git] / old_C_code / stage1 / src / MPI_Communication / pack.c
CommitLineData
ab4a34ef
BA
1#include <stdlib.h>
2#include "Util/types.h"
3#include "Util/utils.h"
4
5// serialize a Work_t object into a bytes string
6void pack_work(Work_t* work, uint32_t nbSeriesInChunk, Byte* packedWork)
7{
8 uint32_t index = 0;
9
10 while (work->inputFileName[index] != 0)
11 {
12 packedWork[index] = work->inputFileName[index];
13 index++;
14 }
15 // complete with zeros
16 while (index < NCHAR_FNAME)
17 packedWork[index++] = 0;
18
73d68777 19 write_int(work->nbSeries, packedWork + index);
ab4a34ef
BA
20 index += 4;
21
22 for (uint32_t i = 0; i < work->nbSeries; i++)
23 {
73d68777 24 write_int(work->ranks[i], packedWork + index);
ab4a34ef
BA
25 index += 4;
26 }
27 // complete with zeros
28 for (uint32_t i = 0; i < nbSeriesInChunk - work->nbSeries; i++)
29 {
73d68777 30 write_int(0, packedWork + index);
ab4a34ef
BA
31 index += 4;
32 }
33
73d68777 34 write_int(work->nbClusters, packedWork + index);
ab4a34ef 35 index += 4;
73d68777 36 write_int(work->clustOnMedoids, packedWork + index);
ab4a34ef 37 index += 4;
73d68777 38 write_int(work->p_for_dissims, packedWork + index);
ab4a34ef
BA
39}
40
41// serialize a Result_t object into a bytes string
42void pack_result(Result_t* result, Byte* packedResult)
43{
44 uint32_t index = 0;
45
73d68777 46 write_int(result->nbClusters, packedResult);
ab4a34ef
BA
47 index += 4;
48
49 for (uint32_t i = 0; i < result->nbClusters; i++)
50 {
73d68777 51 write_int(result->medoids_ID[i], packedResult + index);
ab4a34ef
BA
52 index += 4;
53 }
54
55 for (uint32_t i = 0; i < result->nbClusters; i++)
56 {
73d68777 57 write_int(result->medoids_ranks[i], packedResult + index);
ab4a34ef
BA
58 index += 4;
59 }
60}