Skip to content
Snippets Groups Projects
Commit e6c925dd authored by lykos98's avatar lykos98
Browse files

first upload, implemented median search, still working on top tree

parent 24136844
No related branches found
No related tags found
No related merge requests found
CompileFlags:
Add: -I/usr/lib/x86_64-linux-gnu/openmpi/include
main
sync.sh
Makefile 0 → 100644
CC=mpicc
CFLAGS=-O3 -march=native
LDFLAGS=-lm
all: main
obj=src/main/main.c src/tree/tree.c src/common/common.c
main: ${obj}
${CC} ${CFLAGS} ${LDFLAGS} ${obj} -o $@
README 0 → 100644
added 0 → 100644
#include "common.h"
#include "mpi.h"
#include <time.h>
void get_context(global_context_t* ctx)
{
MPI_Comm_size(ctx -> mpi_communicator, &(ctx -> world_size));
MPI_Get_processor_name(ctx -> processor_mame, &(ctx -> __processor_name_len));
MPI_Comm_rank(ctx -> mpi_communicator, &(ctx -> mpi_rank));
ctx -> local_data = NULL;
ctx -> lb_box = NULL;
ctx -> ub_box = NULL;
}
void free_context(global_context_t* ctx)
{
if(ctx -> local_data)
{
free(ctx -> local_data);
ctx -> local_data = NULL;
}
if(ctx -> ub_box)
{
free(ctx -> ub_box);
ctx -> ub_box = NULL;
}
if(ctx -> lb_box)
{
free(ctx -> lb_box);
ctx -> lb_box = NULL;
}
}
void free_pointset(pointset_t* ps)
{
if(ps -> data)
{
free(ps -> data);
ps -> data = NULL;
}
if(ps -> ub_box)
{
free(ps -> ub_box);
ps -> ub_box = NULL;
}
if(ps -> lb_box)
{
free(ps -> lb_box);
ps -> lb_box = NULL;
}
}
void mpi_printf(global_context_t* ctx, const char *fmt, ...)
{
if(ctx -> mpi_rank == 0)
{
va_list l;
va_start(l, fmt);
// printf("[MASTER]: ");
vprintf(fmt, l);
// myflush(stdout);
va_end(l);
}
}
void generate_random_matrix(
float_t** data,
int dimensions,
size_t nmin,
size_t nmax,
global_context_t* ctx)
{
/* seed the random number generator */
srand((unsigned)time(NULL) + ctx -> mpi_rank * ctx -> world_size + ctx -> __processor_name_len);
size_t n = rand() % (nmax - nmin) + nmin;
float_t* local_data = (float_t*)malloc(dimensions*n*sizeof(float_t));
for(size_t i = 0; i < dimensions*n; ++i) local_data[i] = (float_t)rand()/(float_t)RAND_MAX;
*data = local_data;
ctx -> dims = dimensions;
ctx -> local_n_points = n;
return;
}
#pragma once
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <mpi.h>
#include <stdint.h>
#ifdef USE_FLOAT32
#define float_t float
#else
#define float_t double
#endif
#define MY_TRUE 1
#define MY_FALSE 0
#define DB_PRINT(...) printf(__VA_ARGS__)
#ifdef NDEBUG
#undef DB_PRINT(...)
#define DB_PRINT(...)
#endif
#define MPI_DB_PRINT(...) mpi_printf(ctx,__VA_ARGS__)
#ifdef NDEBUG
#undef MPI_DB_PRINT(...)
#define MPI_DB_PRINT(...)
#endif
#define MPI_PRINT(...) mpi_printf(ctx,__VA_ARGS__)
#define MAX(A,B) ((A) > (B) ? (A) : (B))
#define MIN(A,B) ((A) < (B) ? (A) : (B))
/*
* from Spriengel code Gadget4
*/
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202000L
/* C2x does not require the second parameter for va_start. */
#define va_start(ap, ...) __builtin_va_start(ap, 0)
#else
/* Versions before C2x do require the second parameter. */
#define va_start(ap, param) __builtin_va_start(ap, param)
#endif
#define va_end(ap) __builtin_va_end(ap)
#define va_arg(ap, type) __builtin_va_arg(ap, type)
struct global_context_t
{
size_t n_points;
MPI_Comm mpi_communicator;
int world_size;
char processor_mame[MPI_MAX_PROCESSOR_NAME];
int __processor_name_len;
int mpi_rank;
size_t local_n_points;
uint32_t dims;
float_t* local_data;
float_t* lb_box;
float_t* ub_box;
};
struct pointset_t
{
size_t n_points;
size_t __capacity;
uint32_t dims;
float_t* data;
float_t* lb_box;
float_t* ub_box;
};
typedef struct pointset_t pointset_t;
typedef struct global_context_t global_context_t;
void mpi_printf(global_context_t*, const char *fmt, ...);
void get_context(global_context_t*);
void print_global_context(global_context_t* );
void free_context(global_context_t* );
void free_pointset(pointset_t* );
void generate_random_matrix(float_t** ,int ,size_t ,size_t ,global_context_t*);
This diff is collapsed.
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include "../common/common.h"
typedef struct mpi_double_int{
float_t val;
int key;
} mpi_double_int;
typedef struct partition_t
{
int d;
int n_procs;
size_t n_points;
float_t* base_ptr;
} partition_t;
typedef struct partition_queue_t
{
int count;
int _capacity;
struct partition_t* data;
} partition_queue_t;
typedef struct top_kdtree_node_t
{
float_t* data;
//float_t* node_box_lb; //Needed?
//float_t* node_box_ub; //Needed?
int owner;
int split_dim;
int is_leaf;
size_t n_points;
struct top_kdtree_node_t* lch;
struct top_kdtree_node_t* rch;
struct top_kdtree_node_t* parent;
} top_kdtree_node_t;
typedef struct top_kdtree_t
{
int dims;
size_t count;
size_t _capacity;
float_t* medians;
struct top_kdtree_node_t* _nodes;
struct top_kdtree_node_t* root;
} top_kdtree_t;
void simulate_master_read_and_scatter(int, size_t, global_context_t* );
#pragma once
var.py 0 → 100644
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))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment