From 46beb6c2400f4f2be0fb276d4612147aa610b525 Mon Sep 17 00:00:00 2001 From: Kostis Andriopoulos Date: Thu, 4 Mar 2021 18:58:42 +0200 Subject: [PATCH] Renamed folders --- {ex1 => ex01}/big_input.txt | 0 {ex1 => ex01}/big_output.txt | 0 {ex1 => ex01}/solution.hs | 0 {ex2 => ex02}/solutions.hs | 0 {ex3 => ex03}/rally.erl | 0 {ex3 => ex03}/rally.pdf | Bin {ex3 => ex03}/rallyomatic.beam | Bin {ex3 => ex03}/report_greek.pdf | Bin {ex4 => ex04}/bughunt.erl | 0 {ex4 => ex04}/vectors.beam | Bin {ex5 => ex05}/reverse_hash.hs | 0 {ex5 => ex05}/reverse_hash_solver_par.hs | 21 +-- .../solution-checkpoint.ipynb | 136 ------------------ ex1/small_input.txt.txt | 6 - ex1/small_output.txt.txt | 0 15 files changed, 12 insertions(+), 151 deletions(-) rename {ex1 => ex01}/big_input.txt (100%) rename {ex1 => ex01}/big_output.txt (100%) rename {ex1 => ex01}/solution.hs (100%) rename {ex2 => ex02}/solutions.hs (100%) rename {ex3 => ex03}/rally.erl (100%) rename {ex3 => ex03}/rally.pdf (100%) rename {ex3 => ex03}/rallyomatic.beam (100%) rename {ex3 => ex03}/report_greek.pdf (100%) rename {ex4 => ex04}/bughunt.erl (100%) rename {ex4 => ex04}/vectors.beam (100%) rename {ex5 => ex05}/reverse_hash.hs (100%) rename {ex5 => ex05}/reverse_hash_solver_par.hs (69%) delete mode 100644 ex1/.ipynb_checkpoints/solution-checkpoint.ipynb delete mode 100644 ex1/small_input.txt.txt delete mode 100644 ex1/small_output.txt.txt diff --git a/ex1/big_input.txt b/ex01/big_input.txt similarity index 100% rename from ex1/big_input.txt rename to ex01/big_input.txt diff --git a/ex1/big_output.txt b/ex01/big_output.txt similarity index 100% rename from ex1/big_output.txt rename to ex01/big_output.txt diff --git a/ex1/solution.hs b/ex01/solution.hs similarity index 100% rename from ex1/solution.hs rename to ex01/solution.hs diff --git a/ex2/solutions.hs b/ex02/solutions.hs similarity index 100% rename from ex2/solutions.hs rename to ex02/solutions.hs diff --git a/ex3/rally.erl b/ex03/rally.erl similarity index 100% rename from ex3/rally.erl rename to ex03/rally.erl diff --git a/ex3/rally.pdf b/ex03/rally.pdf similarity index 100% rename from ex3/rally.pdf rename to ex03/rally.pdf diff --git a/ex3/rallyomatic.beam b/ex03/rallyomatic.beam similarity index 100% rename from ex3/rallyomatic.beam rename to ex03/rallyomatic.beam diff --git a/ex3/report_greek.pdf b/ex03/report_greek.pdf similarity index 100% rename from ex3/report_greek.pdf rename to ex03/report_greek.pdf diff --git a/ex4/bughunt.erl b/ex04/bughunt.erl similarity index 100% rename from ex4/bughunt.erl rename to ex04/bughunt.erl diff --git a/ex4/vectors.beam b/ex04/vectors.beam similarity index 100% rename from ex4/vectors.beam rename to ex04/vectors.beam diff --git a/ex5/reverse_hash.hs b/ex05/reverse_hash.hs similarity index 100% rename from ex5/reverse_hash.hs rename to ex05/reverse_hash.hs diff --git a/ex5/reverse_hash_solver_par.hs b/ex05/reverse_hash_solver_par.hs similarity index 69% rename from ex5/reverse_hash_solver_par.hs rename to ex05/reverse_hash_solver_par.hs index b9d25a5..0c61564 100644 --- a/ex5/reverse_hash_solver_par.hs +++ b/ex05/reverse_hash_solver_par.hs @@ -27,20 +27,23 @@ ranges n counter start end = in ((start, end'):(ranges n (counter-1) (end' + 1) end)) -parMap' :: NFData b => (a -> b) -> [a] -> Eval [b] -parMap' f [] = return [] -parMap' f (a:as) = do +parMap' :: NFData b => (a -> b) -> [a] -> MVar () -> Eval [b] +parMap' f [] _ = return [] +parMap' f (a:as) signal = do + sig <- return (tryReadMVar signal) + return (if (sig /= Nothing) then [] else let b = runEval (rpar (force_eval (f a))) + bs = runEval (parMap' f as signal) + in (b : bs)) + {-| b <- rpar (force_eval (f a)) - bs <- parMap' f as + bs <- parMap' f as signal return (b : bs) - - --- Simple parallel solver + -} solver_par :: (Int -> Int) -> [Int] -> MVar () -> MVar [(Int, Int)] -> Int -> IO () solver_par hash _ signal box schedulers = do let num = schedulers*schedulers*4 - output <- runEvalIO (parMap' (hashes_of_range hash) (ranges num num 0 (round(2**27-1)))) - let flat_output = concat output -- A list of tuples: (output, input), one for each possible input + output <- runEvalIO (parMap' (hashes_of_range hash) (ranges num num 0 (round(2**27-1))) signal) + let flat_output = concat output _ <- readMVar signal _ <- putMVar box (flat_output) return () diff --git a/ex1/.ipynb_checkpoints/solution-checkpoint.ipynb b/ex1/.ipynb_checkpoints/solution-checkpoint.ipynb deleted file mode 100644 index 4268b2e..0000000 --- a/ex1/.ipynb_checkpoints/solution-checkpoint.ipynb +++ /dev/null @@ -1,136 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "class Tree: \n", - " def __init__(self, index, weight, children):\n", - " self.index = index\n", - " self.children = children\n", - " self.weight = weight \n", - " self.sub_weight = 0\n", - " self.root_weight = 0" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "def dfs(node):\n", - " for child in node.children:\n", - " node.sub_weight += dfs(child)\n", - " return (node.sub_weight + node.weight)" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "child5 = Tree(5, 20, [])\n", - "child4 = Tree(4, 20, [child5])\n", - "child1 = Tree(1, 10, [])\n", - "child3 = Tree(3, 10, [child4, child1])\n", - "root = Tree(2, 10, [child3])" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "def dfs2(node, father_tot, father_weight):\n", - " node.root_weight = father_tot - node.weight + father_weight \n", - " curr_minim = node.root_weight\n", - " minim_index = node.index\n", - " print(node.index ,node.root_weight, node.sub_weight)\n", - " for child in node.children:\n", - " #minim = min(minim, dfs2(child, node.root_weight, node.weight))\n", - " next = dfs2(child, node.root_weight, node.weight)\n", - " if curr_minim == next[0]:\n", - " minim_index = min(minim_index, next[1])\n", - " elif curr_minim > next[0]:\n", - " minim_index = next[1]\n", - " curr_minim = next[0]\n", - " print(\"hassaa\", node.index, curr_minim, minim_index)\n", - " return (minim, min_i)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "70" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "dfs(root)" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "dfs2() takes 3 positional arguments but 4 were given", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdfs2\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mroot\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mroot\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msub_weight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: dfs2() takes 3 positional arguments but 4 were given" - ] - } - ], - "source": [ - "dfs2(root, root.sub_weight, 10)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.5" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/ex1/small_input.txt.txt b/ex1/small_input.txt.txt deleted file mode 100644 index 9aaf311..0000000 --- a/ex1/small_input.txt.txt +++ /dev/null @@ -1,6 +0,0 @@ -5 -10 3 -10 0 -10 2 -20 3 -20 4 diff --git a/ex1/small_output.txt.txt b/ex1/small_output.txt.txt deleted file mode 100644 index e69de29..0000000