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