Commit 9124ad138206efba650871cd8d27e9d051e55dfa

Authored by Jim Plank
1 parent 9cca12d4
Exists in master and in 1 other branch v2

Ran through all of the examples to make them current. I'll have to

do another sanity-checking pass, and fix multby_2 in the reed_sol code,
but then we're done.
Examples/Makefile.am
... ... @@ -17,7 +17,6 @@ bin_PROGRAMS = jerasure_01 \
17 17 reed_sol_04 \
18 18 reed_sol_test_gf \
19 19 reed_sol_time_gf \
20   - reed_sol_hard_time_gf \
21 20 cauchy_01 \
22 21 cauchy_02 \
23 22 cauchy_03 \
... ... @@ -68,9 +67,6 @@ reed_sol_test_gf_LDADD = ../src/libJerasure.la
68 67 reed_sol_time_gf_SOURCES = reed_sol_time_gf.c
69 68 reed_sol_time_gf_LDADD = ../src/libJerasure.la
70 69  
71   -reed_sol_hard_time_gf_SOURCES = reed_sol_hard_time_gf.c
72   -reed_sol_hard_time_gf_LDADD = ../src/libJerasure.la
73   -
74 70 cauchy_01_SOURCES = cauchy_01.c
75 71 cauchy_01_LDADD = ../src/libJerasure.la
76 72  
... ...
Examples/Makefile.in
... ... @@ -41,7 +41,7 @@ bin_PROGRAMS = jerasure_01$(EXEEXT) jerasure_02$(EXEEXT) \
41 41 jerasure_06$(EXEEXT) jerasure_07$(EXEEXT) jerasure_08$(EXEEXT) \
42 42 reed_sol_01$(EXEEXT) reed_sol_02$(EXEEXT) reed_sol_03$(EXEEXT) \
43 43 reed_sol_04$(EXEEXT) reed_sol_test_gf$(EXEEXT) \
44   - reed_sol_time_gf$(EXEEXT) reed_sol_hard_time_gf$(EXEEXT) \
  44 + reed_sol_time_gf$(EXEEXT) \
45 45 cauchy_01$(EXEEXT) cauchy_02$(EXEEXT) cauchy_03$(EXEEXT) \
46 46 cauchy_04$(EXEEXT) liberation_01$(EXEEXT) encoder$(EXEEXT) \
47 47 decoder$(EXEEXT)
... ... @@ -120,9 +120,6 @@ reed_sol_03_DEPENDENCIES = ../src/libJerasure.la
120 120 am_reed_sol_04_OBJECTS = reed_sol_04.$(OBJEXT)
121 121 reed_sol_04_OBJECTS = $(am_reed_sol_04_OBJECTS)
122 122 reed_sol_04_DEPENDENCIES = ../src/libJerasure.la
123   -am_reed_sol_hard_time_gf_OBJECTS = reed_sol_hard_time_gf.$(OBJEXT)
124   -reed_sol_hard_time_gf_OBJECTS = $(am_reed_sol_hard_time_gf_OBJECTS)
125   -reed_sol_hard_time_gf_DEPENDENCIES = ../src/libJerasure.la
126 123 am_reed_sol_test_gf_OBJECTS = reed_sol_test_gf.$(OBJEXT)
127 124 reed_sol_test_gf_OBJECTS = $(am_reed_sol_test_gf_OBJECTS)
128 125 reed_sol_test_gf_DEPENDENCIES = ../src/libJerasure.la
... ... @@ -150,7 +147,7 @@ SOURCES = $(cauchy_01_SOURCES) $(cauchy_02_SOURCES) \
150 147 $(jerasure_08_SOURCES) $(liberation_01_SOURCES) \
151 148 $(reed_sol_01_SOURCES) $(reed_sol_02_SOURCES) \
152 149 $(reed_sol_03_SOURCES) $(reed_sol_04_SOURCES) \
153   - $(reed_sol_hard_time_gf_SOURCES) $(reed_sol_test_gf_SOURCES) \
  150 + $(reed_sol_test_gf_SOURCES) \
154 151 $(reed_sol_time_gf_SOURCES)
155 152 DIST_SOURCES = $(cauchy_01_SOURCES) $(cauchy_02_SOURCES) \
156 153 $(cauchy_03_SOURCES) $(cauchy_04_SOURCES) $(decoder_SOURCES) \
... ... @@ -161,7 +158,7 @@ DIST_SOURCES = $(cauchy_01_SOURCES) $(cauchy_02_SOURCES) \
161 158 $(jerasure_08_SOURCES) $(liberation_01_SOURCES) \
162 159 $(reed_sol_01_SOURCES) $(reed_sol_02_SOURCES) \
163 160 $(reed_sol_03_SOURCES) $(reed_sol_04_SOURCES) \
164   - $(reed_sol_hard_time_gf_SOURCES) $(reed_sol_test_gf_SOURCES) \
  161 + $(reed_sol_test_gf_SOURCES) \
165 162 $(reed_sol_time_gf_SOURCES)
166 163 ETAGS = etags
167 164 CTAGS = ctags
... ... @@ -306,8 +303,6 @@ reed_sol_test_gf_SOURCES = reed_sol_test_gf.c
306 303 reed_sol_test_gf_LDADD = ../src/libJerasure.la
307 304 reed_sol_time_gf_SOURCES = reed_sol_time_gf.c
308 305 reed_sol_time_gf_LDADD = ../src/libJerasure.la
309   -reed_sol_hard_time_gf_SOURCES = reed_sol_hard_time_gf.c
310   -reed_sol_hard_time_gf_LDADD = ../src/libJerasure.la
311 306 cauchy_01_SOURCES = cauchy_01.c
312 307 cauchy_01_LDADD = ../src/libJerasure.la
313 308 cauchy_02_SOURCES = cauchy_02.c
... ... @@ -456,9 +451,6 @@ reed_sol_03$(EXEEXT): $(reed_sol_03_OBJECTS) $(reed_sol_03_DEPENDENCIES) $(EXTRA
456 451 reed_sol_04$(EXEEXT): $(reed_sol_04_OBJECTS) $(reed_sol_04_DEPENDENCIES) $(EXTRA_reed_sol_04_DEPENDENCIES)
457 452 @rm -f reed_sol_04$(EXEEXT)
458 453 $(LINK) $(reed_sol_04_OBJECTS) $(reed_sol_04_LDADD) $(LIBS)
459   -reed_sol_hard_time_gf$(EXEEXT): $(reed_sol_hard_time_gf_OBJECTS) $(reed_sol_hard_time_gf_DEPENDENCIES) $(EXTRA_reed_sol_hard_time_gf_DEPENDENCIES)
460   - @rm -f reed_sol_hard_time_gf$(EXEEXT)
461   - $(LINK) $(reed_sol_hard_time_gf_OBJECTS) $(reed_sol_hard_time_gf_LDADD) $(LIBS)
462 454 reed_sol_test_gf$(EXEEXT): $(reed_sol_test_gf_OBJECTS) $(reed_sol_test_gf_DEPENDENCIES) $(EXTRA_reed_sol_test_gf_DEPENDENCIES)
463 455 @rm -f reed_sol_test_gf$(EXEEXT)
464 456 $(LINK) $(reed_sol_test_gf_OBJECTS) $(reed_sol_test_gf_LDADD) $(LIBS)
... ...
Examples/cauchy_01.c
1 1 /* *
2   - * Copyright (c) 2013, James S. Plank and Kevin Greenan
  2 + * Copyright (c) 2014, James S. Plank and Kevin Greenan
3 3 * All rights reserved.
4 4 *
5 5 * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
... ... @@ -39,6 +39,7 @@
39 39  
40 40  
41 41 #include <stdio.h>
  42 +#include <stdint.h>
42 43 #include <stdlib.h>
43 44 #include <string.h>
44 45 #include "jerasure.h"
... ... @@ -48,36 +49,56 @@
48 49  
49 50 usage(char *s)
50 51 {
51   - fprintf(stderr, "usage: cauchy_01 n w - Prints the number of ones in the bitmatrix representation of n in GF(2^w).\n");
  52 + fprintf(stderr, "usage: cauchy_01 n w - Converts the value n to a bitmatrix using GF(2^w).\n");
52 53 fprintf(stderr, " \n");
53   - fprintf(stderr, " It also prints out the bit-matrix and confirms that the number of ones is correct.\n");
  54 + fprintf(stderr, " It prints the bitmatrix, and reports on the numberof ones.\n");
  55 + fprintf(stderr, " Use 0x to input n in hexadecimal.\n");
  56 + fprintf(stderr, " W must be <= 32.\n");
54 57 fprintf(stderr, " \n");
55 58 fprintf(stderr, "This demonstrates: cauchy_n_ones()\n");
56 59 fprintf(stderr, " jerasure_matrix_to_bitmatrix()\n");
57 60 fprintf(stderr, " jerasure_print_bitmatrix()\n");
58   - if (s != NULL) fprintf(stderr, "%s\n", s);
  61 + if (s != NULL) fprintf(stderr, "\n%s\n", s);
59 62 exit(1);
60 63 }
61 64  
62 65 int main(int argc, char **argv)
63 66 {
64   - int n, i, no, w;
  67 + uint32_t n;
  68 + int i, no, w;
65 69 int *bitmatrix;
66 70  
67 71 if (argc != 3) usage(NULL);
68   - if (sscanf(argv[1], "%d", &n) == 0 || n <= 0) usage("Bad n");
  72 + if (sscanf(argv[1], "0x%x", &n) == 0) {
  73 + if (sscanf(argv[1], "%d", &n) == 0) usage("Bad n");
  74 + }
69 75 if (sscanf(argv[2], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w");
70   - if (w < 30 && n >= (1 << w)) usage("n is too big");
  76 + if (w == 31) {
  77 + if (n & 0x80000000L) usage("Bad n/w combination (n not between 0 and 2^w-1)\n");
  78 + } else if (w < 31) {
  79 + if (n >= (1 << w)) usage("Bad n/w combination (n not between 0 and 2^w-1)\n");
  80 + }
71 81  
72 82 bitmatrix = jerasure_matrix_to_bitmatrix(1, 1, w, &n);
  83 + printf("<HTML><title>cauchy_01 %u %d</title>\n", w, n);
  84 + printf("<HTML><h3>cauchy_01 %u %d</h3>\n", w, n);
  85 + printf("<pre>\n");
  86 + if (w == 32) {
  87 + printf("Converted the value 0x%x to the following bitmatrix:\n\n", n);
  88 + } else {
  89 + printf("Converted the value %d (0x%x) to the following bitmatrix:\n\n", n, n);
  90 + }
  91 + jerasure_print_bitmatrix(bitmatrix, w, w, w);
  92 + printf("\n");
  93 +
73 94 no = 0;
74 95 for (i = 0; i < w*w; i++) no += bitmatrix[i];
  96 + if (no != cauchy_n_ones(n, w)) {
  97 + fprintf(stderr, "Jerasure error: # ones in the bitmatrix (%d) doesn't match cauchy_n_ones() (%d).\n",
  98 + no, cauchy_n_ones(n, w));
  99 + exit(1);
  100 + }
75 101  
76 102 printf("# Ones: %d\n", cauchy_n_ones(n, w));
77   - printf("\n");
78   - printf("Bitmatrix has %d ones\n", no);
79   - printf("\n");
80   - jerasure_print_bitmatrix(bitmatrix, w, w, w);
81   -
82 103 return 0;
83 104 }
... ...
Examples/cauchy_02.c
... ... @@ -37,15 +37,15 @@
37 37 * POSSIBILITY OF SUCH DAMAGE.
38 38 */
39 39  
40   -
41   -
42 40 /*
43   - revised by S. Simmerman
44   - 2/25/08
  41 + revised by S. Simmerman 2/25/08
  42 + Re-revised by JSP to use GF-Complete - 1/2014
45 43 */
46 44 #include <stdio.h>
47 45 #include <stdlib.h>
  46 +#include <stdint.h>
48 47 #include <string.h>
  48 +#include <gf_rand.h>
49 49 #include "jerasure.h"
50 50 #include "cauchy.h"
51 51  
... ... @@ -53,79 +53,76 @@
53 53  
54 54 usage(char *s)
55 55 {
56   - fprintf(stderr, "usage: cauchy_02 k m w - Scheduled CRS coding example with the original matrix in GF(2^w).\n");
57   - fprintf(stderr, " \n");
58   - fprintf(stderr, " k+m must be <= 2^w. It sets up a Cauchy distribution matrix using the original\n");
59   - fprintf(stderr, " Cauchy Distribution matrix construction algorithm, then it encodes\n");
60   - fprintf(stderr, " k devices of w*%d bytes using smart bit-matrix scheduling.\n", sizeof(long));
61   - fprintf(stderr, " It decodes using bit-matrix scheduling as well.\n");
  56 + fprintf(stderr, "usage: cauchy_02 k m w seed - CRS coding example using Bloemer's original matrix.\n");
62 57 fprintf(stderr, " \n");
  58 + fprintf(stderr, "k+m must be <= 2^w\n");
  59 + fprintf(stderr, "This sets up a generator matrix (G^T) in GF(2^w) whose last m rows are\n");
  60 + fprintf(stderr, "created from a Cauchy matrix, using the original definition from [Bloemer95].\n");
  61 + fprintf(stderr, "It converts this matrix to a bitmatrix, and then it encodes w packets from\n");
  62 + fprintf(stderr, "each of k disks (simulated) onto w packets on each of m disks. Packets are \n");
  63 + fprintf(stderr, "simply longs. Then, it deletes m random disks, and decodes. \n");
  64 + fprintf(stderr, "\n");
  65 + fprintf(stderr, "The encoding and decoding are done twice, first, with jerasure_bitmatrix_encode()\n");
  66 + fprintf(stderr, "and jerasure_bitmatrix_decode(), and second using 'smart' scheduling with\n");
  67 + fprintf(stderr, "jerasure_schedule_encode() and jerasure_schedule_decode_lazy().\n");
  68 +
  69 + fprintf(stderr, "\n");
63 70 fprintf(stderr, "This demonstrates: cauchy_original_coding_matrix()\n");
64   - fprintf(stderr, " cauchy_xy_coding_matrix()\n");
  71 + fprintf(stderr, " jerasure_bitmatrix_encode()\n");
  72 + fprintf(stderr, " jerasure_bitmatrix_decode()\n");
65 73 fprintf(stderr, " cauchy_n_ones()\n");
66 74 fprintf(stderr, " jerasure_smart_bitmatrix_to_schedule()\n");
67 75 fprintf(stderr, " jerasure_schedule_encode()\n");
68 76 fprintf(stderr, " jerasure_schedule_decode_lazy()\n");
69 77 fprintf(stderr, " jerasure_print_matrix()\n");
  78 + fprintf(stderr, " jerasure_print_bitmatrix()\n");
70 79 fprintf(stderr, " jerasure_get_stats()\n");
71 80 if (s != NULL) fprintf(stderr, "%s\n", s);
72 81 exit(1);
73 82 }
74 83  
75   -static void print_data_and_coding(int k, int m, int w, int psize,
76   - char **data, char **coding)
  84 +static print_array(char **ptrs, int ndevices, int size, int packetsize, char *label)
77 85 {
78   - int i, j, x, n, sp;
79   - long l;
80   -
81   - if(k > m) n = k;
82   - else n = m;
83   - sp = psize * 2 + (psize/4) + 12;
84   -
85   - printf("%-*sCoding\n", sp, "Data");
86   - for(i = 0; i < n; i++) {
87   - for (j = 0; j < w; j++) {
88   - if(i < k) {
89   -
90   - if(j==0) printf("D%-2d p%-2d:", i,j);
91   - else printf(" p%-2d:", j);
92   - for(x = 0; x < psize; x +=4) {
93   - memcpy(&l, data[i]+j*psize+x, sizeof(long));
94   - printf(" %08lx", l);
95   - }
96   - printf(" ");
97   - }
98   - else printf("%*s", sp, "");
99   - if(i < m) {
100   - if(j==0) printf("C%-2d p%-2d:", i,j);
101   - else printf(" p%-2d:", j);
102   - for(x = 0; x < psize; x +=4) {
103   - memcpy(&l, coding[i]+j*psize+x, sizeof(long));
104   - printf(" %08lx", l);
105   - }
106   - }
107   - printf("\n");
108   - }
109   - }
110   -
111   - printf("\n");
  86 + int i, j, x;
  87 + unsigned char *up;
  88 +
  89 + printf("<center><table border=3 cellpadding=3><tr><td></td>\n");
  90 +
  91 + for (i = 0; i < ndevices; i++) printf("<td align=center>%s%x</td>\n", label, i);
  92 + printf("</tr>\n");
  93 + printf("<td align=right><pre>");
  94 + for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
  95 + printf("</pre></td>\n");
  96 + for (i = 0; i < ndevices; i++) {
  97 + printf("<td><pre>");
  98 + up = (unsigned char *) ptrs[i];
  99 + for (j = 0; j < size/packetsize; j++) {
  100 + for (x = 0; x < packetsize; x++) {
  101 + if (x > 0 && x%4 == 0) printf(" ");
  102 + printf("%02x", up[j*packetsize+x]);
  103 + }
  104 + printf("\n");
  105 + }
  106 + printf("</td>\n");
  107 + }
  108 + printf("</tr></table></center>\n");
112 109 }
113 110  
114 111 int main(int argc, char **argv)
115 112 {
116   - long l;
117 113 int k, w, i, j, m;
118   - int *matrix, *bitmatrix, *m2, *x, *y;
119   - char **data, **coding, **ptrs;
120   - int **smart;
  114 + int *matrix, *bitmatrix, **schedule;
  115 + char **data, **coding, **ptrs, **dcopy, **ccopy;
121 116 int no;
122 117 int *erasures, *erased;
123   - double stats[3];
  118 + double mstats[3], sstats[3];
  119 + uint32_t seed;
124 120  
125   - if (argc != 4) usage(NULL);
  121 + if (argc != 5) usage(NULL);
126 122 if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
127 123 if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
128 124 if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w");
  125 + if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed");
129 126 if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big");
130 127  
131 128 matrix = cauchy_original_coding_matrix(k, m, w);
... ... @@ -133,42 +130,90 @@ int main(int argc, char **argv)
133 130 usage("couldn't make coding matrix");
134 131 }
135 132  
  133 + /* Print out header information to the output file. */
  134 + printf("<HTML>\n");
  135 + printf("<TITLE>Jerasure Example Output: cauchy_02 %d %d %d %d</TITLE>\n", k, m, w, seed);
  136 + printf("<h2>Jerasure Example Output: cauchy_02 %d %d %d %d</h3>\n", k, m, w, seed);
  137 +
  138 + printf("<hr>\n");
  139 + printf("Parameters:\n");
  140 + printf("<UL><LI> Number of data disks <i>(k)</i>: %d\n", k);
  141 + printf("<LI> Number of coding disks <i>(m)</i>: %d\n", m);
  142 + printf("<LI> Word size of the Galois Field: <i>(w)</i>: %d\n", w);
  143 + printf("<LI> Seed for the random number generator: %d\n", seed);
  144 + printf("<LI> Number of bytes stored per disk: %ld\n", sizeof(long)*w);
  145 + printf("<LI> Number of packets stored per disk: %d\n", w);
  146 + printf("<LI> Number of bytes per packet: %ld\n", sizeof(long));
  147 + printf("</UL>\n");
  148 +
  149 + /* Print out the matrix and the bitmatrix */
  150 + printf("<hr>\n");
  151 + printf("Here is the matrix, which was created with <b>cauchy_original_coding_matrix()</b>.\n");
  152 + printf("This is not the best matrix to use, but we include it to show an example\n");
  153 + printf("of <b>cauchy_original_coding_matrix()</b>. For the best matrix and encoding/decoding\n");
  154 + printf("methodology, see <b>cauchy_04.</b><p><pre>\n");
  155 +
  156 + jerasure_print_matrix(matrix, m, k, w);
  157 + printf("</pre>\n");
  158 +
  159 + bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix);
  160 +
136 161 no = 0;
137 162 for (i = 0; i < k*m; i++) {
138 163 no += cauchy_n_ones(matrix[i], w);
139 164 }
140   - printf("Matrix has %d ones\n\n", no);
141   - jerasure_print_matrix(matrix, m, k, w);
142   - printf("\n", no);
143   - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix);
144 165  
145   - smart = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix);
  166 + printf("The bitmatrix, which has %d one%s:<p><pre>\n", no, (no == 1) ? "" : "s");
  167 + jerasure_print_bitmatrix(bitmatrix, m*w, k*w, w);
  168 + printf("</pre>\n");
  169 + printf("<hr>\n");
  170 + MOA_Seed(seed);
146 171  
147   - srand48(0);
148 172 data = talloc(char *, k);
  173 + dcopy = talloc(char *, k);
149 174 for (i = 0; i < k; i++) {
150 175 data[i] = talloc(char, sizeof(long)*w);
151   - for (j = 0; j < w; j++) {
152   - l = lrand48();
153   - memcpy(data[i]+j*sizeof(long), &l, sizeof(long));
154   - }
  176 + dcopy[i] = talloc(char, sizeof(long)*w);
  177 + MOA_Fill_Random_Region(data[i], sizeof(long)*w);
  178 + memcpy(dcopy[i], data[i], sizeof(long)*w);
155 179 }
156 180  
  181 + printf("Here are the packets on the data disks:<p>\n");
  182 + print_array(data, k, sizeof(long)*w, sizeof(long), "D");
  183 +
157 184 coding = talloc(char *, m);
  185 + ccopy = talloc(char *, m);
158 186 for (i = 0; i < m; i++) {
159 187 coding[i] = talloc(char, sizeof(long)*w);
  188 + ccopy[i] = talloc(char, sizeof(long)*w);
160 189 }
161 190  
162   - jerasure_schedule_encode(k, m, w, smart, data, coding, w*sizeof(long), sizeof(long));
163   - jerasure_get_stats(stats);
164   - printf("Smart Encoding Complete: - %.0lf XOR'd bytes\n\n", stats[0]);
165   - print_data_and_coding(k, m, w, sizeof(long), data, coding);
  191 + jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long));
  192 + jerasure_get_stats(mstats);
  193 +
  194 + schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix);
  195 + jerasure_schedule_encode(k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long));
  196 + jerasure_get_stats(sstats);
  197 +
  198 + printf("<p>Encoding with jerasure_bitmatrix_encode() - Bytes XOR'd: %.0lf.<br>\n", mstats[0]);
  199 + printf("Encoding with jerasure_schedule_encode() - Bytes XOR'd: %.0lf.<br>\n", sstats[0]);
  200 +
  201 + for (i = 0; i < m; i++) {
  202 + if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) {
  203 + printf("Problem: the two encodings don't match on disk C%x\n", i);
  204 + exit(0);
  205 + }
  206 + }
  207 +
  208 + printf("Here are the packets on the coding disks.<br>\n");
  209 + print_array(coding, m, sizeof(long)*w, sizeof(long), "C");
  210 + printf("<hr>\n");
166 211  
167 212 erasures = talloc(int, (m+1));
168 213 erased = talloc(int, (k+m));
169 214 for (i = 0; i < m+k; i++) erased[i] = 0;
170 215 for (i = 0; i < m; ) {
171   - erasures[i] = lrand48()%(k+m);
  216 + erasures[i] = MOA_Random_W(31, 1)%(k+m);
172 217 if (erased[erasures[i]] == 0) {
173 218 erased[erasures[i]] = 1;
174 219 bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w);
... ... @@ -176,29 +221,47 @@ int main(int argc, char **argv)
176 221 }
177 222 }
178 223 erasures[i] = -1;
  224 + printf("Erasures on the following devices:");
  225 + for (i = 0; erasures[i] != -1; i++) {
  226 + printf(" %c%x", ((erasures[i] < k) ? 'D' : 'C'), (erasures[i] < k ? erasures[i] : erasures[i]-k));
  227 + }
  228 + printf("<br>\nHere is the state of the system:\n<p>\n");
  229 + print_array(data, k, sizeof(long)*w, sizeof(long), "D");
  230 + printf("<p>\n");
  231 + print_array(coding, m, sizeof(long)*w, sizeof(long), "C");
  232 + printf("<hr>\n");
179 233  
180   - printf("Erased %d random devices:\n\n", m);
181   - print_data_and_coding(k, m, w, sizeof(long), data, coding);
182   -
183   - jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1);
184   - jerasure_get_stats(stats);
  234 + jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long));
  235 + jerasure_get_stats(mstats);
185 236  
186   - printf("State of the system after decoding: %.0lf XOR'd bytes\n\n", stats[0]);
187   - print_data_and_coding(k, m, w, sizeof(long), data, coding);
188   -
189   - x = talloc(int, m);
190   - y = talloc(int, k);
191   - if (x == NULL || y == NULL) { perror("malloc"); exit(1); }
192   - for (i = 0; i < m; i++) x[i] = i;
193   - for (i = 0; i < k; i++) y[i] = m+i;
194   - m2 = cauchy_xy_coding_matrix(k, m, w, x, y);
195   - if (memcmp(matrix, m2, sizeof(int)*k*m) != 0) {
196   - printf("Error -- the matrices made by original and xy don't match\n");
197   - exit(1);
198   - } else {
199   - printf("Generated the identical matrix using cauchy_xy_coding_matrix()\n");
  237 + printf("<p>Decoded with jerasure_bitmatrix_decode - Bytes XOR'd: %.0lf.<br>\n", mstats[0]);
  238 +
  239 + for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) {
  240 + printf("ERROR: D%x after decoding does not match its state before decoding!<br>\n", i);
  241 + }
  242 + for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) {
  243 + printf("ERROR: C%x after decoding does not match its state before decoding!<br>\n", i);
200 244 }
201 245  
  246 + for (i = 0; erasures[i] != -1; i++) {
  247 + bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w);
  248 + }
  249 +
  250 + jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1);
  251 + jerasure_get_stats(sstats);
  252 +
  253 + printf("jerasure_schedule_decode_lazy - Bytes XOR'd: %.0lf.<br>\n", sstats[0]);
  254 +
  255 + for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) {
  256 + printf("ERROR: D%x after decoding does not match its state before decoding!<br>\n", i);
  257 + }
  258 + for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) {
  259 + printf("ERROR: C%x after decoding does not match its state before decoding!<br>\n", i);
  260 + }
202 261  
203   - return 0;
  262 + printf("Here is the state of the system:\n<p>\n");
  263 + print_array(data, k, sizeof(long)*w, sizeof(long), "D");
  264 + printf("<p>\n");
  265 + print_array(coding, m, sizeof(long)*w, sizeof(long), "C");
  266 + printf("<hr>\n");
204 267 }
... ...
Examples/cauchy_03.c
... ... @@ -37,15 +37,15 @@
37 37 * POSSIBILITY OF SUCH DAMAGE.
38 38 */
39 39  
40   -
41   -
42 40 /*
43   - revised by S. Simmerman
44   - 2/25/08
  41 + revised by S. Simmerman 2/25/08
  42 + Re-revised by JSP to use GF-Complete - 1/2014
45 43 */
46 44 #include <stdio.h>
47 45 #include <stdlib.h>
  46 +#include <stdint.h>
48 47 #include <string.h>
  48 +#include <gf_rand.h>
49 49 #include "jerasure.h"
50 50 #include "cauchy.h"
51 51  
... ... @@ -53,128 +53,185 @@
53 53  
54 54 usage(char *s)
55 55 {
56   - fprintf(stderr, "usage: cauchy_03 k m w - Scheduled CRS coding example with improved matrix in GF(2^w).\n");
57   - fprintf(stderr, " \n");
58   - fprintf(stderr, " k+m must be <= 2^w. It sets up a Cauchy distribution matrix using the original\n");
59   - fprintf(stderr, " Cauchy Distribution matrix construction algorithm, then improves it\n");
60   - fprintf(stderr, " with cauchy_improve_coding_matrix(). Then it does the same encoding and\n");
61   - fprintf(stderr, " decoding as cauchy_02.\n");
  56 + fprintf(stderr, "usage: cauchy_03 k m w seed - CRS coding example improving the matrix.\n");
62 57 fprintf(stderr, " \n");
63   - fprintf(stderr, "This demonstrates: cauchy_original_coding_matrix()\n");
  58 + fprintf(stderr, "k+m must be <= 2^w\n");
  59 + fprintf(stderr, "This sets up a generator matrix (G^T) in GF(2^w) whose last m rows are\n");
  60 + fprintf(stderr, "created from a Cauchy matrix, using the original definition from [Bloemer95].\n");
  61 + fprintf(stderr, "This is done with cauchy_xy_coding_matrix().\n");
  62 + fprintf(stderr, "\n");
  63 + fprintf(stderr, "It then it improves the matrix, which yields a different bitmatrix that is\n");
  64 + fprintf(stderr, "MDS like the original bitmatrix, but it will yield a bitmatrix with fewer ones.\n");
  65 + fprintf(stderr, "Then, it encodes w packets from each of k disks (simulated) onto w packets on\n");
  66 + fprintf(stderr, "on each of m disks. Packets are longs. Then, it deletes m random disks, and decodes.\n");
  67 + fprintf(stderr, "\n");
  68 + fprintf(stderr, "The encoding and decoding are done twice, first, with jerasure_bitmatrix_encode()\n");
  69 + fprintf(stderr, "and jerasure_bitmatrix_decode(), and second using 'smart' scheduling with\n");
  70 + fprintf(stderr, "jerasure_schedule_encode() and jerasure_schedule_decode_lazy().\n");
  71 +
  72 + fprintf(stderr, "\n");
  73 + fprintf(stderr, "This demonstrates: cauchy_xy_coding_matrix()\n");
64 74 fprintf(stderr, " cauchy_improve_coding_matrix()\n");
  75 + fprintf(stderr, " jerasure_bitmatrix_encode()\n");
  76 + fprintf(stderr, " jerasure_bitmatrix_decode()\n");
65 77 fprintf(stderr, " cauchy_n_ones()\n");
66 78 fprintf(stderr, " jerasure_smart_bitmatrix_to_schedule()\n");
67 79 fprintf(stderr, " jerasure_schedule_encode()\n");
68 80 fprintf(stderr, " jerasure_schedule_decode_lazy()\n");
69 81 fprintf(stderr, " jerasure_print_matrix()\n");
  82 + fprintf(stderr, " jerasure_print_bitmatrix()\n");
70 83 fprintf(stderr, " jerasure_get_stats()\n");
71 84 if (s != NULL) fprintf(stderr, "%s\n", s);
72 85 exit(1);
73 86 }
74 87  
75   -static void print_data_and_coding(int k, int m, int w, int psize,
76   - char **data, char **coding)
  88 +static print_array(char **ptrs, int ndevices, int size, int packetsize, char *label)
77 89 {
78   - int i, j, x, n, sp;
79   - long l;
80   -
81   - if(k > m) n = k;
82   - else n = m;
83   - sp = psize * 2 + (psize/4) + 12;
84   -
85   - printf("%-*sCoding\n", sp, "Data");
86   - for(i = 0; i < n; i++) {
87   - for (j = 0; j < w; j++) {
88   - if(i < k) {
89   -
90   - if(j==0) printf("D%-2d p%-2d:", i,j);
91   - else printf(" p%-2d:", j);
92   - for(x = 0; x < psize; x +=4) {
93   - memcpy(&l, data[i]+j*psize+x, sizeof(long));
94   - printf(" %08lx", l);
95   - }
96   - printf(" ");
97   - }
98   - else printf("%*s", sp, "");
99   - if(i < m) {
100   - if(j==0) printf("C%-2d p%-2d:", i,j);
101   - else printf(" p%-2d:", j);
102   - for(x = 0; x < psize; x +=4) {
103   - memcpy(&l, coding[i]+j*psize+x, sizeof(long));
104   - printf(" %08lx", l);
105   - }
106   - }
107   - printf("\n");
108   - }
109   - }
110   -
111   - printf("\n");
  90 + int i, j, x;
  91 + unsigned char *up;
  92 +
  93 + printf("<center><table border=3 cellpadding=3><tr><td></td>\n");
  94 +
  95 + for (i = 0; i < ndevices; i++) printf("<td align=center>%s%x</td>\n", label, i);
  96 + printf("</tr>\n");
  97 + printf("<td align=right><pre>");
  98 + for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
  99 + printf("</pre></td>\n");
  100 + for (i = 0; i < ndevices; i++) {
  101 + printf("<td><pre>");
  102 + up = (unsigned char *) ptrs[i];
  103 + for (j = 0; j < size/packetsize; j++) {
  104 + for (x = 0; x < packetsize; x++) {
  105 + if (x > 0 && x%4 == 0) printf(" ");
  106 + printf("%02x", up[j*packetsize+x]);
  107 + }
  108 + printf("\n");
  109 + }
  110 + printf("</td>\n");
  111 + }
  112 + printf("</tr></table></center>\n");
112 113 }
113 114  
114 115 int main(int argc, char **argv)
115 116 {
116   - long l;
117 117 int k, w, i, j, m;
118   - int *matrix, *bitmatrix, *m2, *x, *y;
119   - char **data, **coding, **ptrs;
120   - int **smart;
  118 + int *matrix, *bitmatrix, **schedule;
  119 + char **data, **coding, **ptrs, **dcopy, **ccopy;
121 120 int no;
122 121 int *erasures, *erased;
123   - double stats[3];
  122 + double mstats[3], sstats[3];
  123 + uint32_t seed;
  124 + int *X, *Y;
124 125  
125   - if (argc != 4) usage(NULL);
  126 + if (argc != 5) usage(NULL);
126 127 if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
127 128 if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
128 129 if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w");
  130 + if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed");
129 131 if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big");
130 132  
131   - matrix = cauchy_original_coding_matrix(k, m, w);
  133 + X = talloc(int, m);
  134 + Y = talloc(int, k);
  135 + for (i = 0; i < m; i++) X[i] = i;
  136 + for (i = 0; i < k; i++) Y[i] = m+i;
  137 +
  138 + matrix = cauchy_xy_coding_matrix(k, m, w, X, Y);
132 139 if (matrix == NULL) {
133 140 usage("couldn't make coding matrix");
134 141 }
135 142  
136   - no = 0;
137   - for (i = 0; i < k*m; i++) {
138   - no += cauchy_n_ones(matrix[i], w);
139   - }
140   - printf("The Original Matrix has %d ones\n", no);
  143 + /* Print out header information to the output file. */
  144 + printf("<HTML>\n");
  145 + printf("<TITLE>Jerasure Example Output: cauchy_03 %d %d %d %d</TITLE>\n", k, m, w, seed);
  146 + printf("<h2>Jerasure Example Output: cauchy_03 %d %d %d %d</h3>\n", k, m, w, seed);
  147 +
  148 + printf("<hr>\n");
  149 + printf("Parameters:\n");
  150 + printf("<UL><LI> Number of data disks <i>(k)</i>: %d\n", k);
  151 + printf("<LI> Number of coding disks <i>(m)</i>: %d\n", m);
  152 + printf("<LI> Word size of the Galois Field: <i>(w)</i>: %d\n", w);
  153 + printf("<LI> Seed for the random number generator: %d\n", seed);
  154 + printf("<LI> Number of bytes stored per disk: %ld\n", sizeof(long)*w);
  155 + printf("<LI> Number of packets stored per disk: %d\n", w);
  156 + printf("<LI> Number of bytes per packet: %ld\n", sizeof(long));
  157 + printf("</UL>\n");
  158 +
  159 + /* Print out the matrix and the bitmatrix */
  160 + printf("<hr>\n");
  161 + printf("Here is the matrix, which was created with <b>cauchy_xy_coding_matrix()</b>.\n");
  162 +
  163 + printf("<pre>\n");
  164 + jerasure_print_matrix(matrix, m, k, w);
  165 + printf("</pre>\n");
  166 +
141 167 cauchy_improve_coding_matrix(k, m, w, matrix);
  168 +
  169 + printf("<hr>\n");
  170 + printf("Here is the matrix improved with <b>cauchy_improve_coding_matrix()</b>.\n");
  171 +
  172 + printf("<pre>\n");
  173 + jerasure_print_matrix(matrix, m, k, w);
  174 + printf("</pre>\n");
  175 +
  176 + bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix);
  177 +
142 178 no = 0;
143 179 for (i = 0; i < k*m; i++) {
144 180 no += cauchy_n_ones(matrix[i], w);
145 181 }
146   - printf("The Improved Matrix has %d ones\n\n", no);
147   - jerasure_print_matrix(matrix, m, k, w);
148   - printf("\n", no);
149   - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix);
150 182  
151   - smart = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix);
  183 + printf("The bitmatrix, which has %d one%s:<p><pre>\n", no, (no == 1) ? "" : "s");
  184 + jerasure_print_bitmatrix(bitmatrix, m*w, k*w, w);
  185 + printf("</pre>\n");
  186 + printf("<hr>\n");
  187 +
  188 + MOA_Seed(seed);
152 189  
153   - srand48(0);
154 190 data = talloc(char *, k);
  191 + dcopy = talloc(char *, k);
155 192 for (i = 0; i < k; i++) {
156 193 data[i] = talloc(char, sizeof(long)*w);
157   - for (j = 0; j < w; j++) {
158   - l = lrand48();
159   - memcpy(data[i]+j*sizeof(long), &l, sizeof(long));
160   - }
  194 + dcopy[i] = talloc(char, sizeof(long)*w);
  195 + MOA_Fill_Random_Region(data[i], sizeof(long)*w);
  196 + memcpy(dcopy[i], data[i], sizeof(long)*w);
161 197 }
162 198  
  199 + printf("Here are the packets on the data disks:<p>\n");
  200 + print_array(data, k, sizeof(long)*w, sizeof(long), "D");
  201 +
163 202 coding = talloc(char *, m);
  203 + ccopy = talloc(char *, m);
164 204 for (i = 0; i < m; i++) {
165 205 coding[i] = talloc(char, sizeof(long)*w);
  206 + ccopy[i] = talloc(char, sizeof(long)*w);
  207 + }
  208 +
  209 + jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long));
  210 + jerasure_get_stats(mstats);
  211 +
  212 + schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix);
  213 + jerasure_schedule_encode(k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long));
  214 + jerasure_get_stats(sstats);
  215 +
  216 + printf("<p>Encoding with jerasure_bitmatrix_encode() - Bytes XOR'd: %.0lf.<br>\n", mstats[0]);
  217 + printf("Encoding with jerasure_schedule_encode() - Bytes XOR'd: %.0lf.<br>\n", sstats[0]);
  218 +
  219 + for (i = 0; i < m; i++) {
  220 + if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) {
  221 + printf("Problem: the two encodings don't match on disk C%x\n", i);
  222 + exit(0);
  223 + }
166 224 }
167 225  
168   - jerasure_schedule_encode(k, m, w, smart, data, coding, w*sizeof(long), sizeof(long));
169   - jerasure_get_stats(stats);
170   - printf("Smart Encoding Complete: - %.0lf XOR'd bytes\n\n", stats[0]);
171   - print_data_and_coding(k, m, w, sizeof(long), data, coding);
  226 + printf("Here are the packets on the coding disks.<br>\n");
  227 + print_array(coding, m, sizeof(long)*w, sizeof(long), "C");
  228 + printf("<hr>\n");
172 229  
173 230 erasures = talloc(int, (m+1));
174 231 erased = talloc(int, (k+m));
175 232 for (i = 0; i < m+k; i++) erased[i] = 0;
176 233 for (i = 0; i < m; ) {
177   - erasures[i] = lrand48()%(k+m);
  234 + erasures[i] = MOA_Random_W(31, 1)%(k+m);
178 235 if (erased[erasures[i]] == 0) {
179 236 erased[erasures[i]] = 1;
180 237 bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w);
... ... @@ -182,15 +239,47 @@ int main(int argc, char **argv)
182 239 }
183 240 }
184 241 erasures[i] = -1;
  242 + printf("Erasures on the following devices:");
  243 + for (i = 0; erasures[i] != -1; i++) {
  244 + printf(" %c%x", ((erasures[i] < k) ? 'D' : 'C'), (erasures[i] < k ? erasures[i] : erasures[i]-k));
  245 + }
  246 + printf("<br>\nHere is the state of the system:\n<p>\n");
  247 + print_array(data, k, sizeof(long)*w, sizeof(long), "D");
  248 + printf("<p>\n");
  249 + print_array(coding, m, sizeof(long)*w, sizeof(long), "C");
  250 + printf("<hr>\n");
  251 +
  252 + jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long));
  253 + jerasure_get_stats(mstats);
  254 +
  255 + printf("<p>Decoded with jerasure_bitmatrix_decode - Bytes XOR'd: %.0lf.<br>\n", mstats[0]);
  256 +
  257 + for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) {
  258 + printf("ERROR: D%x after decoding does not match its state before decoding!<br>\n", i);
  259 + }
  260 + for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) {
  261 + printf("ERROR: C%x after decoding does not match its state before decoding!<br>\n", i);
  262 + }
  263 +
  264 + for (i = 0; erasures[i] != -1; i++) {
  265 + bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w);
  266 + }
185 267  
186   - printf("Erased %d random devices:\n\n", m);
187   - print_data_and_coding(k, m, w, sizeof(long), data, coding);
188   -
189 268 jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1);
190   - jerasure_get_stats(stats);
  269 + jerasure_get_stats(sstats);
191 270  
192   - printf("State of the system after decoding: %.0lf XOR'd bytes\n\n", stats[0]);
193   - print_data_and_coding(k, m, w, sizeof(long), data, coding);
  271 + printf("jerasure_schedule_decode_lazy - Bytes XOR'd: %.0lf.<br>\n", sstats[0]);
  272 +
  273 + for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) {
  274 + printf("ERROR: D%x after decoding does not match its state before decoding!<br>\n", i);
  275 + }
  276 + for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) {
  277 + printf("ERROR: C%x after decoding does not match its state before decoding!<br>\n", i);
  278 + }
194 279  
195   - return 0;
  280 + printf("Here is the state of the system:\n<p>\n");
  281 + print_array(data, k, sizeof(long)*w, sizeof(long), "D");
  282 + printf("<p>\n");
  283 + print_array(coding, m, sizeof(long)*w, sizeof(long), "C");
  284 + printf("<hr>\n");
196 285 }
... ...
Examples/cauchy_04.c
... ... @@ -37,15 +37,15 @@
37 37 * POSSIBILITY OF SUCH DAMAGE.
38 38 */
39 39  
40   -
41   -
42 40 /*
43   - revised by S. Simmerman
44   - 2/25/08
  41 + revised by S. Simmerman 2/25/08
  42 + Re-revised by JSP to use GF-Complete - 1/2014
45 43 */
46 44 #include <stdio.h>
47 45 #include <stdlib.h>
  46 +#include <stdint.h>
48 47 #include <string.h>
  48 +#include <gf_rand.h>
49 49 #include "jerasure.h"
50 50 #include "cauchy.h"
51 51  
... ... @@ -53,78 +53,77 @@
53 53  
54 54 usage(char *s)
55 55 {
56   - fprintf(stderr, "usage: cauchy_04 k m w - Scheduled CRS coding example with a good matrix in GF(2^w).\n");
57   - fprintf(stderr, " \n");
58   - fprintf(stderr, " k+m must be <= 2^w. It sets up a Cauchy distribution matrix using \n");
59   - fprintf(stderr, " cauchy_good_coding_matrix(), then it encodes\n");
60   - fprintf(stderr, " k devices of w*%d bytes using smart bit-matrix scheduling.\n", sizeof(long));
61   - fprintf(stderr, " It decodes using bit-matrix scheduling as well.\n");
  56 + fprintf(stderr, "usage: cauchy_04 k m w seed - CRS coding example improving the matrix.\n");
62 57 fprintf(stderr, " \n");
63   - fprintf(stderr, "This demonstrates: cauchy_original_coding_matrix()\n");
  58 + fprintf(stderr, "k+m must be <= 2^w\n");
  59 + fprintf(stderr, "This sets up a generator matrix (G^T) in GF(2^w) whose last m rows are\n");
  60 + fprintf(stderr, "a 'good' matrix, created with cauchy_good_general_coding_matrix().\n");
  61 + fprintf(stderr, "It converts this matrix to a bitmatrix.\n");
  62 + fprintf(stderr, "\n");
  63 + fprintf(stderr, "Then, it encodes w packets from each of k disks (simulated) onto w packets on\n");
  64 + fprintf(stderr, "on each of m disks. Packets are longs. Then, it deletes m random disks, and decodes.\n");
  65 + fprintf(stderr, "\n");
  66 + fprintf(stderr, "The encoding and decoding are done twice, first, with jerasure_bitmatrix_encode()\n");
  67 + fprintf(stderr, "and jerasure_bitmatrix_decode(), and second using 'smart' scheduling with\n");
  68 + fprintf(stderr, "jerasure_schedule_encode() and jerasure_schedule_decode_lazy().\n");
  69 +
  70 + fprintf(stderr, "\n");
  71 + fprintf(stderr, "This demonstrates: cauchy_good_general_coding_matrix()\n");
  72 + fprintf(stderr, " jerasure_bitmatrix_encode()\n");
  73 + fprintf(stderr, " jerasure_bitmatrix_decode()\n");
64 74 fprintf(stderr, " cauchy_n_ones()\n");
65 75 fprintf(stderr, " jerasure_smart_bitmatrix_to_schedule()\n");
66 76 fprintf(stderr, " jerasure_schedule_encode()\n");
67 77 fprintf(stderr, " jerasure_schedule_decode_lazy()\n");
68 78 fprintf(stderr, " jerasure_print_matrix()\n");
  79 + fprintf(stderr, " jerasure_print_bitmatrix()\n");
69 80 fprintf(stderr, " jerasure_get_stats()\n");
70 81 if (s != NULL) fprintf(stderr, "%s\n", s);
71 82 exit(1);
72 83 }
73 84  
74   -static void print_data_and_coding(int k, int m, int w, int psize,
75   - char **data, char **coding)
  85 +static print_array(char **ptrs, int ndevices, int size, int packetsize, char *label)
76 86 {
77   - int i, j, x, n, sp;
78   - long l;
79   -
80   - if(k > m) n = k;
81   - else n = m;
82   - sp = psize * 2 + (psize/4) + 12;
83   -
84   - printf("%-*sCoding\n", sp, "Data");
85   - for(i = 0; i < n; i++) {
86   - for (j = 0; j < w; j++) {
87   - if(i < k) {
88   -
89   - if(j==0) printf("D%-2d p%-2d:", i,j);
90   - else printf(" p%-2d:", j);
91   - for(x = 0; x < psize; x +=4) {
92   - memcpy(&l, data[i]+j*psize+x, sizeof(long));
93   - printf(" %08lx", l);
94   - }
95   - printf(" ");
96   - }
97   - else printf("%*s", sp, "");
98   - if(i < m) {
99   - if(j==0) printf("C%-2d p%-2d:", i,j);
100   - else printf(" p%-2d:", j);
101   - for(x = 0; x < psize; x +=4) {
102   - memcpy(&l, coding[i]+j*psize+x, sizeof(long));
103   - printf(" %08lx", l);
104   - }
105   - }
106   - printf("\n");
107   - }
108   - }
109   -
110   - printf("\n");
  87 + int i, j, x;
  88 + unsigned char *up;
  89 +
  90 + printf("<center><table border=3 cellpadding=3><tr><td></td>\n");
  91 +
  92 + for (i = 0; i < ndevices; i++) printf("<td align=center>%s%x</td>\n", label, i);
  93 + printf("</tr>\n");
  94 + printf("<td align=right><pre>");
  95 + for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
  96 + printf("</pre></td>\n");
  97 + for (i = 0; i < ndevices; i++) {
  98 + printf("<td><pre>");
  99 + up = (unsigned char *) ptrs[i];
  100 + for (j = 0; j < size/packetsize; j++) {
  101 + for (x = 0; x < packetsize; x++) {
  102 + if (x > 0 && x%4 == 0) printf(" ");
  103 + printf("%02x", up[j*packetsize+x]);
  104 + }
  105 + printf("\n");
  106 + }
  107 + printf("</td>\n");
  108 + }
  109 + printf("</tr></table></center>\n");
111 110 }
112 111  
113 112 int main(int argc, char **argv)
114 113 {
115   - long l;
116 114 int k, w, i, j, m;
117   - int *matrix, *bitmatrix;
118   - char **data, **coding, **ptrs;
119   - int **smart;
  115 + int *matrix, *bitmatrix, **schedule;
  116 + char **data, **coding, **ptrs, **dcopy, **ccopy;
120 117 int no;
121 118 int *erasures, *erased;
122   - double stats[3];
  119 + double mstats[3], sstats[3];
  120 + uint32_t seed;
123 121  
124   - if (argc != 4) usage(NULL);
  122 + if (argc != 5) usage(NULL);
125 123 if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
126 124 if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
127 125 if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w");
  126 + if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed");
128 127 if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big");
129 128  
130 129 matrix = cauchy_good_general_coding_matrix(k, m, w);
... ... @@ -132,42 +131,89 @@ int main(int argc, char **argv)
132 131 usage("couldn't make coding matrix");
133 132 }
134 133  
  134 + /* Print out header information to the output file. */
  135 + printf("<HTML>\n");
  136 + printf("<TITLE>Jerasure Example Output: cauchy_04 %d %d %d %d</TITLE>\n", k, m, w, seed);
  137 + printf("<h2>Jerasure Example Output: cauchy_04 %d %d %d %d</h3>\n", k, m, w, seed);
  138 +
  139 + printf("<hr>\n");
  140 + printf("Parameters:\n");
  141 + printf("<UL><LI> Number of data disks <i>(k)</i>: %d\n", k);
  142 + printf("<LI> Number of coding disks <i>(m)</i>: %d\n", m);
  143 + printf("<LI> Word size of the Galois Field: <i>(w)</i>: %d\n", w);
  144 + printf("<LI> Seed for the random number generator: %d\n", seed);
  145 + printf("<LI> Number of bytes stored per disk: %ld\n", sizeof(long)*w);
  146 + printf("<LI> Number of packets stored per disk: %d\n", w);
  147 + printf("<LI> Number of bytes per packet: %ld\n", sizeof(long));
  148 + printf("</UL>\n");
  149 +
  150 + /* Print out the matrix and the bitmatrix */
  151 + printf("<hr>\n");
  152 + printf("Here is the matrix, which was created with <b>cauchy_xy_coding_matrix()</b>.\n");
  153 +
  154 + printf("<pre>\n");
  155 + jerasure_print_matrix(matrix, m, k, w);
  156 + printf("</pre>\n");
  157 +
  158 + bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix);
  159 +
135 160 no = 0;
136 161 for (i = 0; i < k*m; i++) {
137 162 no += cauchy_n_ones(matrix[i], w);
138 163 }
139   - printf("Matrix has %d ones\n\n", no);
140   - jerasure_print_matrix(matrix, m, k, w);
141   - printf("\n");
142   - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix);
143 164  
144   - smart = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix);
  165 + printf("The bitmatrix, which has %d one%s:<p><pre>\n", no, (no == 1) ? "" : "s");
  166 + jerasure_print_bitmatrix(bitmatrix, m*w, k*w, w);
  167 + printf("</pre>\n");
  168 + printf("<hr>\n");
  169 +
  170 + MOA_Seed(seed);
145 171  
146   - srand48(0);
147 172 data = talloc(char *, k);
  173 + dcopy = talloc(char *, k);
148 174 for (i = 0; i