Commit 6e9128eb authored by lykos98's avatar lykos98
Browse files

added working H3, refactored files into tree, adp and utilities

parent 01f8b2de
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
import numpy as np

d = np.fromfile("../norm_data/std_LR_091_0000", dtype=np.float32)
print(d.shape)
d = d.reshape((d.shape[0]//5,5))
print(np.cov(d.T))
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ LDFLAGS=-lm

all: main

obj=src/main/main.c src/tree/tree.c src/common/common.c src/tree/kdtreeV2.c src/tree/heap.c
obj=src/main/main.c src/tree/tree.c src/common/common.c src/tree/kdtreeV2.c src/tree/heap.c src/adp/adp.c

main: ${obj} 
	${CC} ${CFLAGS} ${LDFLAGS} ${obj} -o $@

src/adp/adp.c

0 → 100644
+2114 −0

File added.

Preview size limit exceeded, changes collapsed.

src/adp/adp.h

0 → 100644
+58 −0
Original line number Diff line number Diff line
#pragma once
#include "../tree/tree.h"

#define PREALLOC_BORDERS 100
#define MAX_SERIAL_MERGING 100
#define PRINT_H2_COMM_SCHEME

typedef struct border_t 
{
    float_t density;
    float_t error;
    idx_t idx;
} border_t;

typedef struct sparse_border_t 
{
    idx_t i;
    idx_t j;
    idx_t idx;
    float_t density;
    float_t error;
} sparse_border_t;

typedef struct adj_list_t 
{
    idx_t count;
    idx_t size;
    struct sparse_border_t* data;
} adj_list_t;


typedef struct clusters_t 
{
    int use_sparse_borders;
    struct adj_list_t *sparse_borders;
    struct lu_dynamic_array_t centers;
    struct border_t **borders;
    struct border_t *__borders_data;
    idx_t n;
} clusters_t;

typedef struct merge_t 
{
    idx_t source;
    idx_t target;
    float_t density;
} merge_t;



void compute_density_kstarnn_rma(global_context_t* ctx, const float_t d, int verbose);
void compute_density_kstarnn_rma_v2(global_context_t* ctx, const float_t d, int verbose);
float_t compute_ID_two_NN_ML(global_context_t* ctx, datapoint_info_t* dp_info, idx_t n, int verbose);
void clusters_allocate(clusters_t * c, int s);

clusters_t Heuristic1(global_context_t *ctx, int verbose);
void Heuristic2(global_context_t* ctx, clusters_t* cluster);
void Heuristic3(global_context_t* ctx, clusters_t* cluster, float_t Z, int halo);
+51 −0
Original line number Diff line number Diff line
@@ -202,3 +202,54 @@ void lu_dynamic_array_init(lu_dynamic_array_t * a)
    a -> size = 0;
}

void ordered_buffer_to_file(global_context_t* ctx, void* buffer, size_t el_size, uint64_t n, const char* fname)
{
    //MPI_Barrier(ctx -> mpi_communicator);
    MPI_DB_PRINT("[MASTER] writing to file %s\n", fname);
    void* tmp_data; 
    int* ppp; 
    int* displs;

    MPI_Barrier(ctx -> mpi_communicator);
    
    uint64_t tot_n = 0;
    MPI_Reduce(&n, &tot_n, 1, MPI_UINT64_T , MPI_SUM, 0, ctx -> mpi_communicator);

    if(I_AM_MASTER) 
    {
        tmp_data = (void*)MY_MALLOC(el_size * tot_n );
        ppp      = (int*)MY_MALLOC(ctx -> world_size * sizeof(int));
        displs   = (int*)MY_MALLOC(ctx -> world_size * sizeof(int));

    }
    
    int nn = (int)n;
    MPI_Gather(&nn, 1, MPI_INT, ppp, 1, MPI_INT, 0, ctx -> mpi_communicator);

    if(I_AM_MASTER)
    {
        displs[0] = 0;
        for(int i = 0; i < ctx -> world_size; ++i) ppp[i]    = el_size  * ppp[i];
        for(int i = 1; i < ctx -> world_size; ++i) displs[i] = displs[i - 1] + ppp[i - 1];
            
    }

    MPI_Gatherv(buffer, (int)(el_size * n), 
            MPI_BYTE, tmp_data, ppp, displs, MPI_BYTE, 0, ctx -> mpi_communicator);

    if(I_AM_MASTER)
    {
        FILE* file = fopen(fname,"w");
        if(!file)
        {
            printf("Cannot open file %s ! Aborting \n", fname);
        }
        fwrite(tmp_data, 1, el_size * tot_n, file);
        fclose(file);
        free(tmp_data);
        free(ppp);
        free(displs);

    }
    MPI_Barrier(ctx -> mpi_communicator);
}
Loading