Browse Source

remove mandelbrot, now on separate repo

Douglas A 4 năm trước cách đây
mục cha
commit
5e30512d02

+ 0 - 62
mandelbrot/.gitignore

@@ -1,62 +0,0 @@
-# Prerequisites
-*.d
-
-# Object files
-*.o
-*.ko
-*.obj
-*.elf
-
-# Linker output
-*.ilk
-*.map
-*.exp
-
-# Precompiled Headers
-*.gch
-*.pch
-
-# Libraries
-*.lib
-*.a
-*.la
-*.lo
-
-# Shared objects (inc. Windows DLLs)
-*.dll
-*.so
-*.so.*
-*.dylib
-
-# Executables
-*.exe
-*.out
-*.app
-*.i*86
-*.x86_64
-*.hex
-
-# Debug files
-*.dSYM/
-*.su
-*.idb
-*.pdb
-
-# Kernel Module Compile Results
-*.mod*
-*.cmd
-.tmp_versions/
-modules.order
-Module.symvers
-Mkfile.old
-dkms.conf
-
-# Remove indent metafiles
-*.h~
-*.c~
-
-# Remove vscode metafiles
-.vscode/*
-
-*.png
-bin/*

+ 0 - 21
mandelbrot/LICENSE

@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2020 Douglas R Andreani
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.

+ 0 - 26
mandelbrot/Makefile

@@ -1,26 +0,0 @@
-CC=/usr/bin/gcc
-CFLAGS=-g -Werror -D _DEFAULT_SOURCE -O0 -D_XOPEN_SOURCE=600 -pthread -pedantic -pedantic-errors -fno-fast-math -fno-builtin -m64 -std=iso9899:1999 -I${PWD} -I${PWD}/../libpng 
-OUT=bin
-OBJ=$(OUT)/obj
-OBJS=$(OBJ)/mandelbrot.o $(OBJ)/img.o  $(OBJ)/queue.o   
-
-
-all: pre bin/mandelbrot
-
-bin/mandelbrot: $(OBJS)
-	$(CC) $(CFLAGS) $(OBJS) -o $(OUT)/mandelbrot -lpng -pthread
-
-bin/obj/mandelbrot.o: mandelbrot.c config.h
-	$(CC) $(CFLAGS) -c mandelbrot.c -o $(OBJ)/mandelbrot.o -pthread
-
-bin/obj/img.o: ../libpng/img.c
-	$(CC) $(CFLAGS) -c ../libpng/img.c -o $(OBJ)/img.o -lpng
-
-bin/obj/queue.o: queue.c
-	$(CC) $(CFLAGS) -c queue.c -o $(OBJ)/queue.o -pthread
-
-pre:
-	mkdir -p bin/obj
-
-clean:
-	find ./bin -type f -exec rm {} \;

+ 0 - 26
mandelbrot/Makefile-deb-arm

@@ -1,26 +0,0 @@
-CC=/usr/bin/gcc
-CFLAGS=-g -Werror -D _DEFAULT_SOURCE -O0 -D_XOPEN_SOURCE=600 -pthread -pedantic -pedantic-errors -fno-fast-math -fno-builtin -std=iso9899:1999 -I${PWD} -I${PWD}/../libpng 
-OUT=bin
-OBJ=$(OUT)/obj
-OBJS=$(OBJ)/mandelbrot.o $(OBJ)/img.o  $(OBJ)/queue.o   
-
-
-all: pre bin/mandelbrot
-
-bin/mandelbrot: $(OBJS)
-	$(CC) $(CFLAGS) $(OBJS) -o $(OUT)/mandelbrot -lpng -pthread
-
-bin/obj/mandelbrot.o: mandelbrot.c config.h
-	$(CC) $(CFLAGS) -c mandelbrot.c -o $(OBJ)/mandelbrot.o 
-
-bin/obj/img.o: ../libpng/img.c
-	$(CC) $(CFLAGS) -c ../libpng/img.c -o $(OBJ)/img.o 
-
-bin/obj/queue.o: queue.c
-	$(CC) $(CFLAGS) -c queue.c -o $(OBJ)/queue.o 
-
-pre:
-	mkdir -p bin/obj
-
-clean:
-	find ./bin -type f -exec rm {} \;

+ 0 - 26
mandelbrot/Makefile-fbsd-amd64

@@ -1,26 +0,0 @@
-CC=/usr/bin/clang
-CFLAGS=-g -Werror -D _DEFAULT_SOURCE -O0 -D_XOPEN_SOURCE=600 -pthread -pedantic -pedantic-errors -fno-fast-math -fno-builtin -m64 -std=iso9899:1999 -I/usr/local/include/ -I${PWD} -I${PWD}/../libpng 
-OUT=bin
-OBJ=$(OUT)/obj
-OBJS=$(OBJ)/mandelbrot.o $(OBJ)/img.o  $(OBJ)/queue.o   
-
-
-all: pre bin/mandelbrot
-
-bin/mandelbrot: $(OBJS)
-	$(CC) $(CFLAGS) $(OBJS) -o $(OUT)/mandelbrot -pthread -L/usr/local/lib/ -lpng
-
-bin/obj/mandelbrot.o: mandelbrot.c config.h
-	$(CC) $(CFLAGS) -c mandelbrot.c -o $(OBJ)/mandelbrot.o -pthread
-
-bin/obj/img.o: ../libpng/img.c
-	$(CC) $(CFLAGS) -c ../libpng/img.c -o $(OBJ)/img.o
-
-bin/obj/queue.o: queue.c
-	$(CC) $(CFLAGS) -c queue.c -o $(OBJ)/queue.o -pthread
-
-pre:
-	mkdir -p bin/obj
-
-clean:
-	find ./bin -type f -exec rm {} \;

+ 0 - 26
mandelbrot/Makefile-obsd-amd64

@@ -1,26 +0,0 @@
-CC=/usr/bin/clang
-CFLAGS=-g -Werror -D _DEFAULT_SOURCE -O0 -D_XOPEN_SOURCE=600 -pthread -pedantic -pedantic-errors -fno-fast-math -fno-builtin -m64 -std=iso9899:1999 -I/usr/local/include/ -I${PWD} -I${PWD}/../libpng 
-OUT=bin
-OBJ=$(OUT)/obj
-OBJS=$(OBJ)/mandelbrot.o $(OBJ)/img.o  $(OBJ)/queue.o   
-
-
-all: pre bin/mandelbrot
-
-bin/mandelbrot: $(OBJS)
-	$(CC) $(CFLAGS) $(OBJS) -o $(OUT)/mandelbrot -pthread -L/usr/local/lib/ -lpng
-
-bin/obj/mandelbrot.o: mandelbrot.c config.h
-	$(CC) $(CFLAGS) -c mandelbrot.c -o $(OBJ)/mandelbrot.o -pthread
-
-bin/obj/img.o: ../libpng/img.c
-	$(CC) $(CFLAGS) -c ../libpng/img.c -o $(OBJ)/img.o
-
-bin/obj/queue.o: queue.c
-	$(CC) $(CFLAGS) -c queue.c -o $(OBJ)/queue.o -pthread
-
-pre:
-	mkdir -p bin/obj
-
-clean:
-	find ./bin -type f -exec rm {} \;

+ 0 - 8
mandelbrot/config.h

@@ -1,8 +0,0 @@
-#define BAIL_OUT 8192
-#define MAX_ITER 16384
-
-#define WIDTH 1024
-#define HEIGHT 1024
-
-#define THREAD_COUNT 36
-#define BUFFER_SIZE  256

BIN
mandelbrot/mandel.png


+ 0 - 188
mandelbrot/mandelbrot.c

@@ -1,188 +0,0 @@
-#include "mandelbrot.h"
-
-double map(int value, int min, int max, int map_min, int map_max)
-{
-	double R = (double) (map_max - map_min) / (double) (max - min);
-	double y = map_min + (value * R) + R;
-	return y;
-}
-
-int mandelbrot_pix(double x, double y, int bail_out, int max_iter)
-{
-	int k;
-	double real, imaginary, x2, y2;
-
-	x2 = x;
-	y2 = y;
-
-	// iterate a^2 - b^2 + 2ab
-	for (k = 0; k < max_iter; k++) {
-		// a^2 - b^2
-		real = x * x - y * y;
-		// 2ab
-		imaginary = 2 * x * y;
-
-		// x = real + c
-		x = real + x2;
-		// y = imaginary + c
-		y = imaginary +y2;
-
-		if ((x * x + y * y) > bail_out) {
-			return k;
-		}
-	}
-	return max_iter;
-}
-
-void mandelbrot(int *field, int w, int h, int bail_out, int max_iter,
-		int thread_count)
-{
-
-	for (int i = 0; i < w; i++) {
-		for (int j = 0; j < h; j++) {
-			double x = map(i, 0, w, -1, 1);
-			double y = map(j, 0, h, -1, 1);
-
-			int k = mandelbrot_pix(x, y, BAIL_OUT, MAX_ITER);
-			fprintf(stdout, "\nComputing %d %d = %d", i, j, k);
-			field[i + j * h] = k;
-		}
-	}
-
-}
-
-void *produce(void *b)
-{
-	mandel_buf_t *buf;
-	mandel_t *m;
-
-	double x;
-	double y;
-
-	buf = (mandel_buf_t *) b;
-
-	for (int i = 0; i < buf->prop.width; i++) {
-		for (int j = 0; j < buf->prop.height; j++) {
-
-			m = malloc(sizeof(mandel_t));
-			m->x = i;
-			m->y = j;
-			enqueue(buf->q, m, buf->lock);
-		}
-	}
-	buf->produce_end = 1;
-	return NULL;
-}
-
-void *consume(void *b)
-{
-	mandel_buf_t *buf;
-	mandel_t *m;
-	double x, y;
-	int k, i;
-
-	buf = (mandel_buf_t *) b;
-
-
-	/* This will not work on a multi-consumer program 
-	while (i < buf->prop.width * buf->prop.height) { */
-	for(;;){
-		m = dequeue(buf->q, buf->lock);
-		if (m == NULL) return NULL; // if m is null then the queue is empty ?
-		x = map(m->x, 0, buf->prop.width, -1, 1);
-		y = map(m->y, 0, buf->prop.height, -1, 1);
-		//fprintf(stdout, "\nSending %d %d", m->x, m->y, k);
-
-		k = mandelbrot_pix(x, y, buf->prop.bail_out,
-				buf->prop.max_iter);
-		buf->result_field[m->y + m->x * buf->prop.height] = k;
-		free(m);
-		i++;
-	}
-	return NULL;
-}
-
-int main(int argc, char **argv)
-{
-
-	pthread_t consumer[THREAD_COUNT];
-	pthread_t producer;
-	pthread_attr_t attr;
-	pthread_mutex_t lock;
-
-	printf
-	    ("WIDTH: %d\nHEIGHT %d\nBAIL OUT %d\nMAX ITER %d\nTHREAD COUNT %d",
-	     WIDTH, HEIGHT, BAIL_OUT, MAX_ITER, THREAD_COUNT);
-
-	pthread_attr_init(&attr);
-
-	/* Define current mandelbrot set properties */
-	mandel_prop_t prop;
-	prop.bail_out = BAIL_OUT;
-	prop.max_iter = MAX_ITER;
-	prop.height = HEIGHT;
-	prop.width = WIDTH;
-
-	/* Initialize the buffer for threads to work with */
-	mandel_buf_t buf;
-	buf.prop = prop;
-	queue_t *queue;
-	queue = initialize_queue();
-	pthread_mutex_init(&lock, NULL);
-	buf.lock = &lock;
-	buf.produce_end = 0;
-	buf.result_field = malloc(sizeof(int) * WIDTH * HEIGHT);
-
-	buf.q = queue;
-
-	/* Create and start threads */
-	pthread_create(&producer, &attr, produce, &buf);
-
-	pthread_join(producer, NULL);
-	
-	for (int i=0; i<THREAD_COUNT; i++) {
-		pthread_create(&consumer[i], &attr, consume, &buf);
-	}
-
-	for (int i=0; i<THREAD_COUNT; i++) {
-		pthread_join(consumer[i], NULL);
-	}
-
-	/* Create the png image with the result buffer */
-	pix_row rows[WIDTH];
-	pix p;
-
-	char filename[30];
-	image img;
-	p.r = 200;
-	p.g = 200;
-	p.b = 200;
-
-	for (int i = 0; i < WIDTH; i++) {
-		rows[i].p = malloc(HEIGHT * sizeof(pix));
-		for (int j = 0; j < HEIGHT; j++) {
-			p.r =
-			    map(buf.result_field[i * HEIGHT + j], 0,
-				MAX_ITER, 0, 255);
-			p.g =
-			    map(buf.result_field[i * HEIGHT + j], 0,
-				MAX_ITER, 0, 255);
-			p.b =
-			    map(buf.result_field[i * HEIGHT + j], 0,
-				MAX_ITER, 0, 255);
-			rows[i].p[j] = p;
-		}
-	}
-	sprintf(filename, "mandel.png");
-	img = initialize_png("mandelbrot", filename, WIDTH, HEIGHT);
-	write_image(&img, rows);
-	finish_image(&img);
-	for (int i = 0; i < WIDTH; i++) {
-
-		free(rows[i].p);
-	}
-
-	free(buf.result_field);
-
-	return (0);
-}

+ 0 - 43
mandelbrot/mandelbrot.h

@@ -1,43 +0,0 @@
-#include <stdio.h>
-#include <pthread.h>
-#include <semaphore.h>
-#include <unistd.h>
-
-#include "../libpng/img.h"
-#include "config.h"
-
-typedef struct queue {
-	struct queue_node_t *head;
-	struct queue_node_t *tail;
-} queue_t;
-
-typedef struct mandel_t {
-	int x;
-	int y;
-} mandel_t;
-
-struct queue_node_t {
-	mandel_t *node;
-	struct queue_node_t *next;
-};
-
-typedef struct mandel_prop_t {
-	int width;
-	int height;
-	int bail_out;
-	int max_iter;
-} mandel_prop_t;
-
-typedef struct mandel_buf_t {
-	queue_t *q;
-	int *result_field;
-	mandel_prop_t prop;
-	pthread_mutex_t *lock;
-	int produce_end;
-} mandel_buf_t;
-
-queue_t *initialize_queue();
-void enqueue(queue_t * q, mandel_t * w, pthread_mutex_t * lock);
-mandel_t *dequeue(queue_t * q, pthread_mutex_t * lock);
-void destroy_queue(queue_t * q);
-int is_empty(queue_t * q, pthread_mutex_t * lock);

+ 0 - 86
mandelbrot/queue.c

@@ -1,86 +0,0 @@
-#include "mandelbrot.h"
-
-queue_t *initialize_queue()
-{
-	queue_t *q;
-
-	q = (queue_t *) malloc(sizeof(queue_t *));
-
-	return q;
-}
-
-void enqueue(queue_t * q, mandel_t * w, pthread_mutex_t * lock)
-{
-	struct queue_node_t *aux;
-
-	pthread_mutex_lock(lock);
-
-	if (q->head == NULL) {
-		q->head =
-		    (struct queue_node_t *)
-		    malloc(sizeof(struct queue_node_t *));
-		q->head->next = NULL;
-		q->head->node = w;
-		q->tail = q->head;
-	} else {
-		aux =
-		    (struct queue_node_t *)
-		    malloc(sizeof(struct queue_node_t *));
-		aux->next = NULL;
-		aux->node = w;
-		q->tail->next = aux;
-		q->tail = aux;
-	}
-
-	pthread_mutex_unlock(lock);
-}
-
-mandel_t *dequeue(queue_t * q, pthread_mutex_t * lock)
-{
-	struct queue_node_t *aux;
-	mandel_t *ret_val;
-	pthread_mutex_lock(lock);
-	
-	if (q->head == NULL) {
-		ret_val = NULL;
-	}
-	else if (q->head == q->tail) {
-		aux = q->head;
-		ret_val = aux->node;
-		q->head = NULL;
-		q->tail = NULL;
-	}
-	else {
-		aux = q->head;
-		ret_val = aux->node;
-		q->head = aux->next;
-	}
-	pthread_mutex_unlock(lock);
-	return ret_val;
-
-}
-
-int is_empty(queue_t * q, pthread_mutex_t * lock)
-{
-	int ret = 0;
-	pthread_mutex_lock(lock);
-	if (q->head == NULL) ret = 1;
-	pthread_mutex_unlock(lock);
-	
-	return (ret);
-}
-
-void destroy_queue(queue_t * q)
-{
-	struct queue_node_t *aux, *next;
-
-	aux = q->head;
-
-	while (aux != NULL) {
-		next = aux->next;
-		free(aux);
-		if (next != NULL)
-			aux = next;
-	}
-	free(q);
-}