Commit fbc083c2f8ea11612e80c8bafd500cf9e6e2142e

Authored by John Markus Bjørndalen
1 parent 4e7dab23

added today's lecture

lectures/tools-code/patchfil.txt 0 → 100644
  1 +--- proftest.c 2012-04-24 16:35:45.692958455 +0200
  2 ++++ proftest-difftest.c 2012-04-24 16:35:45.692958455 +0200
  3 +@@ -10,6 +10,8 @@
  4 + *
  5 + *
  6 + * The source code is from a simple Mandelbrot benchmark / mandatory exercise in inf-3201.
  7 ++ *
  8 ++ * NB: this version has a bug. How do you compare it with the original?
  9 + */
  10 +
  11 + #include <stdio.h>
  12 +@@ -17,7 +19,7 @@
  13 + int zooms = 10;
  14 +
  15 + const int WIDTH = 500;
  16 +-const int HEIGHT = 500;
  17 ++const int HEIGHT = 600;
  18 +
  19 + int crc = 0;
  20 +
  21 +@@ -54,11 +56,11 @@
  22 + double box_x_min, box_x_max, box_y_min, box_y_max;
  23 +
  24 + inline double translate_x(int x) {
  25 +- return (((box_x_max - box_x_min) / WIDTH) * x) + box_x_min;
  26 ++ return (((box_x_max - box_x_min) / WIDTH) * x) + box_y_min;
  27 + }
  28 +
  29 + inline double translate_y(int y) {
  30 +- return (((box_y_max - box_y_min) / HEIGHT) * y) + box_y_min;
  31 ++ return (((box_y_max - box_y_min) / HEIGHT) * y) + box_x_min;
  32 + }
  33 +
  34 + // Simple Mandelbrot divergation test
  35 +@@ -122,6 +124,7 @@
  36 +
  37 + RoadMap();
  38 +
  39 ++ printf("NB: This version has a bug... but where?\n");
  40 + printf("CRC is %x\n", crc);
  41 +
  42 + return 0;
... ...
lectures/tools-code/proftest-difftest.c 0 → 100644
  1 +/*
  2 + * Compiles cleanly with gcc proftest.c
  3 + *
  4 + * For profiling / debugging: gcc -pg proftest.c, run the program (a.out) and
  5 + * inspect the output with gprof a.out
  6 + *
  7 + * Warnings: -Wall - what happens?
  8 + *
  9 + * Static checking: try splint proftest.c
  10 + *
  11 + *
  12 + * The source code is from a simple Mandelbrot benchmark / mandatory exercise in inf-3201.
  13 + *
  14 + * NB: this version has a bug. How do you compare it with the original?
  15 + */
  16 +
  17 +#include <stdio.h>
  18 +
  19 +int zooms = 10;
  20 +
  21 +const int WIDTH = 500;
  22 +const int HEIGHT = 600;
  23 +
  24 +int crc = 0;
  25 +
  26 +enum fake_cols {
  27 + WHITE,
  28 + BLUE,
  29 + CYAN,
  30 + BLACK,
  31 + GREEN,
  32 + MAGENTA,
  33 + ORANGE,
  34 + PINK,
  35 + RED,
  36 + YELLOW,
  37 + };
  38 +
  39 +
  40 +int colortable[] = {
  41 + WHITE,
  42 + WHITE,
  43 + BLUE,
  44 + CYAN,
  45 + BLACK,
  46 + GREEN,
  47 + MAGENTA,
  48 + ORANGE,
  49 + PINK,
  50 + RED,
  51 + YELLOW
  52 +};
  53 +
  54 +int colorcount = 10;
  55 +
  56 +double box_x_min, box_x_max, box_y_min, box_y_max;
  57 +
  58 +inline double translate_x(int x) {
  59 + return (((box_x_max - box_x_min) / WIDTH) * x) + box_y_min;
  60 +}
  61 +
  62 +inline double translate_y(int y) {
  63 + return (((box_y_max - box_y_min) / HEIGHT) * y) + box_x_min;
  64 +}
  65 +
  66 +// Simple Mandelbrot divergation test
  67 +inline int solve(double x, double y)
  68 +{
  69 + double r = 0.0, s = 0.0;
  70 + double next_r, next_s;
  71 + int itt = 0;
  72 +
  73 + while ((r * r + s * s) <= 4.0) {
  74 + next_r = r * r - s * s + x;
  75 + next_s = 2 * r * s + y;
  76 + r = next_r; s = next_s;
  77 + if (++itt == 100)
  78 + break;
  79 + }
  80 +
  81 + return itt;
  82 +}
  83 +
  84 +//Our 'main' function
  85 +void CreateMap()
  86 +{
  87 + int x, y, color; //Holds the result of slove
  88 +
  89 + for(y = 0; y < HEIGHT; y++) //Main loop for map generation
  90 + for(x = 0; x < WIDTH; x++) {
  91 + color = solve(translate_x(x), translate_y(y)) * colorcount / 100;
  92 + crc += colortable[color];
  93 + }
  94 +}
  95 +
  96 +
  97 +int RoadMap()
  98 +{
  99 + int i;
  100 + double deltaxmin, deltaymin, deltaxmax,deltaymax;
  101 +
  102 + box_x_min = -1.5; box_x_max = 0.5; //Set the map bounding box for total map
  103 + box_y_min = -1.0; box_y_max = 1.0;
  104 +
  105 + deltaxmin = (-0.9 - box_x_min) / zooms;
  106 + deltaxmax = (-0.65 - box_x_max) / zooms;
  107 + deltaymin = (-0.4 - box_y_min) / zooms;
  108 + deltaymax = (-0.1 - box_y_max) / zooms;
  109 +
  110 + CreateMap(); //Call our main
  111 + for (i = 0; i < zooms; i++){
  112 + box_x_min += deltaxmin;
  113 + box_x_max += deltaxmax;
  114 + box_y_min += deltaymin;
  115 + box_y_max += deltaymax;
  116 + CreateMap(); //Call our main
  117 + }
  118 +
  119 + return 0;
  120 +}
  121 +
  122 +int main(){
  123 + char buf[256];
  124 +
  125 + RoadMap();
  126 +
  127 + printf("NB: This version has a bug... but where?\n");
  128 + printf("CRC is %x\n", crc);
  129 +
  130 + return 0;
  131 +}
... ...
lectures/tools-code/proftest.c 0 → 100644
  1 +/*
  2 + * Compiles cleanly with gcc proftest.c
  3 + *
  4 + * For profiling / debugging: gcc -pg proftest.c, run the program (a.out) and
  5 + * inspect the output with gprof a.out
  6 + *
  7 + * Warnings: -Wall - what happens?
  8 + *
  9 + * Static checking: try splint proftest.c
  10 + *
  11 + *
  12 + * The source code is from a simple Mandelbrot benchmark / mandatory exercise in inf-3201.
  13 + */
  14 +
  15 +#include <stdio.h>
  16 +
  17 +int zooms = 10;
  18 +
  19 +const int WIDTH = 500;
  20 +const int HEIGHT = 500;
  21 +
  22 +int crc = 0;
  23 +
  24 +enum fake_cols {
  25 + WHITE,
  26 + BLUE,
  27 + CYAN,
  28 + BLACK,
  29 + GREEN,
  30 + MAGENTA,
  31 + ORANGE,
  32 + PINK,
  33 + RED,
  34 + YELLOW,
  35 + };
  36 +
  37 +
  38 +int colortable[] = {
  39 + WHITE,
  40 + WHITE,
  41 + BLUE,
  42 + CYAN,
  43 + BLACK,
  44 + GREEN,
  45 + MAGENTA,
  46 + ORANGE,
  47 + PINK,
  48 + RED,
  49 + YELLOW
  50 +};
  51 +
  52 +int colorcount = 10;
  53 +
  54 +double box_x_min, box_x_max, box_y_min, box_y_max;
  55 +
  56 +inline double translate_x(int x) {
  57 + return (((box_x_max - box_x_min) / WIDTH) * x) + box_x_min;
  58 +}
  59 +
  60 +inline double translate_y(int y) {
  61 + return (((box_y_max - box_y_min) / HEIGHT) * y) + box_y_min;
  62 +}
  63 +
  64 +// Simple Mandelbrot divergation test
  65 +inline int solve(double x, double y)
  66 +{
  67 + double r = 0.0, s = 0.0;
  68 + double next_r, next_s;
  69 + int itt = 0;
  70 +
  71 + while ((r * r + s * s) <= 4.0) {
  72 + next_r = r * r - s * s + x;
  73 + next_s = 2 * r * s + y;
  74 + r = next_r; s = next_s;
  75 + if (++itt == 100)
  76 + break;
  77 + }
  78 +
  79 + return itt;
  80 +}
  81 +
  82 +//Our 'main' function
  83 +void CreateMap()
  84 +{
  85 + int x, y, color; //Holds the result of slove
  86 +
  87 + for(y = 0; y < HEIGHT; y++) //Main loop for map generation
  88 + for(x = 0; x < WIDTH; x++) {
  89 + color = solve(translate_x(x), translate_y(y)) * colorcount / 100;
  90 + crc += colortable[color];
  91 + }
  92 +}
  93 +
  94 +
  95 +int RoadMap()
  96 +{
  97 + int i;
  98 + double deltaxmin, deltaymin, deltaxmax,deltaymax;
  99 +
  100 + box_x_min = -1.5; box_x_max = 0.5; //Set the map bounding box for total map
  101 + box_y_min = -1.0; box_y_max = 1.0;
  102 +
  103 + deltaxmin = (-0.9 - box_x_min) / zooms;
  104 + deltaxmax = (-0.65 - box_x_max) / zooms;
  105 + deltaymin = (-0.4 - box_y_min) / zooms;
  106 + deltaymax = (-0.1 - box_y_max) / zooms;
  107 +
  108 + CreateMap(); //Call our main
  109 + for (i = 0; i < zooms; i++){
  110 + box_x_min += deltaxmin;
  111 + box_x_max += deltaxmax;
  112 + box_y_min += deltaymin;
  113 + box_y_max += deltaymax;
  114 + CreateMap(); //Call our main
  115 + }
  116 +
  117 + return 0;
  118 +}
  119 +
  120 +int main(){
  121 + char buf[256];
  122 +
  123 + RoadMap();
  124 +
  125 + printf("CRC is %x\n", crc);
  126 +
  127 + return 0;
  128 +}
... ...
lectures/tools-code/t/NOTES.txt 0 → 100644
  1 +gcc -g proftest.c
  2 +nemiver a.out
  3 +
  4 +
  5 +pydb python debugger som virker med ddd !
  6 +
  7 +
  8 +
... ...
lectures/tools-code/t/proftest.c 0 → 100644
  1 +/*
  2 + * Compiles cleanly with gcc proftest.c
  3 + *
  4 + * For profiling / debugging: gcc -pg proftest.c, run the program (a.out) and
  5 + * inspect the output with gprof a.out
  6 + *
  7 + * Warnings: -Wall - what happens?
  8 + *
  9 + * Static checking: try splint proftest.c
  10 + *
  11 + *
  12 + * The source code is from a simple Mandelbrot benchmark / mandatory exercise in inf-3201.
  13 + */
  14 +
  15 +#include <stdio.h>
  16 +
  17 +int zooms = 10;
  18 +
  19 +const int WIDTH = 500;
  20 +const int HEIGHT = 500;
  21 +
  22 +int crc = 0;
  23 +
  24 +enum fake_cols {
  25 + WHITE,
  26 + BLUE,
  27 + CYAN,
  28 + BLACK,
  29 + GREEN,
  30 + MAGENTA,
  31 + ORANGE,
  32 + PINK,
  33 + RED,
  34 + YELLOW,
  35 + };
  36 +
  37 +
  38 +int colortable[] = {
  39 + WHITE,
  40 + WHITE,
  41 + BLUE,
  42 + CYAN,
  43 + BLACK,
  44 + GREEN,
  45 + MAGENTA,
  46 + ORANGE,
  47 + PINK,
  48 + RED,
  49 + YELLOW
  50 +};
  51 +
  52 +int colorcount = 10;
  53 +
  54 +double box_x_min, box_x_max, box_y_min, box_y_max;
  55 +
  56 +inline double translate_x(int x) {
  57 + return (((box_x_max - box_x_min) / WIDTH) * x) + box_x_min;
  58 +}
  59 +
  60 +inline double translate_y(int y) {
  61 + return (((box_y_max - box_y_min) / HEIGHT) * y) + box_y_min;
  62 +}
  63 +
  64 +// Simple Mandelbrot divergation test
  65 +inline int solve(double x, double y)
  66 +{
  67 + double r = 0.0, s = 0.0;
  68 + double next_r, next_s;
  69 + int itt = 0;
  70 +
  71 + while ((r * r + s * s) <= 4.0) {
  72 + next_r = r * r - s * s + x;
  73 + next_s = 2 * r * s + y;
  74 + r = next_r; s = next_s;
  75 + if (++itt == 100)
  76 + break;
  77 + }
  78 +
  79 + return itt;
  80 +}
  81 +
  82 +//Our 'main' function
  83 +void CreateMap()
  84 +{
  85 + int x, y, color; //Holds the result of slove
  86 +
  87 + for(y = 0; y < HEIGHT; y++) //Main loop for map generation
  88 + for(x = 0; x < WIDTH; x++) {
  89 + color = solve(translate_x(x), translate_y(y)) * colorcount / 100;
  90 + crc += colortable[color];
  91 + }
  92 +}
  93 +
  94 +
  95 +int RoadMap()
  96 +{
  97 + int i;
  98 + double deltaxmin, deltaymin, deltaxmax,deltaymax;
  99 +
  100 + box_x_min = -1.5; box_x_max = 0.5; //Set the map bounding box for total map
  101 + box_y_min = -1.0; box_y_max = 1.0;
  102 +
  103 + deltaxmin = (-0.9 - box_x_min) / zooms;
  104 + deltaxmax = (-0.65 - box_x_max) / zooms;
  105 + deltaymin = (-0.4 - box_y_min) / zooms;
  106 + deltaymax = (-0.1 - box_y_max) / zooms;
  107 +
  108 + CreateMap(); //Call our main
  109 + for (i = 0; i < zooms; i++){
  110 + box_x_min += deltaxmin;
  111 + box_x_max += deltaxmax;
  112 + box_y_min += deltaymin;
  113 + box_y_max += deltaymax;
  114 + CreateMap(); //Call our main
  115 + }
  116 +
  117 + return 0;
  118 +}
  119 +
  120 +int main(){
  121 + char buf[256];
  122 +
  123 + RoadMap();
  124 +
  125 + printf("CRC is %x\n", crc);
  126 +
  127 + return 0;
  128 +}
... ...
lectures/tools-code/t2/NOTES.txt 0 → 100644
  1 +gcc -g proftest.c
  2 +nemiver a.out
  3 +
  4 +
  5 +pydb python debugger som virker med ddd !
  6 +
  7 +
  8 +
... ...
lectures/tools-code/t2/proftest.c 0 → 100644
  1 +/*
  2 + * Compiles cleanly with gcc proftest.c
  3 + *
  4 + * For profiling / debugging: gcc -pg proftest.c, run the program (a.out) and
  5 + * inspect the output with gprof a.out
  6 + *
  7 + * Warnings: -Wall - what happens?
  8 + *
  9 + * Static checking: try splint proftest.c
  10 + *
  11 + *
  12 + * The source code is from a simple Mandelbrot benchmark / mandatory exercise in inf-3201.
  13 + *
  14 + * NB: this version has a bug. How do you compare it with the original?
  15 + */
  16 +
  17 +#include <stdio.h>
  18 +
  19 +int zooms = 10;
  20 +
  21 +const int WIDTH = 500;
  22 +const int HEIGHT = 600;
  23 +
  24 +int crc = 0;
  25 +
  26 +enum fake_cols {
  27 + WHITE,
  28 + BLUE,
  29 + CYAN,
  30 + BLACK,
  31 + GREEN,
  32 + MAGENTA,
  33 + ORANGE,
  34 + PINK,
  35 + RED,
  36 + YELLOW,
  37 + };
  38 +
  39 +
  40 +int colortable[] = {
  41 + WHITE,
  42 + WHITE,
  43 + BLUE,
  44 + CYAN,
  45 + BLACK,
  46 + GREEN,
  47 + MAGENTA,
  48 + ORANGE,
  49 + PINK,
  50 + RED,
  51 + YELLOW
  52 +};
  53 +
  54 +int colorcount = 10;
  55 +
  56 +double box_x_min, box_x_max, box_y_min, box_y_max;
  57 +
  58 +inline double translate_x(int x) {
  59 + return (((box_x_max - box_x_min) / WIDTH) * x) + box_y_min;
  60 +}
  61 +
  62 +inline double translate_y(int y) {
  63 + return (((box_y_max - box_y_min) / HEIGHT) * y) + box_x_min;
  64 +}
  65 +
  66 +// Simple Mandelbrot divergation test
  67 +inline int solve(double x, double y)
  68 +{
  69 + double r = 0.0, s = 0.0;
  70 + double next_r, next_s;
  71 + int itt = 0;
  72 +
  73 + while ((r * r + s * s) <= 4.0) {
  74 + next_r = r * r - s * s + x;
  75 + next_s = 2 * r * s + y;
  76 + r = next_r; s = next_s;
  77 + if (++itt == 100)
  78 + break;
  79 + }
  80 +
  81 + return itt;
  82 +}
  83 +
  84 +//Our 'main' function
  85 +void CreateMap()
  86 +{
  87 + int x, y, color; //Holds the result of slove
  88 +
  89 + for(y = 0; y < HEIGHT; y++) //Main loop for map generation
  90 + for(x = 0; x < WIDTH; x++) {
  91 + color = solve(translate_x(x), translate_y(y)) * colorcount / 100;
  92 + crc += colortable[color];
  93 + }
  94 +}
  95 +
  96 +
  97 +int RoadMap()
  98 +{
  99 + int i;
  100 + double deltaxmin, deltaymin, deltaxmax,deltaymax;
  101 +
  102 + box_x_min = -1.5; box_x_max = 0.5; //Set the map bounding box for total map
  103 + box_y_min = -1.0; box_y_max = 1.0;
  104 +
  105 + deltaxmin = (-0.9 - box_x_min) / zooms;
  106 + deltaxmax = (-0.65 - box_x_max) / zooms;
  107 + deltaymin = (-0.4 - box_y_min) / zooms;
  108 + deltaymax = (-0.1 - box_y_max) / zooms;
  109 +
  110 + CreateMap(); //Call our main
  111 + for (i = 0; i < zooms; i++){
  112 + box_x_min += deltaxmin;
  113 + box_x_max += deltaxmax;
  114 + box_y_min += deltaymin;
  115 + box_y_max += deltaymax;
  116 + CreateMap(); //Call our main
  117 + }
  118 +
  119 + return 0;
  120 +}
  121 +
  122 +int main(){
  123 + char buf[256];
  124 +
  125 + RoadMap();
  126 +
  127 + printf("NB: This version has a bug... but where?\n");
  128 + printf("CRC is %x\n", crc);
  129 +
  130 + return 0;
  131 +}
... ...
lectures/tools-handouts.pdf 0 → 100644
No preview for this file type
lectures/tools.pdf 0 → 100644
No preview for this file type