<commit_before>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: smifsud <<EMAIL>>                     +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2017/05/04 13:31:03 by smifsud           #+#    #+#             */
/*   Updated: 2017/05/30 12:56:56 by smifsud          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>
#include <fcntl.h>
#include <checker.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>

void			setnode(t_octant *node, t_body *bodies, int64_t nbodies)
{
    node->parent = 0;
    node->bodies = bodies;
    node->start = 0;
    node->end = (size_t)nbodies - 1;
    node->children = (t_octant**)malloc(sizeof(t_octant*) * 8);
}

t_body          *copybodies(t_body *bodies, size_t len)
{
    t_body  *new;

    new = (t_body*)malloc(sizeof(t_body) * len);
    for (size_t i = 0; i < len; i++)
    {
        new[i].position = bodies[i].position;
        new[i].velocity = bodies[i].velocity;
        new[i].id = bodies[i].id;
        new[i].mass = bodies[i].mass;
        new[i].octant = bodies[i].octant;
    }
    return (new);
}

int         compare_id(const void *b1, const void *b2)
{
    const t_body    *a; 
    const t_body    *b; 

    a = (const t_body *)b1;
    b = (const t_body *)b2;
    if (a->id < b->id)
        return (-1);
    if (a->id == b->id)
        return (0);
    return (1);
}

void			outresults(t_octant *universe, int filen)
{
    char		*filename;
    int			fd;
    int64_t		*buf;
    double		*cords;
    size_t		i;
    size_t		j;
    t_body      *new;

    i = 0;
    j = 0;
    printf("THIS IS A DEBUG MESSAGE\n");
    asprintf(&filename, "out%d.jgrav", filen);
    fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP);
    buf = malloc(sizeof(int64_t) * 1);
    *buf = universe->end - universe->start + 1;
    printf("%lld\n", *buf);
    write(fd, buf, sizeof(int64_t));
    cords = (double*)malloc(sizeof(double) * 4 * (universe->end - universe->start + 1));
    if (!cords)
    {
        printf("ALLOC ERROR\n");
        exit(1);
    }
    new = copybodies(universe->bodies, (universe->end - universe->start + 1));
    qsort(&new[0], (universe->end - universe->start + 1), sizeof(t_body), compare_id);
    while (i <= universe->end)
    {
        cords[j] = new[i].position.x;
        j++;
        cords[j] = new[i].position.y;
        j++;
        cords[j] = new[i].position.z;
        j++;
        cords[j] = new[i].mass;
        j++;
        //	if (i == 71523 || i == 71522 || i == 71524)
        //			printf("CORDS: x: %lf, y: %lf, z: %lf, m: %lf\n", cords[j - 4], cords[j - 3], cords[j - 2], cords[j - 1]);
        i++;
    }
    printf("DEBUG WOKKA%ld\n", universe->end - universe->start + 1);
    write(fd, cords, sizeof(double) * 4 * (universe->end - universe->start + 1));
    free(cords);
    free(filename);
    free(buf);
    free(new);
}

void				simulation(t_octant *universe)
{
    int		i;

    i = 0;
    while (i < 10000)
    {
        /*	for (size_t j = universe->start; j <= universe->end; j++)
            {
            printf("PARTICLE ID %zu:\nposition = (%lf, %lf, %lf)\nvelocity = (%lf, %lf, %lf)\nmass = (%lf)\n", 
            j,
            universe->bodies[j].position.x,
            universe->bodies[j].position.y,
            universe->bodies[j].position.z,
            universe->bodies[j].velocity.x,
            universe->bodies[j].velocity.y,
            universe->bodies[j].velocity.z,
            universe->bodies[j].mass);
            } */
        printf("OK %d\n", i);
        universe = barnes_hut(universe);
        re_tree(universe);
        octree_divide(universe);
        //printf("%zu, %zu\n", universe->start, universe->end);
        /*		for (size_t j = universe->start; j <= universe->end; j++)
                {
                printf("PARTICLE ID %zu:\nposition = (%lf, %lf, %lf)\nvelocity = (%lf, %lf, %lf)\nmass = (%lf)\n", 
                j,
                universe->bodies[j].position.x,
                universe->bodies[j].position.y,
                universe->bodies[j].position.z,
                universe->bodies[j].velocity.x,
                universe->bodies[j].velocity.y,
                universe->bodies[j].velocity.z,
                universe->bodies[j].mass);
                } */
        i++;
    }
    outresults(universe, i);
}

double				rand_double(double max)
{
    double	r;
<commit_msg>retree causes issues. see the comment<commit_after>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: smifsud <<EMAIL>>                     +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2017/05/04 13:31:03 by smifsud           #+#    #+#             */
/*   Updated: 2017/05/30 13:22:12 by smifsud          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <stdlib.h>
#include <fcntl.h>
#include <checker.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <pthread.h>

void			setnode(t_octant *node, t_body *bodies, int64_t nbodies)
{
    node->parent = 0;
    node->bodies = bodies;
    node->start = 0;
    node->end = (size_t)nbodies - 1;
    node->children = (t_octant**)malloc(sizeof(t_octant*) * 8);
}

t_body          *copybodies(t_body *bodies, size_t len)
{
    t_body  *new;

    new = (t_body*)malloc(sizeof(t_body) * len);
    for (size_t i = 0; i < len; i++)
    {
        new[i].position = bodies[i].position;
        new[i].velocity = bodies[i].velocity;
        new[i].id = bodies[i].id;
        new[i].mass = bodies[i].mass;
        new[i].octant = bodies[i].octant;
    }
    return (new);
}

int         compare_id(const void *b1, const void *b2)
{
    const t_body    *a; 
    const t_body    *b; 

    a = (const t_body *)b1;
    b = (const t_body *)b2;
    if (a->id < b->id)
        return (-1);
    if (a->id == b->id)
        return (0);
    return (1);
}

void			outresults(t_octant *universe, int filen)
{
    char		*filename;
    int			fd;
    int64_t		*buf;
    double		*cords;
    size_t		i;
    size_t		j;
    t_body      *new;

    i = 0;
    j = 0;
    printf("THIS IS A DEBUG MESSAGE\n");
    asprintf(&filename, "out%d.jgrav", filen);
    fd = open(filename, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IROTH | S_IWOTH | S_IRGRP | S_IWGRP);
    buf = malloc(sizeof(int64_t) * 1);
    *buf = universe->end - universe->start + 1;
    printf("%lld\n", *buf);
    write(fd, buf, sizeof(int64_t));
    cords = (double*)malloc(sizeof(double) * 4 * (universe->end - universe->start + 1));
    if (!cords)
    {
        printf("ALLOC ERROR\n");
        exit(1);
    }
    new = copybodies(universe->bodies, (universe->end - universe->start + 1));
    qsort(&new[0], (universe->end - universe->start + 1), sizeof(t_body), compare_id);
    while (i <= universe->end)
    {
        cords[j] = new[i].position.x;
        j++;
        cords[j] = new[i].position.y;
        j++;
        cords[j] = new[i].position.z;
        j++;
        cords[j] = new[i].mass;
        j++;
        //	if (i == 71523 || i == 71522 || i == 71524)
        //			printf("CORDS: x: %lf, y: %lf, z: %lf, m: %lf\n", cords[j - 4], cords[j - 3], cords[j - 2], cords[j - 1]);
        i++;
    }
    printf("DEBUG WOKKA%ld\n", universe->end - universe->start + 1);
    write(fd, cords, sizeof(double) * 4 * (universe->end - universe->start + 1));
    free(cords);
    free(filename);
    free(buf);
    free(new);
}

void				simulation(t_octant *universe)
{
    int		i;

    i = 0;
    while (i < 30000)
    {
        /*	for (size_t j = universe->start; j <= universe->end; j++)
            {
            printf("PARTICLE ID %zu:\nposition = (%lf, %lf, %lf)\nvelocity = (%lf, %lf, %lf)\nmass = (%lf)\n", 
            j,
            universe->bodies[j].position.x,
            universe->bodies[j].position.y,
            universe->bodies[j].position.z,
            universe->bodies[j].velocity.x,
            universe->bodies[j].velocity.y,
            universe->bodies[j].velocity.z,
            universe->bodies[j].mass);
            } */
        printf("OK %d\n", i);
        universe = barnes_hut(universe);
/*		this causes linux to kill the process due to system resource usage
        re_tree(universe);
        octree_divide(universe); */
        //printf("%zu, %zu\n", universe->start, universe->end);
        /*		for (size_t j = universe->start; j <= universe->end; j++)
                {
                printf("PARTICLE ID %zu:\nposition = (%lf, %lf, %lf)\nvelocity = (%lf, %lf, %lf)\nmass = (%lf)\n", 
                j,
                universe->bodies[j].position.x,
                universe->bodies[j].position.y,
                universe->bodies[j].position.z,
                universe->bodies[j].velocity.x,
                universe->bodies[j].velocity.y,
                universe->bodies[j].velocity.z,
                universe->bodies[j].mass);
                } */
        i++;
    }
    outresults(universe, i);
}

double				rand_double(double max)
{
    double	r;

{'fraction_non_alphanumeric': 0.20311879221295193, 'fraction_numerical': 0.01708382995629718, 'mean_word_length': 1.6085492227979274, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4483193', 'n_tokens_mistral': 3728, 'n_tokens_neox': 3429, 'n_words': 659}