├── .gitattributes ├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── Examples ├── .gitignore ├── Makefile.am ├── cauchy_01.c ├── cauchy_02.c ├── cauchy_03.c ├── cauchy_04.c ├── decoder.c ├── encode_decode.sh ├── encoder.c ├── jerasure_01.c ├── jerasure_02.c ├── jerasure_03.c ├── jerasure_04.c ├── jerasure_05.c ├── jerasure_06.c ├── jerasure_07.c ├── jerasure_08.c ├── liberation_01.c ├── reed_sol_01.c ├── reed_sol_02.c ├── reed_sol_03.c ├── reed_sol_04.c ├── reed_sol_test_gf.c ├── reed_sol_time_gf.c ├── test_all_gfs.sh ├── test_galois.c └── time_all_gfs_argv_init.sh ├── License.txt ├── Makefile.am ├── Manual.pdf ├── NEWS ├── PERF.txt ├── README ├── configure.ac ├── include ├── cauchy.h ├── galois.h ├── jerasure.h ├── liberation.h ├── reed_sol.h └── timing.h ├── m4 ├── ax_check_compile_flag.m4 ├── ax_ext.m4 ├── ax_gcc_x86_avx_xgetbv.m4 ├── ax_gcc_x86_cpuid.m4 └── ax_require_defined.m4 └── src ├── Makefile.am ├── cauchy.c ├── cauchy_best_r6.c ├── galois.c ├── jerasure.c ├── liberation.c ├── reed_sol.c └── timing.c /.gitattributes: -------------------------------------------------------------------------------- 1 | *.ac eol=lf 2 | *.am eol=lf 3 | *.sh eol=lf 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /INSTALL 2 | Makefile 3 | Makefile.in 4 | /aclocal.m4 5 | /autom4te.cache/ 6 | /autoscan.log 7 | /build-aux/ 8 | /config.log 9 | /config.status 10 | /configure 11 | /configure.scan 12 | .deps/ 13 | /include/config.h 14 | /include/config.h.in 15 | /include/stamp-h1 16 | .libs/ 17 | /libtool 18 | /m4/libtool.m4 19 | /m4/ltoptions.m4 20 | /m4/ltsugar.m4 21 | /m4/ltversion.m4 22 | /m4/lt~obsolete.m4 23 | *.l[ao] 24 | *.[ao] 25 | *~ 26 | .dirstamp 27 | *.log 28 | *.trs 29 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceph/jerasure/de1739cc8483696506829b52e7fda4f6bb195e6a/AUTHORS -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2013, James S. Plank and Kevin Greenan 3 | All rights reserved. 4 | 5 | Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques 6 | 7 | Revision 2.0: Galois Field backend now links to GF-Complete 8 | 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | - Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | - Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in 18 | the documentation and/or other materials provided with the 19 | distribution. 20 | 21 | - Neither the name of the University of Tennessee nor the names of its 22 | contributors may be used to endorse or promote products derived 23 | from this software without specific prior written permission. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 30 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 31 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 32 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 33 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 35 | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 | POSSIBILITY OF SUCH DAMAGE. 37 | 38 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ceph/jerasure/de1739cc8483696506829b52e7fda4f6bb195e6a/ChangeLog -------------------------------------------------------------------------------- /Examples/.gitignore: -------------------------------------------------------------------------------- 1 | /cauchy_[0-9][0-9] 2 | /decoder 3 | /encoder 4 | /jerasure_[0-9][0-9] 5 | /liberation_[0-9][0-9] 6 | /reed_sol_[0-9][0-9] 7 | /reed_sol_test_gf 8 | /reed_sol_time_gf 9 | /test_galois 10 | -------------------------------------------------------------------------------- /Examples/Makefile.am: -------------------------------------------------------------------------------- 1 | # Jerasure AM file 2 | 3 | AM_CPPFLAGS = -I$(top_srcdir)/include 4 | AM_CFLAGS = $(SIMD_FLAGS) 5 | 6 | bin_PROGRAMS = jerasure_01 \ 7 | jerasure_02 \ 8 | jerasure_03 \ 9 | jerasure_04 \ 10 | jerasure_05 \ 11 | jerasure_06 \ 12 | jerasure_07 \ 13 | jerasure_08 \ 14 | reed_sol_01 \ 15 | reed_sol_02 \ 16 | reed_sol_03 \ 17 | reed_sol_04 \ 18 | reed_sol_test_gf \ 19 | reed_sol_time_gf \ 20 | cauchy_01 \ 21 | cauchy_02 \ 22 | cauchy_03 \ 23 | cauchy_04 \ 24 | liberation_01 \ 25 | encoder \ 26 | decoder 27 | 28 | check_PROGRAMS = 29 | 30 | TESTS=test_all_gfs.sh encode_decode.sh $(check_PROGRAMS) 31 | 32 | dist_noinst_SCRIPTS = test_all_gfs.sh time_all_gfs_argv_init.sh 33 | 34 | test_galois_SOURCES = test_galois.c 35 | check_PROGRAMS += test_galois 36 | 37 | jerasure_01_SOURCES = jerasure_01.c 38 | jerasure_02_SOURCES = jerasure_02.c 39 | jerasure_03_SOURCES = jerasure_03.c 40 | jerasure_04_SOURCES = jerasure_04.c 41 | jerasure_05_SOURCES = jerasure_05.c 42 | jerasure_06_SOURCES = jerasure_06.c 43 | jerasure_07_SOURCES = jerasure_07.c 44 | jerasure_08_SOURCES = jerasure_08.c 45 | 46 | reed_sol_01_SOURCES = reed_sol_01.c 47 | reed_sol_02_SOURCES = reed_sol_02.c 48 | reed_sol_03_SOURCES = reed_sol_03.c 49 | reed_sol_04_SOURCES = reed_sol_04.c 50 | 51 | reed_sol_test_gf_SOURCES = reed_sol_test_gf.c 52 | reed_sol_time_gf_SOURCES = reed_sol_time_gf.c 53 | 54 | cauchy_01_SOURCES = cauchy_01.c 55 | cauchy_02_SOURCES = cauchy_02.c 56 | cauchy_03_SOURCES = cauchy_03.c 57 | cauchy_04_SOURCES = cauchy_04.c 58 | 59 | liberation_01_SOURCES = liberation_01.c 60 | 61 | decoder_SOURCES = decoder.c 62 | encoder_SOURCES = encoder.c 63 | 64 | LDADD = ../src/libJerasure.la 65 | decoder_LDADD = $(LDADD) ../src/libtiming.a 66 | encoder_LDADD = $(LDADD) ../src/libtiming.a 67 | reed_sol_time_gf_LDADD = $(LDADD) ../src/libtiming.a 68 | -------------------------------------------------------------------------------- /Examples/cauchy_01.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include "cauchy.h" 52 | #include "jerasure.h" 53 | #include "reed_sol.h" 54 | 55 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 56 | 57 | static void usage(char *s) 58 | { 59 | fprintf(stderr, "usage: cauchy_01 n w - Converts the value n to a bitmatrix using GF(2^w).\n"); 60 | fprintf(stderr, " \n"); 61 | fprintf(stderr, " It prints the bitmatrix, and reports on the numberof ones.\n"); 62 | fprintf(stderr, " Use 0x to input n in hexadecimal.\n"); 63 | fprintf(stderr, " W must be <= 32.\n"); 64 | fprintf(stderr, " \n"); 65 | fprintf(stderr, "This demonstrates: cauchy_n_ones()\n"); 66 | fprintf(stderr, " jerasure_matrix_to_bitmatrix()\n"); 67 | fprintf(stderr, " jerasure_print_bitmatrix()\n"); 68 | if (s != NULL) fprintf(stderr, "\n%s\n", s); 69 | exit(1); 70 | } 71 | 72 | int main(int argc, char **argv) 73 | { 74 | int n; 75 | int i, no, w; 76 | int *bitmatrix; 77 | 78 | if (argc != 3) usage(NULL); 79 | if (sscanf(argv[1], "0x%x", &n) == 0) { 80 | if (sscanf(argv[1], "%d", &n) == 0) usage("Bad n"); 81 | } 82 | if (sscanf(argv[2], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w"); 83 | if (w == 31) { 84 | if (n & 0x80000000L) usage("Bad n/w combination (n not between 0 and 2^w-1)\n"); 85 | } else if (w < 31) { 86 | if (n >= (1 << w)) usage("Bad n/w combination (n not between 0 and 2^w-1)\n"); 87 | } 88 | 89 | bitmatrix = jerasure_matrix_to_bitmatrix(1, 1, w, &n); 90 | printf("cauchy_01 %u %d\n", w, n); 91 | printf("

cauchy_01 %u %d

\n", w, n); 92 | printf("
\n");
 93 |   if (w == 32) {
 94 |     printf("Converted the value 0x%x to the following bitmatrix:\n\n", n);
 95 |   } else {
 96 |     printf("Converted the value %d (0x%x) to the following bitmatrix:\n\n", n, n);
 97 |   }
 98 |   jerasure_print_bitmatrix(bitmatrix, w, w, w);
 99 |   printf("\n");
100 | 
101 |   no = 0;
102 |   for (i = 0; i < w*w; i++) no += bitmatrix[i];
103 |   if (no != cauchy_n_ones(n, w)) { 
104 |     fprintf(stderr, "Jerasure error: # ones in the bitmatrix (%d) doesn't match cauchy_n_ones() (%d).\n",
105 |        no, cauchy_n_ones(n, w));
106 |     exit(1);
107 |   }
108 | 
109 |   printf("# Ones: %d\n", cauchy_n_ones(n, w));
110 | 
111 |   return 0;
112 | }
113 | 


--------------------------------------------------------------------------------
/Examples/cauchy_02.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 |  
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include 
 51 | #include 
 52 | #include "jerasure.h"
 53 | #include "cauchy.h"
 54 | 
 55 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
 56 | 
 57 | static void usage(char *s)
 58 | {
 59 |   fprintf(stderr, "usage: cauchy_02 k m w seed - CRS coding example using Bloemer's original matrix.\n");
 60 |   fprintf(stderr, "       \n");
 61 |   fprintf(stderr, "k+m must be <= 2^w\n");
 62 |   fprintf(stderr, "This sets up a generator matrix (G^T) in GF(2^w) whose last m rows are\n");
 63 |   fprintf(stderr, "created from a Cauchy matrix, using the original definition from [Bloemer95].\n");
 64 |   fprintf(stderr, "It converts this matrix to a bitmatrix, and then it encodes w packets from\n");
 65 |   fprintf(stderr, "each of k disks (simulated) onto w packets on each of m disks.  Packets are \n");
 66 |   fprintf(stderr, "simply 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_original_coding_matrix()\n");
 74 |   fprintf(stderr, "                   jerasure_bitmatrix_encode()\n");
 75 |   fprintf(stderr, "                   jerasure_bitmatrix_decode()\n");
 76 |   fprintf(stderr, "                   cauchy_n_ones()\n");
 77 |   fprintf(stderr, "                   jerasure_smart_bitmatrix_to_schedule()\n");
 78 |   fprintf(stderr, "                   jerasure_schedule_encode()\n");
 79 |   fprintf(stderr, "                   jerasure_schedule_decode_lazy()\n");
 80 |   fprintf(stderr, "                   jerasure_print_matrix()\n");
 81 |   fprintf(stderr, "                   jerasure_print_bitmatrix()\n");
 82 |   fprintf(stderr, "                   jerasure_get_stats()\n");
 83 |   if (s != NULL) fprintf(stderr, "%s\n", s);
 84 |   exit(1);
 85 | }
 86 | 
 87 | static void print_array(char **ptrs, int ndevices, int size, int packetsize, char *label)
 88 | {
 89 |   int i, j, x;
 90 |   unsigned char *up;
 91 | 
 92 |   printf("
\n"); 93 | 94 | for (i = 0; i < ndevices; i++) printf("\n", label, i); 95 | printf("\n"); 96 | printf("\n"); 99 | for (i = 0; i < ndevices; i++) { 100 | printf("\n"); 110 | } 111 | printf("
%s%x
");
 97 |   for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
 98 |   printf("
");
101 |     up = (unsigned char *) ptrs[i];
102 |     for (j = 0; j < size/packetsize; j++) {
103 |       for (x = 0; x < packetsize; x++) {
104 |         if (x > 0 && x%4 == 0) printf(" ");
105 |         printf("%02x", up[j*packetsize+x]);
106 |       }
107 |       printf("\n");
108 |     }
109 |     printf("
\n"); 112 | } 113 | 114 | int main(int argc, char **argv) 115 | { 116 | int k, w, i, m; 117 | int *matrix, *bitmatrix, **schedule; 118 | char **data, **coding, **dcopy, **ccopy; 119 | int no; 120 | int *erasures, *erased; 121 | double mstats[3], sstats[3]; 122 | uint32_t seed; 123 | 124 | if (argc != 5) usage(NULL); 125 | if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); 126 | if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m"); 127 | if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w"); 128 | if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed"); 129 | if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big"); 130 | 131 | matrix = cauchy_original_coding_matrix(k, m, w); 132 | if (matrix == NULL) { 133 | usage("couldn't make coding matrix"); 134 | } 135 | 136 | /* Print out header information to the output file. */ 137 | printf("\n"); 138 | printf("Jerasure Example Output: cauchy_02 %d %d %d %d\n", k, m, w, seed); 139 | printf("

Jerasure Example Output: cauchy_02 %d %d %d %d

\n", k, m, w, seed); 140 | 141 | printf("
\n"); 142 | printf("Parameters:\n"); 143 | printf("
  • Number of data disks (k): %d\n", k); 144 | printf("
  • Number of coding disks (m): %d\n", m); 145 | printf("
  • Word size of the Galois Field: (w): %d\n", w); 146 | printf("
  • Seed for the random number generator: %d\n", seed); 147 | printf("
  • Number of bytes stored per disk: %ld\n", sizeof(long)*w); 148 | printf("
  • Number of packets stored per disk: %d\n", w); 149 | printf("
  • Number of bytes per packet: %ld\n", sizeof(long)); 150 | printf("
\n"); 151 | 152 | /* Print out the matrix and the bitmatrix */ 153 | printf("
\n"); 154 | printf("Here is the matrix, which was created with cauchy_original_coding_matrix().\n"); 155 | printf("This is not the best matrix to use, but we include it to show an example\n"); 156 | printf("of cauchy_original_coding_matrix(). For the best matrix and encoding/decoding\n"); 157 | printf("methodology, see cauchy_04.

\n");
158 | 
159 |   jerasure_print_matrix(matrix, m, k, w);
160 |   printf("
\n"); 161 | 162 | bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); 163 | 164 | no = 0; 165 | for (i = 0; i < k*m; i++) { 166 | no += cauchy_n_ones(matrix[i], w); 167 | } 168 | 169 | printf("The bitmatrix, which has %d one%s:

\n", no, (no == 1) ? "" : "s");
170 |   jerasure_print_bitmatrix(bitmatrix, m*w, k*w, w);
171 |   printf("
\n"); 172 | printf("
\n"); 173 | MOA_Seed(seed); 174 | 175 | data = talloc(char *, k); 176 | dcopy = talloc(char *, k); 177 | for (i = 0; i < k; i++) { 178 | data[i] = talloc(char, sizeof(long)*w); 179 | dcopy[i] = talloc(char, sizeof(long)*w); 180 | MOA_Fill_Random_Region(data[i], sizeof(long)*w); 181 | memcpy(dcopy[i], data[i], sizeof(long)*w); 182 | } 183 | 184 | printf("Here are the packets on the data disks:

\n"); 185 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 186 | 187 | coding = talloc(char *, m); 188 | ccopy = talloc(char *, m); 189 | for (i = 0; i < m; i++) { 190 | coding[i] = talloc(char, sizeof(long)*w); 191 | ccopy[i] = talloc(char, sizeof(long)*w); 192 | } 193 | 194 | jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long)); 195 | jerasure_get_stats(mstats); 196 | 197 | schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix); 198 | jerasure_schedule_encode(k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long)); 199 | jerasure_get_stats(sstats); 200 | 201 | printf("

Encoding with jerasure_bitmatrix_encode() - Bytes XOR'd: %.0lf.
\n", mstats[0]); 202 | printf("Encoding with jerasure_schedule_encode() - Bytes XOR'd: %.0lf.
\n", sstats[0]); 203 | 204 | for (i = 0; i < m; i++) { 205 | if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) { 206 | printf("Problem: the two encodings don't match on disk C%x\n", i); 207 | exit(0); 208 | } 209 | } 210 | 211 | printf("Here are the packets on the coding disks.
\n"); 212 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 213 | printf("


\n"); 214 | 215 | erasures = talloc(int, (m+1)); 216 | erased = talloc(int, (k+m)); 217 | for (i = 0; i < m+k; i++) erased[i] = 0; 218 | for (i = 0; i < m; ) { 219 | erasures[i] = MOA_Random_W(31, 1)%(k+m); 220 | if (erased[erasures[i]] == 0) { 221 | erased[erasures[i]] = 1; 222 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); 223 | i++; 224 | } 225 | } 226 | erasures[i] = -1; 227 | printf("Erasures on the following devices:"); 228 | for (i = 0; erasures[i] != -1; i++) { 229 | printf(" %c%x", ((erasures[i] < k) ? 'D' : 'C'), (erasures[i] < k ? erasures[i] : erasures[i]-k)); 230 | } 231 | printf("
\nHere is the state of the system:\n

\n"); 232 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 233 | printf("

\n"); 234 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 235 | printf("


\n"); 236 | 237 | jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long)); 238 | jerasure_get_stats(mstats); 239 | 240 | printf("

Decoded with jerasure_bitmatrix_decode - Bytes XOR'd: %.0lf.
\n", mstats[0]); 241 | 242 | for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) { 243 | printf("ERROR: D%x after decoding does not match its state before decoding!
\n", i); 244 | } 245 | for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) { 246 | printf("ERROR: C%x after decoding does not match its state before decoding!
\n", i); 247 | } 248 | 249 | for (i = 0; erasures[i] != -1; i++) { 250 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); 251 | } 252 | 253 | jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); 254 | jerasure_get_stats(sstats); 255 | 256 | printf("jerasure_schedule_decode_lazy - Bytes XOR'd: %.0lf.
\n", sstats[0]); 257 | 258 | for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) { 259 | printf("ERROR: D%x after decoding does not match its state before decoding!
\n", i); 260 | } 261 | for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) { 262 | printf("ERROR: C%x after decoding does not match its state before decoding!
\n", i); 263 | } 264 | 265 | printf("Here is the state of the system:\n

\n"); 266 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 267 | printf("

\n"); 268 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 269 | printf("


\n"); 270 | 271 | return 0; 272 | } 273 | -------------------------------------------------------------------------------- /Examples/cauchy_03.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "jerasure.h" 53 | #include "cauchy.h" 54 | 55 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 56 | 57 | static void usage(char *s) 58 | { 59 | fprintf(stderr, "usage: cauchy_03 k m w seed - CRS coding example improving the matrix.\n"); 60 | fprintf(stderr, " \n"); 61 | fprintf(stderr, "k+m must be <= 2^w\n"); 62 | fprintf(stderr, "This sets up a generator matrix (G^T) in GF(2^w) whose last m rows are\n"); 63 | fprintf(stderr, "created from a Cauchy matrix, using the original definition from [Bloemer95].\n"); 64 | fprintf(stderr, "This is done with cauchy_xy_coding_matrix().\n"); 65 | fprintf(stderr, "\n"); 66 | fprintf(stderr, "It then it improves the matrix, which yields a different bitmatrix that is\n"); 67 | fprintf(stderr, "MDS like the original bitmatrix, but it will yield a bitmatrix with fewer ones.\n"); 68 | fprintf(stderr, "Then, it encodes w packets from each of k disks (simulated) onto w packets on\n"); 69 | fprintf(stderr, "on each of m disks. Packets are longs. Then, it deletes m random disks, and decodes.\n"); 70 | fprintf(stderr, "\n"); 71 | fprintf(stderr, "The encoding and decoding are done twice, first, with jerasure_bitmatrix_encode()\n"); 72 | fprintf(stderr, "and jerasure_bitmatrix_decode(), and second using 'smart' scheduling with\n"); 73 | fprintf(stderr, "jerasure_schedule_encode() and jerasure_schedule_decode_lazy().\n"); 74 | 75 | fprintf(stderr, "\n"); 76 | fprintf(stderr, "This demonstrates: cauchy_xy_coding_matrix()\n"); 77 | fprintf(stderr, " cauchy_improve_coding_matrix()\n"); 78 | fprintf(stderr, " jerasure_bitmatrix_encode()\n"); 79 | fprintf(stderr, " jerasure_bitmatrix_decode()\n"); 80 | fprintf(stderr, " cauchy_n_ones()\n"); 81 | fprintf(stderr, " jerasure_smart_bitmatrix_to_schedule()\n"); 82 | fprintf(stderr, " jerasure_schedule_encode()\n"); 83 | fprintf(stderr, " jerasure_schedule_decode_lazy()\n"); 84 | fprintf(stderr, " jerasure_print_matrix()\n"); 85 | fprintf(stderr, " jerasure_print_bitmatrix()\n"); 86 | fprintf(stderr, " jerasure_get_stats()\n"); 87 | if (s != NULL) fprintf(stderr, "%s\n", s); 88 | exit(1); 89 | } 90 | 91 | static void print_array(char **ptrs, int ndevices, int size, int packetsize, char *label) 92 | { 93 | int i, j, x; 94 | unsigned char *up; 95 | 96 | printf("
\n"); 97 | 98 | for (i = 0; i < ndevices; i++) printf("\n", label, i); 99 | printf("\n"); 100 | printf("\n"); 103 | for (i = 0; i < ndevices; i++) { 104 | printf("\n"); 114 | } 115 | printf("
%s%x
");
101 |   for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
102 |   printf("
");
105 |     up = (unsigned char *) ptrs[i];
106 |     for (j = 0; j < size/packetsize; j++) {
107 |       for (x = 0; x < packetsize; x++) {
108 |         if (x > 0 && x%4 == 0) printf(" ");
109 |         printf("%02x", up[j*packetsize+x]);
110 |       }
111 |       printf("\n");
112 |     }
113 |     printf("
\n"); 116 | } 117 | 118 | int main(int argc, char **argv) 119 | { 120 | int k, w, i, m; 121 | int *matrix, *bitmatrix, **schedule; 122 | char **data, **coding, **dcopy, **ccopy; 123 | int no; 124 | int *erasures, *erased; 125 | double mstats[3], sstats[3]; 126 | uint32_t seed; 127 | int *X, *Y; 128 | 129 | if (argc != 5) usage(NULL); 130 | if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); 131 | if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m"); 132 | if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w"); 133 | if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed"); 134 | if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big"); 135 | 136 | X = talloc(int, m); 137 | Y = talloc(int, k); 138 | for (i = 0; i < m; i++) X[i] = i; 139 | for (i = 0; i < k; i++) Y[i] = m+i; 140 | 141 | matrix = cauchy_xy_coding_matrix(k, m, w, X, Y); 142 | if (matrix == NULL) { 143 | usage("couldn't make coding matrix"); 144 | } 145 | 146 | /* Print out header information to the output file. */ 147 | printf("\n"); 148 | printf("Jerasure Example Output: cauchy_03 %d %d %d %d\n", k, m, w, seed); 149 | printf("

Jerasure Example Output: cauchy_03 %d %d %d %d

\n", k, m, w, seed); 150 | 151 | printf("
\n"); 152 | printf("Parameters:\n"); 153 | printf("
  • Number of data disks (k): %d\n", k); 154 | printf("
  • Number of coding disks (m): %d\n", m); 155 | printf("
  • Word size of the Galois Field: (w): %d\n", w); 156 | printf("
  • Seed for the random number generator: %d\n", seed); 157 | printf("
  • Number of bytes stored per disk: %ld\n", sizeof(long)*w); 158 | printf("
  • Number of packets stored per disk: %d\n", w); 159 | printf("
  • Number of bytes per packet: %ld\n", sizeof(long)); 160 | printf("
\n"); 161 | 162 | /* Print out the matrix and the bitmatrix */ 163 | printf("
\n"); 164 | printf("Here is the matrix, which was created with cauchy_xy_coding_matrix().\n"); 165 | 166 | printf("
\n");
167 |   jerasure_print_matrix(matrix, m, k, w);
168 |   printf("
\n"); 169 | 170 | cauchy_improve_coding_matrix(k, m, w, matrix); 171 | 172 | printf("
\n"); 173 | printf("Here is the matrix improved with cauchy_improve_coding_matrix().\n"); 174 | 175 | printf("
\n");
176 |   jerasure_print_matrix(matrix, m, k, w);
177 |   printf("
\n"); 178 | 179 | bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); 180 | 181 | no = 0; 182 | for (i = 0; i < k*m; i++) { 183 | no += cauchy_n_ones(matrix[i], w); 184 | } 185 | 186 | printf("The bitmatrix, which has %d one%s:

\n", no, (no == 1) ? "" : "s");
187 |   jerasure_print_bitmatrix(bitmatrix, m*w, k*w, w);
188 |   printf("
\n"); 189 | printf("
\n"); 190 | 191 | MOA_Seed(seed); 192 | 193 | data = talloc(char *, k); 194 | dcopy = talloc(char *, k); 195 | for (i = 0; i < k; i++) { 196 | data[i] = talloc(char, sizeof(long)*w); 197 | dcopy[i] = talloc(char, sizeof(long)*w); 198 | MOA_Fill_Random_Region(data[i], sizeof(long)*w); 199 | memcpy(dcopy[i], data[i], sizeof(long)*w); 200 | } 201 | 202 | printf("Here are the packets on the data disks:

\n"); 203 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 204 | 205 | coding = talloc(char *, m); 206 | ccopy = talloc(char *, m); 207 | for (i = 0; i < m; i++) { 208 | coding[i] = talloc(char, sizeof(long)*w); 209 | ccopy[i] = talloc(char, sizeof(long)*w); 210 | } 211 | 212 | jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long)); 213 | jerasure_get_stats(mstats); 214 | 215 | schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix); 216 | jerasure_schedule_encode(k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long)); 217 | jerasure_get_stats(sstats); 218 | 219 | printf("

Encoding with jerasure_bitmatrix_encode() - Bytes XOR'd: %.0lf.
\n", mstats[0]); 220 | printf("Encoding with jerasure_schedule_encode() - Bytes XOR'd: %.0lf.
\n", sstats[0]); 221 | 222 | for (i = 0; i < m; i++) { 223 | if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) { 224 | printf("Problem: the two encodings don't match on disk C%x\n", i); 225 | exit(0); 226 | } 227 | } 228 | 229 | printf("Here are the packets on the coding disks.
\n"); 230 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 231 | printf("


\n"); 232 | 233 | erasures = talloc(int, (m+1)); 234 | erased = talloc(int, (k+m)); 235 | for (i = 0; i < m+k; i++) erased[i] = 0; 236 | for (i = 0; i < m; ) { 237 | erasures[i] = MOA_Random_W(31, 1)%(k+m); 238 | if (erased[erasures[i]] == 0) { 239 | erased[erasures[i]] = 1; 240 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); 241 | i++; 242 | } 243 | } 244 | erasures[i] = -1; 245 | printf("Erasures on the following devices:"); 246 | for (i = 0; erasures[i] != -1; i++) { 247 | printf(" %c%x", ((erasures[i] < k) ? 'D' : 'C'), (erasures[i] < k ? erasures[i] : erasures[i]-k)); 248 | } 249 | printf("
\nHere is the state of the system:\n

\n"); 250 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 251 | printf("

\n"); 252 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 253 | printf("


\n"); 254 | 255 | jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long)); 256 | jerasure_get_stats(mstats); 257 | 258 | printf("

Decoded with jerasure_bitmatrix_decode - Bytes XOR'd: %.0lf.
\n", mstats[0]); 259 | 260 | for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) { 261 | printf("ERROR: D%x after decoding does not match its state before decoding!
\n", i); 262 | } 263 | for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) { 264 | printf("ERROR: C%x after decoding does not match its state before decoding!
\n", i); 265 | } 266 | 267 | for (i = 0; erasures[i] != -1; i++) { 268 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); 269 | } 270 | 271 | jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); 272 | jerasure_get_stats(sstats); 273 | 274 | printf("jerasure_schedule_decode_lazy - Bytes XOR'd: %.0lf.
\n", sstats[0]); 275 | 276 | for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) { 277 | printf("ERROR: D%x after decoding does not match its state before decoding!
\n", i); 278 | } 279 | for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) { 280 | printf("ERROR: C%x after decoding does not match its state before decoding!
\n", i); 281 | } 282 | 283 | printf("Here is the state of the system:\n

\n"); 284 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 285 | printf("

\n"); 286 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 287 | printf("


\n"); 288 | 289 | return 0; 290 | } 291 | -------------------------------------------------------------------------------- /Examples/cauchy_04.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan. 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank. 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "jerasure.h" 53 | #include "cauchy.h" 54 | 55 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 56 | 57 | static void usage(char *s) 58 | { 59 | fprintf(stderr, "usage: cauchy_04 k m w seed - CRS coding example improving the matrix.\n"); 60 | fprintf(stderr, " \n"); 61 | fprintf(stderr, "k+m must be <= 2^w\n"); 62 | fprintf(stderr, "This sets up a generator matrix (G^T) in GF(2^w) whose last m rows are\n"); 63 | fprintf(stderr, "a 'good' matrix, created with cauchy_good_general_coding_matrix().\n"); 64 | fprintf(stderr, "It converts this matrix to a bitmatrix.\n"); 65 | fprintf(stderr, "\n"); 66 | fprintf(stderr, "Then, it encodes w packets from each of k disks (simulated) onto w packets on\n"); 67 | fprintf(stderr, "on each of m disks. Packets are longs. Then, it deletes m random disks, and decodes.\n"); 68 | fprintf(stderr, "\n"); 69 | fprintf(stderr, "The encoding and decoding are done twice, first, with jerasure_bitmatrix_encode()\n"); 70 | fprintf(stderr, "and jerasure_bitmatrix_decode(), and second using 'smart' scheduling with\n"); 71 | fprintf(stderr, "jerasure_schedule_encode() and jerasure_schedule_decode_lazy().\n"); 72 | 73 | fprintf(stderr, "\n"); 74 | fprintf(stderr, "This demonstrates: cauchy_good_general_coding_matrix()\n"); 75 | fprintf(stderr, " jerasure_bitmatrix_encode()\n"); 76 | fprintf(stderr, " jerasure_bitmatrix_decode()\n"); 77 | fprintf(stderr, " cauchy_n_ones()\n"); 78 | fprintf(stderr, " jerasure_smart_bitmatrix_to_schedule()\n"); 79 | fprintf(stderr, " jerasure_schedule_encode()\n"); 80 | fprintf(stderr, " jerasure_schedule_decode_lazy()\n"); 81 | fprintf(stderr, " jerasure_print_matrix()\n"); 82 | fprintf(stderr, " jerasure_print_bitmatrix()\n"); 83 | fprintf(stderr, " jerasure_get_stats()\n"); 84 | if (s != NULL) fprintf(stderr, "%s\n", s); 85 | exit(1); 86 | } 87 | 88 | static void print_array(char **ptrs, int ndevices, int size, int packetsize, char *label) 89 | { 90 | int i, j, x; 91 | unsigned char *up; 92 | 93 | printf("
\n"); 94 | 95 | for (i = 0; i < ndevices; i++) printf("\n", label, i); 96 | printf("\n"); 97 | printf("\n"); 100 | for (i = 0; i < ndevices; i++) { 101 | printf("\n"); 111 | } 112 | printf("
%s%x
");
 98 |   for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
 99 |   printf("
");
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("
\n"); 113 | } 114 | 115 | int main(int argc, char **argv) 116 | { 117 | int k, w, i, m; 118 | int *matrix, *bitmatrix, **schedule; 119 | char **data, **coding, **dcopy, **ccopy; 120 | int no; 121 | int *erasures, *erased; 122 | double mstats[3], sstats[3]; 123 | uint32_t seed; 124 | 125 | if (argc != 5) usage(NULL); 126 | if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); 127 | if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m"); 128 | if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w"); 129 | if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed"); 130 | if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big"); 131 | 132 | matrix = cauchy_good_general_coding_matrix(k, m, w); 133 | if (matrix == NULL) { 134 | usage("couldn't make coding matrix"); 135 | } 136 | 137 | /* Print out header information to the output file. */ 138 | printf("\n"); 139 | printf("Jerasure Example Output: cauchy_04 %d %d %d %d\n", k, m, w, seed); 140 | printf("

Jerasure Example Output: cauchy_04 %d %d %d %d

\n", k, m, w, seed); 141 | 142 | printf("
\n"); 143 | printf("Parameters:\n"); 144 | printf("
  • Number of data disks (k): %d\n", k); 145 | printf("
  • Number of coding disks (m): %d\n", m); 146 | printf("
  • Word size of the Galois Field: (w): %d\n", w); 147 | printf("
  • Seed for the random number generator: %d\n", seed); 148 | printf("
  • Number of bytes stored per disk: %ld\n", sizeof(long)*w); 149 | printf("
  • Number of packets stored per disk: %d\n", w); 150 | printf("
  • Number of bytes per packet: %ld\n", sizeof(long)); 151 | printf("
\n"); 152 | 153 | /* Print out the matrix and the bitmatrix */ 154 | printf("
\n"); 155 | printf("Here is the matrix, which was created with cauchy_good_general_coding_matrix().\n"); 156 | 157 | printf("
\n");
158 |   jerasure_print_matrix(matrix, m, k, w);
159 |   printf("
\n"); 160 | 161 | bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); 162 | 163 | no = 0; 164 | for (i = 0; i < k*m; i++) { 165 | no += cauchy_n_ones(matrix[i], w); 166 | } 167 | 168 | printf("The bitmatrix, which has %d one%s:

\n", no, (no == 1) ? "" : "s");
169 |   jerasure_print_bitmatrix(bitmatrix, m*w, k*w, w);
170 |   printf("
\n"); 171 | printf("
\n"); 172 | 173 | MOA_Seed(seed); 174 | 175 | data = talloc(char *, k); 176 | dcopy = talloc(char *, k); 177 | for (i = 0; i < k; i++) { 178 | data[i] = talloc(char, sizeof(long)*w); 179 | dcopy[i] = talloc(char, sizeof(long)*w); 180 | MOA_Fill_Random_Region(data[i], sizeof(long)*w); 181 | memcpy(dcopy[i], data[i], sizeof(long)*w); 182 | } 183 | 184 | printf("Here are the packets on the data disks:

\n"); 185 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 186 | 187 | coding = talloc(char *, m); 188 | ccopy = talloc(char *, m); 189 | for (i = 0; i < m; i++) { 190 | coding[i] = talloc(char, sizeof(long)*w); 191 | ccopy[i] = talloc(char, sizeof(long)*w); 192 | } 193 | 194 | jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long)); 195 | jerasure_get_stats(mstats); 196 | 197 | schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix); 198 | jerasure_schedule_encode(k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long)); 199 | jerasure_get_stats(sstats); 200 | 201 | printf("

Encoding with jerasure_bitmatrix_encode() - Bytes XOR'd: %.0lf.
\n", mstats[0]); 202 | printf("Encoding with jerasure_schedule_encode() - Bytes XOR'd: %.0lf.
\n", sstats[0]); 203 | 204 | for (i = 0; i < m; i++) { 205 | if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) { 206 | printf("Problem: the two encodings don't match on disk C%x\n", i); 207 | exit(0); 208 | } 209 | } 210 | 211 | printf("Here are the packets on the coding disks.
\n"); 212 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 213 | printf("


\n"); 214 | 215 | erasures = talloc(int, (m+1)); 216 | erased = talloc(int, (k+m)); 217 | for (i = 0; i < m+k; i++) erased[i] = 0; 218 | for (i = 0; i < m; ) { 219 | erasures[i] = MOA_Random_W(31, 1)%(k+m); 220 | if (erased[erasures[i]] == 0) { 221 | erased[erasures[i]] = 1; 222 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); 223 | i++; 224 | } 225 | } 226 | erasures[i] = -1; 227 | printf("Erasures on the following devices:"); 228 | for (i = 0; erasures[i] != -1; i++) { 229 | printf(" %c%x", ((erasures[i] < k) ? 'D' : 'C'), (erasures[i] < k ? erasures[i] : erasures[i]-k)); 230 | } 231 | printf("
\nHere is the state of the system:\n

\n"); 232 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 233 | printf("

\n"); 234 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 235 | printf("


\n"); 236 | 237 | jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long)); 238 | jerasure_get_stats(mstats); 239 | 240 | printf("

Decoded with jerasure_bitmatrix_decode - Bytes XOR'd: %.0lf.
\n", mstats[0]); 241 | 242 | for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) { 243 | printf("ERROR: D%x after decoding does not match its state before decoding!
\n", i); 244 | } 245 | for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) { 246 | printf("ERROR: C%x after decoding does not match its state before decoding!
\n", i); 247 | } 248 | 249 | for (i = 0; erasures[i] != -1; i++) { 250 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); 251 | } 252 | 253 | jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); 254 | jerasure_get_stats(sstats); 255 | 256 | printf("jerasure_schedule_decode_lazy - Bytes XOR'd: %.0lf.
\n", sstats[0]); 257 | 258 | for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)*w) != 0) { 259 | printf("ERROR: D%x after decoding does not match its state before decoding!
\n", i); 260 | } 261 | for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)*w) != 0) { 262 | printf("ERROR: C%x after decoding does not match its state before decoding!
\n", i); 263 | } 264 | 265 | printf("Here is the state of the system:\n

\n"); 266 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 267 | printf("

\n"); 268 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 269 | printf("


\n"); 270 | 271 | return 0; 272 | } 273 | -------------------------------------------------------------------------------- /Examples/encode_decode.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | # 3 | # Copyright (C) 2014 Red Hat 4 | # 5 | # Author: Loic Dachary 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU Library Public License as published by 9 | # the Free Software Foundation; either version 2, or (at your option) 10 | # any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU Library Public License for more details. 16 | # 17 | trap "rm -fr T Coding" EXIT 18 | 19 | dd if=/dev/urandom of=T bs=4096 count=1 20 | ./encoder T 3 2 reed_sol_van 8 0 0 21 | ./decoder T 22 | -------------------------------------------------------------------------------- /Examples/jerasure_01.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan. 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank. 45 | */ 46 | 47 | #include 48 | #include 49 | #include "jerasure.h" 50 | 51 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 52 | 53 | static void usage(char *s) 54 | { 55 | fprintf(stderr, "usage: jerasure_01 r c w - creates and prints out a matrix in GF(2^w).\n\n"); 56 | fprintf(stderr, " Element i,j is equal to 2^(i*c+j)\n"); 57 | fprintf(stderr, " \n"); 58 | fprintf(stderr, "This demonstrates jerasure_print_matrix().\n"); 59 | if (s != NULL) fprintf(stderr, "%s\n", s); 60 | exit(1); 61 | } 62 | 63 | int main(int argc, char **argv) 64 | { 65 | int r, c, w, i, n; 66 | int *matrix; 67 | 68 | if (argc != 4) usage(NULL); 69 | if (sscanf(argv[1], "%d", &r) == 0 || r <= 0) usage("Bad r"); 70 | if (sscanf(argv[2], "%d", &c) == 0 || c <= 0) usage("Bad c"); 71 | if (sscanf(argv[3], "%d", &w) == 0 || w <= 0) usage("Bad w"); 72 | 73 | matrix = talloc(int, r*c); 74 | 75 | n = 1; 76 | for (i = 0; i < r*c; i++) { 77 | matrix[i] = n; 78 | n = galois_single_multiply(n, 2, w); 79 | } 80 | 81 | printf("jerasure_01"); 82 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 83 | printf("\n"); 84 | printf("

jerasure_01"); 85 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 86 | printf("

\n"); 87 | printf("
\n");
88 | 
89 |   jerasure_print_matrix(matrix, r, c, w);
90 |   return 0;
91 | }
92 | 
93 | 


--------------------------------------------------------------------------------
/Examples/jerasure_02.c:
--------------------------------------------------------------------------------
 1 | /* *
 2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
 3 |  * All rights reserved.
 4 |  *
 5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
 6 |  * Coding Techniques
 7 |  *
 8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
 9 |  *
10 |  * Redistribution and use in source and binary forms, with or without
11 |  * modification, are permitted provided that the following conditions
12 |  * are met:
13 |  *
14 |  *  - Redistributions of source code must retain the above copyright
15 |  *    notice, this list of conditions and the following disclaimer.
16 |  *
17 |  *  - Redistributions in binary form must reproduce the above copyright
18 |  *    notice, this list of conditions and the following disclaimer in
19 |  *    the documentation and/or other materials provided with the
20 |  *    distribution.
21 |  *
22 |  *  - Neither the name of the University of Tennessee nor the names of its
23 |  *    contributors may be used to endorse or promote products derived
24 |  *    from this software without specific prior written permission.
25 |  *
26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 |  * POSSIBILITY OF SUCH DAMAGE.
38 |  */
39 | 
40 | /* Jerasure's authors:
41 | 
42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
44 |    Revision 1.0 - 2007: James S. Plank.
45 |  */
46 | 
47 | #include 
48 | #include 
49 | #include "jerasure.h"
50 | 
51 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
52 | 
53 | static void usage(char *s)
54 | {
55 |   fprintf(stderr, "usage: jerasure_02 r c w - Converts the matrix of jerasure_01 to a bit matrix.\n");
56 |   fprintf(stderr, "       \n");
57 |   fprintf(stderr, "This demonstrates jerasure_print_bitmatrix() and jerasure_matrix_to_bitmatrix().\n");
58 |   if (s != NULL) fprintf(stderr, "%s\n", s);
59 |   exit(1);
60 | }
61 | 
62 | int main(int argc, char **argv)
63 | {
64 |   int r, c, w, i, n;
65 |   int *matrix;
66 |   int *bitmatrix;
67 | 
68 |   if (argc != 4) usage(NULL);
69 |   if (sscanf(argv[1], "%d", &r) == 0 || r <= 0) usage("Bad r");
70 |   if (sscanf(argv[2], "%d", &c) == 0 || c <= 0) usage("Bad c");
71 |   if (sscanf(argv[3], "%d", &w) == 0 || w <= 0) usage("Bad w");
72 | 
73 |   matrix = talloc(int, r*c);
74 | 
75 |   n = 1;
76 |   for (i = 0; i < r*c; i++) {
77 |     matrix[i] = n;
78 |     n = galois_single_multiply(n, 2, w);
79 |   }
80 | 
81 |   bitmatrix = jerasure_matrix_to_bitmatrix(c, r, w, matrix);
82 | 
83 |   printf("jerasure_02");
84 |   for (i = 1; i < argc; i++) printf(" %s", argv[i]);
85 |   printf("\n");
86 |   printf("

jerasure_02"); 87 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 88 | printf("

\n"); 89 | printf("
\n");
90 | 
91 |   jerasure_print_bitmatrix(bitmatrix, r*w, c*w, w);
92 |   return 0;
93 | }
94 | 
95 | 


--------------------------------------------------------------------------------
/Examples/jerasure_03.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank.
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include "jerasure.h"
 51 | 
 52 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
 53 | 
 54 | static void usage(char *s)
 55 | {
 56 |   fprintf(stderr, "usage: jerasure_03 k w - Creates a kxk Cauchy matrix in GF(2^w). \n\n");
 57 |   fprintf(stderr, "       k must be < 2^w.  Element i,j is 1/(i+(2^w-j-1)).  (If that is\n");
 58 |   fprintf(stderr, "       If that is 1/0, then it sets it to zero).  \n");
 59 |   fprintf(stderr, "       It then tests whether that matrix is invertible.\n");
 60 |   fprintf(stderr, "       If it is invertible, then it prints out the inverse.\n");
 61 |   fprintf(stderr, "       Finally, it prints the product of the matrix and its inverse.\n");
 62 |   fprintf(stderr, "       \n");
 63 |   fprintf(stderr, "This demonstrates: jerasure_print_matrix()\n");
 64 |   fprintf(stderr, "                   jerasure_invertible_matrix()\n");
 65 |   fprintf(stderr, "                   jerasure_invert_matrix()\n");
 66 |   fprintf(stderr, "                   jerasure_matrix_multiply().\n");
 67 |   if (s != NULL) fprintf(stderr, "%s\n", s);
 68 |   exit(1);
 69 | }
 70 | 
 71 | int main(int argc, char **argv)
 72 | {
 73 |   unsigned int k, w, i, j, n;
 74 |   int *matrix;
 75 |   int *matrix_copy;
 76 |   int *inverse;
 77 |   int *identity;
 78 | 
 79 |   if (argc != 3) usage(NULL);
 80 |   if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
 81 |   if (sscanf(argv[2], "%d", &w) == 0 || w <= 0 || w > 31) usage("Bad w");
 82 |   if (k >= (1 << w)) usage("K too big");
 83 | 
 84 |   matrix = talloc(int, k*k);
 85 |   matrix_copy = talloc(int, k*k);
 86 |   inverse = talloc(int, k*k);
 87 | 
 88 |   for (i = 0; i < k; i++) {
 89 |     for (j = 0; j < k; j++) {
 90 |       n = i ^ ((1 << w)-1-j);
 91 |       matrix[i*k+j] = (n == 0) ? 0 : galois_single_divide(1, n, w);
 92 |     }
 93 |   }
 94 | 
 95 |   printf("jerasure_03");
 96 |   for (i = 1; i < argc; i++) printf(" %s", argv[i]);
 97 |   printf("\n");
 98 |   printf("

jerasure_03"); 99 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 100 | printf("

\n"); 101 | printf("
\n");
102 | 
103 |   printf("The Cauchy Matrix:\n");
104 |   jerasure_print_matrix(matrix, k, k, w);
105 |   memcpy(matrix_copy, matrix, sizeof(int)*k*k);
106 |   i = jerasure_invertible_matrix(matrix_copy, k, w);
107 |   printf("\nInvertible: %s\n", (i == 1) ? "Yes" : "No");
108 |   if (i == 1) {
109 |     printf("\nInverse:\n");
110 |     memcpy(matrix_copy, matrix, sizeof(int)*k*k);
111 |     i = jerasure_invert_matrix(matrix_copy, inverse, k, w);
112 |     jerasure_print_matrix(inverse, k, k, w);
113 |     identity = jerasure_matrix_multiply(inverse, matrix, k, k, k, k, w);
114 |     printf("\nInverse times matrix (should be identity):\n");
115 |     jerasure_print_matrix(identity, k, k, w);
116 |   }
117 |   return 0;
118 | }
119 | 
120 | 


--------------------------------------------------------------------------------
/Examples/jerasure_04.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank.
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include "jerasure.h"
 51 | 
 52 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
 53 | 
 54 | static void usage(char *s)
 55 | {
 56 |   fprintf(stderr, "usage: jerasure_04 k w - Performs the analogous bit-matrix operations to jerasure_03.\n\n");
 57 |   fprintf(stderr, "       It converts the matrix to a kw*kw bit matrix and does the same operations.\n");
 58 |   fprintf(stderr, "       k must be < 2^w.\n");
 59 |   fprintf(stderr, "This demonstrates: jerasure_print_bitmatrix()\n");
 60 |   fprintf(stderr, "                   jerasure_matrix_to_bitmatrix()\n");
 61 |   fprintf(stderr, "                   jerasure_invertible_bitmatrix()\n");
 62 |   fprintf(stderr, "                   jerasure_invert_bitmatrix()\n");
 63 |   fprintf(stderr, "                   jerasure_matrix_multiply().\n");
 64 |   if (s != NULL) fprintf(stderr, "%s\n", s);
 65 |   exit(1);
 66 | }
 67 | 
 68 | int main(int argc, char **argv)
 69 | {
 70 |   unsigned int k, w, i, j, n;
 71 |   int *matrix;
 72 |   int *bitmatrix;
 73 |   int *bitmatrix_copy;
 74 |   int *inverse;
 75 |   int *identity;
 76 | 
 77 |   if (argc != 3) usage(NULL);
 78 |   if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
 79 |   if (sscanf(argv[2], "%d", &w) == 0 || w <= 0 || w > 31) usage("Bad w");
 80 |   if (k >= (1 << w)) usage("K too big");
 81 | 
 82 |   matrix = talloc(int, k*k);
 83 |   bitmatrix_copy = talloc(int, k*w*k*w);
 84 |   inverse = talloc(int, k*w*k*w);
 85 | 
 86 |   for (i = 0; i < k; i++) {
 87 |     for (j = 0; j < k; j++) {
 88 |       n = i ^ ((1 << w)-1-j);
 89 |       matrix[i*k+j] = (n == 0) ? 0 : galois_single_divide(1, n, w);
 90 |     }
 91 |   }
 92 |   bitmatrix = jerasure_matrix_to_bitmatrix(k, k, w, matrix);
 93 | 
 94 |   printf("jerasure_04");
 95 |   for (i = 1; i < argc; i++) printf(" %s", argv[i]);
 96 |   printf("\n");
 97 |   printf("

jerasure_04"); 98 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 99 | printf("

\n"); 100 | printf("
\n");
101 | 
102 |   printf("The Cauchy Bit-Matrix:\n");
103 |   jerasure_print_bitmatrix(bitmatrix, k*w, k*w, w);
104 |   memcpy(bitmatrix_copy, bitmatrix, sizeof(int)*k*w*k*w);
105 |   i = jerasure_invertible_bitmatrix(bitmatrix_copy, k*w);
106 |   printf("\nInvertible: %s\n", (i == 1) ? "Yes" : "No");
107 |   if (i == 1) {
108 |     printf("\nInverse:\n");
109 |     memcpy(bitmatrix_copy, bitmatrix, sizeof(int)*k*w*k*w);
110 |     i = jerasure_invert_bitmatrix(bitmatrix_copy, inverse, k*w);
111 |     jerasure_print_bitmatrix(inverse, k*w, k*w, w);
112 |     identity = jerasure_matrix_multiply(inverse, bitmatrix, k*w, k*w, k*w, k*w, 2);
113 |     printf("\nInverse times matrix (should be identity):\n");
114 |     jerasure_print_bitmatrix(identity, k*w, k*w, w);
115 |   }
116 |   return 0;
117 | }
118 | 
119 | 


--------------------------------------------------------------------------------
/Examples/jerasure_05.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank.
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include 
 51 | #include 
 52 | #include "jerasure.h"
 53 | 
 54 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
 55 | 
 56 | static void usage(char *s)
 57 | {
 58 |   fprintf(stderr, "usage: jerasure_05 k m w size seed - Does a simple Reed-Solomon coding example in GF(2^w).\n");
 59 |   fprintf(stderr, "       \n");
 60 |   fprintf(stderr, "       k+m must be <= 2^w.  w can be 8, 16 or 32.\n");
 61 |   fprintf(stderr, "       It sets up a Cauchy generator matrix and encodes\n");
 62 |   fprintf(stderr, "       k devices of size bytes with it.  Then it decodes.\n");
 63 |   fprintf(stderr, "       After that, it decodes device 0 by using jerasure_make_decoding_matrix()\n");
 64 |   fprintf(stderr, "       and jerasure_matrix_dotprod().\n");
 65 |   fprintf(stderr, "       \n");
 66 |   fprintf(stderr, "This demonstrates: jerasure_matrix_encode()\n");
 67 |   fprintf(stderr, "                   jerasure_matrix_decode()\n");
 68 |   fprintf(stderr, "                   jerasure_print_matrix()\n");
 69 |   fprintf(stderr, "                   jerasure_make_decoding_matrix()\n");
 70 |   fprintf(stderr, "                   jerasure_matrix_dotprod()\n");
 71 |   if (s != NULL) fprintf(stderr, "\n%s\n\n", s);
 72 |   exit(1);
 73 | }
 74 | 
 75 | static void print_data_and_coding(int k, int m, int w, int size, 
 76 | 		char **data, char **coding) 
 77 | {
 78 |   int i, j, x;
 79 |   int n, sp;
 80 | 
 81 |   if(k > m) n = k;
 82 |   else n = m;
 83 |   sp = size * 2 + size/(w/8) + 8;
 84 | 
 85 |   printf("%-*sCoding\n", sp, "Data");
 86 |   for(i = 0; i < n; i++) {
 87 | 	  if(i < k) {
 88 | 		  printf("D%-2d:", i);
 89 | 		  for(j=0;j< size; j+=(w/8)) { 
 90 | 			  printf(" ");
 91 | 			  for(x=0;x < w/8;x++){
 92 | 				printf("%02x", (unsigned char)data[i][j+x]);
 93 | 			  }
 94 | 		  }
 95 | 		  printf("    ");
 96 | 	  }
 97 | 	  else printf("%*s", sp, "");
 98 | 	  if(i < m) {
 99 | 		  printf("C%-2d:", i);
100 | 		  for(j=0;j< size; j+=(w/8)) { 
101 | 			  printf(" ");
102 | 			  for(x=0;x < w/8;x++){
103 | 				printf("%02x", (unsigned char)coding[i][j+x]);
104 | 			  }
105 | 		  }
106 | 	  }
107 | 	  printf("\n");
108 |   }
109 | 	printf("\n");
110 | }
111 | 
112 | int main(int argc, char **argv)
113 | {
114 |   int k, m, w, size;
115 |   int i, j;
116 |   int *matrix;
117 |   char **data, **coding;
118 |   int *erasures, *erased;
119 |   int *decoding_matrix, *dm_ids;
120 |   uint32_t seed;
121 |   
122 |   if (argc != 6) usage(NULL);
123 |   if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
124 |   if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
125 |   if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
126 |   if (w < 32 && k + m > (1 << w)) usage("k + m must be <= 2 ^ w");
127 |   if (sscanf(argv[4], "%d", &size) == 0 || size % sizeof(long) != 0) 
128 | 		usage("size must be multiple of sizeof(long)");
129 |   if (sscanf(argv[5], "%d", &seed) == 0) usage("Bad seed");
130 | 
131 |   matrix = talloc(int, m*k);
132 |   for (i = 0; i < m; i++) {
133 |     for (j = 0; j < k; j++) {
134 |       matrix[i*k+j] = galois_single_divide(1, i ^ (m + j), w);
135 |     }
136 |   }
137 | 
138 |   printf("jerasure_05");
139 |   for (i = 1; i < argc; i++) printf(" %s", argv[i]);
140 |   printf("\n");
141 |   printf("

jerasure_05"); 142 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 143 | printf("

\n"); 144 | printf("
\n");
145 | 
146 |   printf("The Coding Matrix (the last m rows of the Generator Matrix G^T):\n\n");
147 |   jerasure_print_matrix(matrix, m, k, w);
148 |   printf("\n");
149 | 
150 |   MOA_Seed(seed);
151 |   data = talloc(char *, k);
152 |   for (i = 0; i < k; i++) {
153 |     data[i] = talloc(char, size);
154 |     MOA_Fill_Random_Region(data[i], size);
155 |   }
156 | 
157 |   coding = talloc(char *, m);
158 |   for (i = 0; i < m; i++) {
159 |     coding[i] = talloc(char, size);
160 |   }
161 | 
162 |   jerasure_matrix_encode(k, m, w, matrix, data, coding, size);
163 |   
164 |   printf("Encoding Complete:\n\n");
165 |   print_data_and_coding(k, m, w, size, data, coding);
166 | 
167 |   erasures = talloc(int, (m+1));
168 |   erased = talloc(int, (k+m));
169 |   for (i = 0; i < m+k; i++) erased[i] = 0;
170 |   for (i = 0; i < m; ) {
171 |     erasures[i] = (MOA_Random_W(w, 1))%(k+m);
172 |     if (erased[erasures[i]] == 0) {
173 |       erased[erasures[i]] = 1;
174 | 	  
175 |       bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], size);
176 |       i++;
177 |     }
178 |   }
179 |   erasures[i] = -1;
180 | 
181 |   printf("Erased %d random devices:\n\n", m);
182 |   print_data_and_coding(k, m, w, size, data, coding);
183 |   
184 |   i = jerasure_matrix_decode(k, m, w, matrix, 0, erasures, data, coding, size);
185 | 
186 |   printf("State of the system after decoding:\n\n");
187 |   print_data_and_coding(k, m, w, size, data, coding);
188 |   
189 |   decoding_matrix = talloc(int, k*k);
190 |   dm_ids = talloc(int, k);
191 | 
192 |   for (i = 0; i < m; i++) erased[i] = 1;
193 |   for (; i < k+m; i++) erased[i] = 0;
194 | 
195 |   jerasure_make_decoding_matrix(k, m, w, matrix, erased, decoding_matrix, dm_ids);
196 | 
197 |   printf("Suppose we erase the first %d devices.  Here is the decoding matrix:\n\n", m);
198 |   jerasure_print_matrix(decoding_matrix, k, k, w);
199 |   printf("\n");
200 |   printf("And dm_ids:\n\n");
201 |   jerasure_print_matrix(dm_ids, 1, k, w);
202 | 
203 |   bzero(data[0], size);
204 |   jerasure_matrix_dotprod(k, w, decoding_matrix, dm_ids, 0, data, coding, size);
205 | 
206 |   printf("\nAfter calling jerasure_matrix_dotprod, we calculate the value of device #0 to be:\n\n");
207 |   printf("D0 :");
208 |   for(i=0;i< size; i+=(w/8)) {
209 | 	  printf(" ");
210 | 	  for(j=0;j < w/8;j++){
211 | 		printf("%02x", (unsigned char)data[0][i+j]);
212 | 	  }
213 |   }
214 |   printf("\n\n");
215 | 
216 |   return 0;
217 | }
218 | 


--------------------------------------------------------------------------------
/Examples/jerasure_06.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank.
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include 
 51 | #include 
 52 | #include "jerasure.h"
 53 | 
 54 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
 55 | 
 56 | static void usage(char *s)
 57 | {
 58 |   fprintf(stderr, "usage: jerasure_06 k m w packetsize seed\n");
 59 |   fprintf(stderr, "Does a simple Cauchy Reed-Solomon coding example in GF(2^w).\n");
 60 |   fprintf(stderr, "       \n");
 61 |   fprintf(stderr, "       k+m must be < 2^w.  Packetsize must be a multiple of sizeof(long)\n");
 62 |   fprintf(stderr, "       It sets up a Cauchy generator matrix and encodes k devices of w*packetsize bytes.\n");
 63 |   fprintf(stderr, "       After that, it decodes device 0 by using jerasure_make_decoding_bitmatrix()\n");
 64 |   fprintf(stderr, "       and jerasure_bitmatrix_dotprod().\n");
 65 |   fprintf(stderr, "       \n");
 66 |   fprintf(stderr, "This demonstrates: jerasure_bitmatrix_encode()\n");
 67 |   fprintf(stderr, "                   jerasure_bitmatrix_decode()\n");
 68 |   fprintf(stderr, "                   jerasure_print_bitmatrix()\n");
 69 |   fprintf(stderr, "                   jerasure_make_decoding_bitmatrix()\n");
 70 |   fprintf(stderr, "                   jerasure_bitmatrix_dotprod()\n");
 71 |   if (s != NULL) fprintf(stderr, "\n%s\n\n", s);
 72 |   exit(1);
 73 | }
 74 | 
 75 | static void print_array(char **ptrs, int ndevices, int size, int packetsize, char *label)
 76 | {
 77 |   int i, j, x;
 78 |   unsigned char *up;
 79 | 
 80 |   printf("
\n"); 81 | 82 | for (i = 0; i < ndevices; i++) printf("\n", label, i); 83 | printf("\n"); 84 | printf("\n"); 87 | for (i = 0; i < ndevices; i++) { 88 | printf("\n"); 98 | } 99 | printf("
%s%x
");
 85 |   for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
 86 |   printf("
");
 89 |     up = (unsigned char *) ptrs[i];
 90 |     for (j = 0; j < size/packetsize; j++) {
 91 |       for (x = 0; x < packetsize; x++) {
 92 |         if (x > 0 && x%4 == 0) printf(" ");
 93 |         printf("%02x", up[j*packetsize+x]);
 94 |       }
 95 |       printf("\n");
 96 |     }
 97 |     printf("
\n"); 100 | } 101 | 102 | int main(int argc, char **argv) 103 | { 104 | int k, w, i, j, m, psize, x; 105 | int *matrix, *bitmatrix; 106 | char **data, **coding; 107 | int *erasures, *erased; 108 | int *decoding_matrix, *dm_ids; 109 | uint32_t seed; 110 | 111 | if (argc != 6) usage(NULL); 112 | if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); 113 | if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m"); 114 | if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w"); 115 | if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big"); 116 | if (sscanf(argv[4], "%d", &psize) == 0 || psize <= 0) usage("Bad packetsize"); 117 | if(psize%sizeof(long) != 0) usage("Packetsize must be multiple of sizeof(long)"); 118 | if (sscanf(argv[5], "%d", &seed) == 0) usage("Bad seed"); 119 | 120 | MOA_Seed(seed); 121 | matrix = talloc(int, m*k); 122 | for (i = 0; i < m; i++) { 123 | for (j = 0; j < k; j++) { 124 | matrix[i*k+j] = galois_single_divide(1, i ^ (m + j), w); 125 | } 126 | } 127 | bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); 128 | 129 | printf("jerasure_06"); 130 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 131 | printf("\n"); 132 | printf("

jerasure_06"); 133 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 134 | printf("

\n"); 135 | 136 | printf("
\n"); 137 | printf("Last (m * w) rows of the Generator Matrix: (G^T):\n
\n");
138 |   jerasure_print_bitmatrix(bitmatrix, w*m, w*k, w);
139 |   printf("

\n"); 140 | 141 | data = talloc(char *, k); 142 | for (i = 0; i < k; i++) { 143 | data[i] = talloc(char, psize*w); 144 | MOA_Fill_Random_Region(data[i], psize*w); 145 | } 146 | 147 | coding = talloc(char *, m); 148 | for (i = 0; i < m; i++) { 149 | coding[i] = talloc(char, psize*w); 150 | } 151 | 152 | jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*psize, psize); 153 | 154 | printf("Encoding Complete - Here is the state of the system\n\n"); 155 | printf("

\n"); 156 | print_array(data, k, psize*w, psize, "D"); 157 | printf("

\n"); 158 | print_array(coding, m, psize*w, psize, "C"); 159 | printf("


\n"); 160 | 161 | erasures = talloc(int, (m+1)); 162 | erased = talloc(int, (k+m)); 163 | for (i = 0; i < m+k; i++) erased[i] = 0; 164 | for (i = 0; i < m; ) { 165 | erasures[i] = MOA_Random_W(w, 1)%(k+m); 166 | if (erased[erasures[i]] == 0) { 167 | erased[erasures[i]] = 1; 168 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], psize*w); 169 | i++; 170 | } 171 | } 172 | erasures[i] = -1; 173 | 174 | printf("Erased %d random devices:", m); 175 | for (i = 0; erasures[i] != -1; i++) { 176 | printf(" %c%x", ((erasures[i] < k) ? 'D' : 'C'), (erasures[i] < k ? erasures[i] : erasures[i]-k)); 177 | } 178 | printf(". Here is the state of the system:\n"); 179 | 180 | printf("

\n"); 181 | print_array(data, k, psize*w, psize, "D"); 182 | printf("

\n"); 183 | print_array(coding, m, psize*w, psize, "C"); 184 | printf("


\n"); 185 | 186 | i = jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, 187 | w*psize, psize); 188 | 189 | printf("Here is the state of the system after decoding:\n\n"); 190 | printf("

\n"); 191 | print_array(data, k, psize*w, psize, "D"); 192 | printf("

\n"); 193 | print_array(coding, m, psize*w, psize, "C"); 194 | printf("


\n"); 195 | 196 | decoding_matrix = talloc(int, k*k*w*w); 197 | dm_ids = talloc(int, k); 198 | 199 | x = (m < k) ? m : k; 200 | 201 | for (i = 0; i < x; i++) erased[i] = 1; 202 | for (; i < k+m; i++) erased[i] = 0; 203 | 204 | jerasure_make_decoding_bitmatrix(k, m, w, bitmatrix, erased, decoding_matrix, dm_ids); 205 | 206 | printf("Suppose we erase the first %d devices. Here is the decoding matrix:\n
\n", x);
207 |   jerasure_print_bitmatrix(decoding_matrix, k*w, k*w, w);
208 |   printf("
\n"); 209 | printf("And dm_ids:\n
\n");
210 |   jerasure_print_matrix(dm_ids, 1, k, w);
211 |   printf("

\n"); 212 | 213 | for (i = 0; i < x; i++) bzero(data[i], w*psize); 214 | 215 | printf("Here is the state of the system after the erasures:\n\n"); 216 | printf("

\n"); 217 | print_array(data, k, psize*w, psize, "D"); 218 | printf("

\n"); 219 | print_array(coding, m, psize*w, psize, "C"); 220 | printf("


\n"); 221 | 222 | for (i = 0; i < x; i++) { 223 | jerasure_bitmatrix_dotprod(k, w, decoding_matrix+i*(k*w*w), dm_ids, i, data, coding, w*psize, psize); 224 | } 225 | 226 | printf("Here is the state of the system after calling jerasure_bitmatrix_dotprod() %d time%s with the decoding matrix:\n\n", x, (x == 1) ? "" : "s"); 227 | printf("

\n"); 228 | print_array(data, k, psize*w, psize, "D"); 229 | printf("

\n"); 230 | print_array(coding, m, psize*w, psize, "C"); 231 | printf("


\n"); 232 | return 0; 233 | } 234 | -------------------------------------------------------------------------------- /Examples/jerasure_07.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan. 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank. 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "jerasure.h" 53 | 54 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 55 | 56 | static void usage(char *s) 57 | { 58 | fprintf(stderr, "usage: jerasure_07 k m w seed - Scheduled Cauchy Reed-Solomon coding example in GF(2^w).\n"); 59 | fprintf(stderr, " \n"); 60 | fprintf(stderr, " k+m must be <= 2^w. It sets up a Cauchy generator matrix and encodes\n"); 61 | fprintf(stderr, " k sets of w*%ld bytes. It uses bit-matrix scheduling, both smart and dumb.\n", sizeof(long)); 62 | fprintf(stderr, " It decodes using bit-matrix scheduling, then shows an example of\n"); 63 | fprintf(stderr, " using jerasure_do_scheduled_operations().\n"); 64 | fprintf(stderr, " \n"); 65 | fprintf(stderr, "This demonstrates: jerasure_dumb_bitmatrix_to_schedule()\n"); 66 | fprintf(stderr, " jerasure_smart_bitmatrix_to_schedule()\n"); 67 | fprintf(stderr, " jerasure_schedule_encode()\n"); 68 | fprintf(stderr, " jerasure_schedule_decode_lazy()\n"); 69 | fprintf(stderr, " jerasure_do_scheduled_operations()\n"); 70 | fprintf(stderr, " jerasure_get_stats()\n"); 71 | if (s != NULL) fprintf(stderr, "%s\n", s); 72 | exit(1); 73 | } 74 | 75 | static void print_array(char **ptrs, int ndevices, int size, int packetsize, char *label) 76 | { 77 | int i, j, x; 78 | unsigned char *up; 79 | 80 | printf("
\n"); 81 | 82 | for (i = 0; i < ndevices; i++) printf("\n", label, i); 83 | printf("\n"); 84 | printf("\n"); 87 | for (i = 0; i < ndevices; i++) { 88 | printf("\n"); 98 | } 99 | printf("
%s%x
");
 85 |   for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
 86 |   printf("
");
 89 |     up = (unsigned char *) ptrs[i];
 90 |     for (j = 0; j < size/packetsize; j++) {
 91 |       for (x = 0; x < packetsize; x++) {
 92 |         if (x > 0 && x%4 == 0) printf(" ");
 93 |         printf("%02x", up[j*packetsize+x]);
 94 |       }
 95 |       printf("\n");
 96 |     }
 97 |     printf("
\n"); 100 | } 101 | 102 | int main(int argc, char **argv) 103 | { 104 | int k, w, i, j, m; 105 | int *matrix, *bitmatrix; 106 | char **data, **coding, **ptrs; 107 | int **smart, **dumb; 108 | int *erasures, *erased; 109 | double stats[3]; 110 | uint32_t seed; 111 | 112 | if (argc != 5) usage("Wrong number of arguments"); 113 | if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); 114 | if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m"); 115 | if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w"); 116 | if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed"); 117 | if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big"); 118 | 119 | matrix = talloc(int, m*k); 120 | for (i = 0; i < m; i++) { 121 | for (j = 0; j < k; j++) { 122 | matrix[i*k+j] = galois_single_divide(1, i ^ (m + j), w); 123 | } 124 | } 125 | bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); 126 | 127 | printf("jerasure_07"); 128 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 129 | printf("\n"); 130 | printf("

jerasure_07"); 131 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 132 | printf("

\n"); 133 | printf("
\n"); 134 | 135 | printf("Last m*w rows of the generator matrix (G^T):\n
\n");
136 |   jerasure_print_bitmatrix(bitmatrix, w*m, w*k, w);
137 |   printf("

\n"); 138 | 139 | dumb = jerasure_dumb_bitmatrix_to_schedule(k, m, w, bitmatrix); 140 | smart = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix); 141 | 142 | MOA_Seed(seed); 143 | data = talloc(char *, k); 144 | for (i = 0; i < k; i++) { 145 | data[i] = talloc(char, sizeof(long)*w); 146 | MOA_Fill_Random_Region(data[i], sizeof(long)*w); 147 | } 148 | 149 | coding = talloc(char *, m); 150 | for (i = 0; i < m; i++) { 151 | coding[i] = talloc(char, sizeof(long)*w); 152 | } 153 | 154 | jerasure_schedule_encode(k, m, w, dumb, data, coding, w*sizeof(long), sizeof(long)); 155 | jerasure_get_stats(stats); 156 | printf("Dumb Encoding Complete: - %.0lf XOR'd bytes. State of the system:\n\n", stats[0]); 157 | printf("

\n"); 158 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 159 | printf("

\n"); 160 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 161 | printf("


\n"); 162 | 163 | jerasure_schedule_encode(k, m, w, smart, data, coding, w*sizeof(long), sizeof(long)); 164 | jerasure_get_stats(stats); 165 | printf("Smart Encoding Complete: - %.0lf XOR'd bytes\n\n", stats[0]); 166 | printf("

\n"); 167 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 168 | printf("

\n"); 169 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 170 | printf("


\n"); 171 | 172 | erasures = talloc(int, (m+1)); 173 | erased = talloc(int, (k+m)); 174 | for (i = 0; i < m+k; i++) erased[i] = 0; 175 | for (i = 0; i < m; ) { 176 | erasures[i] = MOA_Random_W(w, 1)%(k+m); 177 | if (erased[erasures[i]] == 0) { 178 | erased[erasures[i]] = 1; 179 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); 180 | i++; 181 | } 182 | } 183 | erasures[i] = -1; 184 | 185 | printf("Erased %d random devices:\n\n", m); 186 | printf("

\n"); 187 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 188 | printf("

\n"); 189 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 190 | printf("


\n"); 191 | 192 | jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); 193 | jerasure_get_stats(stats); 194 | 195 | printf("State of the system after decoding: %.0lf XOR'd bytes\n\n", stats[0]); 196 | printf("

\n"); 197 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 198 | printf("

\n"); 199 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 200 | printf("


\n"); 201 | 202 | ptrs = talloc(char *, (k+m)); 203 | for (i = 0; i < k; i++) ptrs[i] = data[i]; 204 | for (i = 0; i < m; i++) ptrs[k+i] = coding[i]; 205 | 206 | for (j = 0; j < m; j++) bzero(coding[j], sizeof(long)*w); 207 | printf("State of the system after erasing the coding devices:\n"); 208 | printf("

\n"); 209 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 210 | printf("

\n"); 211 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 212 | printf("


\n"); 213 | 214 | jerasure_do_scheduled_operations(ptrs, smart, sizeof(long)); 215 | printf("And using jerasure_do_scheduled_operations(): %.0lf XOR'd bytes\n\n", stats[0]); 216 | printf("

\n"); 217 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 218 | printf("

\n"); 219 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 220 | printf("


\n"); 221 | 222 | return 0; 223 | } 224 | -------------------------------------------------------------------------------- /Examples/jerasure_08.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan. 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank. 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "jerasure.h" 53 | 54 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 55 | 56 | static void usage(char *s) 57 | { 58 | fprintf(stderr, "usage: jerasure_08 k w seed - Example schedule cache usage with RAID-6\n"); 59 | fprintf(stderr, " \n"); 60 | fprintf(stderr, " m=2. k+m must be <= 2^w. It sets up a RAID-6 generator matrix and encodes\n"); 61 | fprintf(stderr, " k sets of w*%ld bytes. It creates a schedule cache for decoding.\n", sizeof(long)); 62 | fprintf(stderr, " It demonstrates using the schedule cache for both encoding and decoding.\n"); 63 | fprintf(stderr, " Then it demonstrates using jerasure_do_parity() to re-encode the first.\n"); 64 | fprintf(stderr, " coding device\n"); 65 | fprintf(stderr, " \n"); 66 | fprintf(stderr, "This demonstrates: jerasure_generate_schedule_cache()\n"); 67 | fprintf(stderr, " jerasure_smart_bitmatrix_to_schedule()\n"); 68 | fprintf(stderr, " jerasure_schedule_encode()\n"); 69 | fprintf(stderr, " jerasure_schedule_decode_cache()\n"); 70 | fprintf(stderr, " jerasure_free_schedule()\n"); 71 | fprintf(stderr, " jerasure_free_schedule_cache()\n"); 72 | fprintf(stderr, " jerasure_get_stats()\n"); 73 | fprintf(stderr, " jerasure_do_parity()\n"); 74 | if (s != NULL) fprintf(stderr, "%s\n", s); 75 | exit(1); 76 | } 77 | 78 | static void print_array(char **ptrs, int ndevices, int size, int packetsize, char *label) 79 | { 80 | int i, j, x; 81 | unsigned char *up; 82 | 83 | printf("
\n"); 84 | 85 | for (i = 0; i < ndevices; i++) printf("\n", label, i); 86 | printf("\n"); 87 | printf("\n"); 90 | for (i = 0; i < ndevices; i++) { 91 | printf("\n"); 101 | } 102 | printf("
%s%x
");
 88 |   for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
 89 |   printf("
");
 92 |     up = (unsigned char *) ptrs[i];
 93 |     for (j = 0; j < size/packetsize; j++) {
 94 |       for (x = 0; x < packetsize; x++) {
 95 |         if (x > 0 && x%4 == 0) printf(" ");
 96 |         printf("%02x", up[j*packetsize+x]);
 97 |       }
 98 |       printf("\n");
 99 |     }
100 |     printf("
\n"); 103 | } 104 | 105 | int main(int argc, char **argv) 106 | { 107 | int k, w, i, j, m; 108 | int *matrix, *bitmatrix; 109 | char **data, **coding; 110 | int **smart, ***cache; 111 | int *erasures, *erased; 112 | double stats[3]; 113 | uint32_t seed; 114 | 115 | if (argc != 4) usage("Wrong number of arguments"); 116 | if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); 117 | if (sscanf(argv[2], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad m"); 118 | if (sscanf(argv[3], "%d", &seed) == 0) usage("Bad seed"); 119 | m = 2; 120 | if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big"); 121 | 122 | MOA_Seed(seed); 123 | 124 | matrix = talloc(int, m*k); 125 | for (j = 0; j < k; j++) matrix[j] = 1; 126 | i = 1; 127 | for (j = 0; j < k; j++) { 128 | matrix[k+j] = i; 129 | i = galois_single_multiply(i, 2, w); 130 | } 131 | bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); 132 | 133 | smart = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix); 134 | cache = jerasure_generate_schedule_cache(k, m, w, bitmatrix, 1); 135 | 136 | data = talloc(char *, k); 137 | for (i = 0; i < k; i++) { 138 | data[i] = talloc(char, sizeof(long)*w); 139 | MOA_Fill_Random_Region(data[i], sizeof(long)*w); 140 | } 141 | 142 | coding = talloc(char *, m); 143 | for (i = 0; i < m; i++) { 144 | coding[i] = talloc(char, sizeof(long)*w); 145 | } 146 | 147 | jerasure_schedule_encode(k, m, w, smart, data, coding, w*sizeof(long), sizeof(long)); 148 | jerasure_get_stats(stats); 149 | 150 | printf("jerasure_08"); 151 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 152 | printf("\n"); 153 | printf("

jerasure_08"); 154 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 155 | printf("

\n"); 156 | printf("
\n"); 157 | 158 | printf("Encoding Complete: - %.0lf XOR'd bytes. Here is the state of the system:\n

\n", stats[0]); 159 | printf("

\n"); 160 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 161 | printf("

\n"); 162 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 163 | printf("


\n"); 164 | 165 | erasures = talloc(int, (m+1)); 166 | erasures[0] = k; 167 | erasures[1] = k+1; 168 | erasures[2] = -1; 169 | for (j = 0; j < m; j++) bzero(coding[j], sizeof(long)*w); 170 | 171 | jerasure_schedule_decode_cache(k, m, w, cache, erasures, data, coding, w*sizeof(long), sizeof(long)); 172 | jerasure_get_stats(stats); 173 | printf("Encoding Using the Schedule Cache: - %.0lf XOR'd bytes\n\n", stats[0]); 174 | printf("

\n"); 175 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 176 | printf("

\n"); 177 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 178 | printf("


\n"); 179 | 180 | erased = talloc(int, (k+m)); 181 | for (i = 0; i < m+k; i++) erased[i] = 0; 182 | for (i = 0; i < m; ) { 183 | erasures[i] = MOA_Random_W(w, 1)%(k+m); 184 | if (erased[erasures[i]] == 0) { 185 | erased[erasures[i]] = 1; 186 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); 187 | i++; 188 | } 189 | } 190 | erasures[i] = -1; 191 | 192 | printf("Erased %d random devices:\n\n", m); 193 | printf("

\n"); 194 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 195 | printf("

\n"); 196 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 197 | printf("


\n"); 198 | 199 | jerasure_schedule_decode_cache(k, m, w, cache, erasures, data, coding, w*sizeof(long), sizeof(long)); 200 | jerasure_get_stats(stats); 201 | 202 | printf("State of the system after decoding: %.0lf XOR'd bytes\n\n", stats[0]); 203 | printf("

\n"); 204 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 205 | printf("

\n"); 206 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 207 | printf("


\n"); 208 | 209 | bzero(coding[0], sizeof(long)*w); 210 | printf("Erased the first coding device:\n\n"); 211 | printf("

\n"); 212 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 213 | printf("

\n"); 214 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 215 | printf("


\n"); 216 | 217 | jerasure_do_parity(k, data, coding[0], sizeof(long)*w); 218 | printf("State of the system after using\n"); 219 | printf("jerasure_do_parity() to re-encode it:\n\n"); 220 | printf("

\n"); 221 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 222 | printf("

\n"); 223 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 224 | printf("


\n"); 225 | 226 | jerasure_free_schedule(smart); 227 | jerasure_free_schedule_cache(k, m, cache); 228 | 229 | printf("Smart schedule and cache freed.\n\n"); 230 | 231 | return 0; 232 | } 233 | -------------------------------------------------------------------------------- /Examples/liberation_01.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan. 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank. 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "jerasure.h" 53 | #include "liberation.h" 54 | 55 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 56 | 57 | static void usage(char *s) 58 | { 59 | fprintf(stderr, "usage: liberation_01 k w seed - Liberation RAID-6 coding/decoding example in GF(2^w).\n"); 60 | fprintf(stderr, " \n"); 61 | fprintf(stderr, " w must be prime and k <= w. It sets up a Liberation bit-matrix\n"); 62 | fprintf(stderr, " then it encodes k devices of w*%ld bytes using dumb bit-matrix scheduling.\n", sizeof(long)); 63 | fprintf(stderr, " It decodes using smart bit-matrix scheduling.\n"); 64 | fprintf(stderr, " \n"); 65 | fprintf(stderr, "This demonstrates: liberation_coding_bitmatrix()\n"); 66 | fprintf(stderr, " jerasure_smart_bitmatrix_to_schedule()\n"); 67 | fprintf(stderr, " jerasure_dumb_bitmatrix_to_schedule()\n"); 68 | fprintf(stderr, " jerasure_schedule_encode()\n"); 69 | fprintf(stderr, " jerasure_schedule_decode_lazy()\n"); 70 | fprintf(stderr, " jerasure_print_bitmatrix()\n"); 71 | fprintf(stderr, " jerasure_get_stats()\n"); 72 | if (s != NULL) fprintf(stderr, "%s\n", s); 73 | exit(1); 74 | } 75 | 76 | static void print_array(char **ptrs, int ndevices, int size, int packetsize, char *label) 77 | { 78 | int i, j, x; 79 | unsigned char *up; 80 | 81 | printf("
\n"); 82 | 83 | for (i = 0; i < ndevices; i++) printf("\n", label, i); 84 | printf("\n"); 85 | printf("\n"); 88 | for (i = 0; i < ndevices; i++) { 89 | printf("\n"); 99 | } 100 | printf("
%s%x
");
 86 |   for (j = 0; j < size/packetsize; j++) printf("Packet %d\n", j);
 87 |   printf("
");
 90 |     up = (unsigned char *) ptrs[i];
 91 |     for (j = 0; j < size/packetsize; j++) {
 92 |       for (x = 0; x < packetsize; x++) {
 93 |         if (x > 0 && x%4 == 0) printf(" ");
 94 |         printf("%02x", up[j*packetsize+x]);
 95 |       }
 96 |       printf("\n");
 97 |     }
 98 |     printf("
\n"); 101 | } 102 | 103 | int main(int argc, char **argv) 104 | { 105 | int k, w, i, m; 106 | int *bitmatrix; 107 | char **data, **coding; 108 | int **dumb; 109 | int *erasures, *erased; 110 | double stats[3]; 111 | uint32_t seed; 112 | 113 | if (argc != 4) usage("Wrong number of arguments"); 114 | if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); 115 | if (sscanf(argv[2], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w"); 116 | if (sscanf(argv[3], "%u", &seed) == 0) usage("Bad seed"); 117 | m = 2; 118 | if (w < k) usage("k is too big"); 119 | for (i = 2; i*i <= w; i++) if (w%i == 0) usage("w isn't prime"); 120 | 121 | bitmatrix = liberation_coding_bitmatrix(k, w); 122 | if (bitmatrix == NULL) { 123 | usage("couldn't make coding matrix"); 124 | } 125 | 126 | printf("liberation_01"); 127 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 128 | printf("\n"); 129 | printf("

liberation_01"); 130 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 131 | printf("

\n"); 132 | printf("
\n"); 133 | 134 | printf("Coding Bit-Matrix:\n
\n");
135 |   jerasure_print_bitmatrix(bitmatrix, w*m, w*k, w);
136 |   printf("

\n"); 137 | 138 | dumb = jerasure_dumb_bitmatrix_to_schedule(k, m, w, bitmatrix); 139 | 140 | MOA_Seed(seed); 141 | data = talloc(char *, k); 142 | for (i = 0; i < k; i++) { 143 | data[i] = talloc(char, sizeof(long)*w); 144 | MOA_Fill_Random_Region(data[i], sizeof(long)*w); 145 | } 146 | 147 | coding = talloc(char *, m); 148 | for (i = 0; i < m; i++) { 149 | coding[i] = talloc(char, sizeof(long)*w); 150 | } 151 | 152 | jerasure_schedule_encode(k, m, w, dumb, data, coding, w*sizeof(long), sizeof(long)); 153 | jerasure_get_stats(stats); 154 | printf("Smart Encoding Complete: - %.0lf XOR'd bytes. State of the system:\n\n", stats[0]); 155 | printf("

\n"); 156 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 157 | printf("

\n"); 158 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 159 | printf("


\n"); 160 | 161 | erasures = talloc(int, (m+1)); 162 | erased = talloc(int, (k+m)); 163 | for (i = 0; i < m+k; i++) erased[i] = 0; 164 | for (i = 0; i < m; ) { 165 | erasures[i] = MOA_Random_W(30,1)%(k+m); 166 | if (erased[erasures[i]] == 0) { 167 | erased[erasures[i]] = 1; 168 | bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); 169 | i++; 170 | } 171 | } 172 | erasures[i] = -1; 173 | 174 | printf("Erased %d random devices:\n\n", m); 175 | printf("

\n"); 176 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 177 | printf("

\n"); 178 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 179 | printf("


\n"); 180 | 181 | jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); 182 | jerasure_get_stats(stats); 183 | 184 | printf("State of the system after decoding: %.0lf XOR'd bytes\n\n", stats[0]); 185 | printf("

\n"); 186 | print_array(data, k, sizeof(long)*w, sizeof(long), "D"); 187 | printf("

\n"); 188 | print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); 189 | printf("


\n"); 190 | 191 | return 0; 192 | } 193 | -------------------------------------------------------------------------------- /Examples/reed_sol_01.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan. 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank. 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "jerasure.h" 53 | #include "reed_sol.h" 54 | 55 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 56 | 57 | static void usage(char *s) 58 | { 59 | fprintf(stderr, "usage: reed_sol_01 k m w seed - Does a simple Reed-Solomon coding example in GF(2^w).\n"); 60 | fprintf(stderr, " \n"); 61 | fprintf(stderr, "w must be 8, 16 or 32. k+m must be <= 2^w. It sets up a classic\n"); 62 | fprintf(stderr, "Vandermonde-based generator matrix and encodes k devices of\n"); 63 | fprintf(stderr, "%ld bytes each with it. Then it decodes.\n", sizeof(long)); 64 | fprintf(stderr, " \n"); 65 | fprintf(stderr, "This demonstrates: jerasure_matrix_encode()\n"); 66 | fprintf(stderr, " jerasure_matrix_decode()\n"); 67 | fprintf(stderr, " jerasure_print_matrix()\n"); 68 | fprintf(stderr, " reed_sol_vandermonde_coding_matrix()\n"); 69 | if (s != NULL) fprintf(stderr, "%s\n", s); 70 | exit(1); 71 | } 72 | 73 | static void print_data_and_coding(int k, int m, int w, int size, 74 | char **data, char **coding) 75 | { 76 | int i, j, x; 77 | int n, sp; 78 | 79 | if(k > m) n = k; 80 | else n = m; 81 | sp = size * 2 + size/(w/8) + 8; 82 | 83 | printf("%-*sCoding\n", sp, "Data"); 84 | for(i = 0; i < n; i++) { 85 | if(i < k) { 86 | printf("D%-2d:", i); 87 | for(j=0;j< size; j+=(w/8)) { 88 | printf(" "); 89 | for(x=0;x < w/8;x++){ 90 | printf("%02x", (unsigned char)data[i][j+x]); 91 | } 92 | } 93 | printf(" "); 94 | } 95 | else printf("%*s", sp, ""); 96 | if(i < m) { 97 | printf("C%-2d:", i); 98 | for(j=0;j< size; j+=(w/8)) { 99 | printf(" "); 100 | for(x=0;x < w/8;x++){ 101 | printf("%02x", (unsigned char)coding[i][j+x]); 102 | } 103 | } 104 | } 105 | printf("\n"); 106 | } 107 | printf("\n"); 108 | } 109 | 110 | int main(int argc, char **argv) 111 | { 112 | long l; 113 | int k, w, i, j, m; 114 | int *matrix; 115 | char **data, **coding, **dcopy, **ccopy; 116 | unsigned char uc; 117 | int *erasures, *erased; 118 | uint32_t seed; 119 | 120 | if (argc != 5) usage(NULL); 121 | if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); 122 | if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m"); 123 | if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w"); 124 | if (sscanf(argv[4], "%u", &seed) == 0) usage("Bad seed"); 125 | if (w <= 16 && k + m > (1 << w)) usage("k + m is too big"); 126 | 127 | matrix = reed_sol_vandermonde_coding_matrix(k, m, w); 128 | 129 | printf("reed_sol_01 %d %d %d %d\n", k, m, w, seed); 130 | printf("

reed_sol_01 %d %d %d %d

\n", k, m, w, seed); 131 | printf("
\n");
132 |   printf("Last m rows of the generator Matrix (G^T):\n\n");
133 |   jerasure_print_matrix(matrix, m, k, w);
134 |   printf("\n");
135 | 
136 |   MOA_Seed(seed);
137 |   data = talloc(char *, k);
138 |   dcopy = talloc(char *, k);
139 |   for (i = 0; i < k; i++) {
140 |     data[i] = talloc(char, sizeof(long));
141 |     dcopy[i] = talloc(char, sizeof(long));
142 |     for (j = 0; j < sizeof(long); j++) {
143 |       uc = MOA_Random_W(8, 1);
144 |       data[i][j] = (char) uc;
145 |     }
146 |     memcpy(dcopy[i], data[i], sizeof(long));
147 |   }
148 | 
149 |   coding = talloc(char *, m);
150 |   ccopy = talloc(char *, m);
151 |   for (i = 0; i < m; i++) {
152 |     coding[i] = talloc(char, sizeof(long));
153 |     ccopy[i] = talloc(char, sizeof(long));
154 |   }
155 | 
156 |   jerasure_matrix_encode(k, m, w, matrix, data, coding, sizeof(long));
157 | 
158 |   for (i = 0; i < m; i++) {
159 |     memcpy(ccopy[i], coding[i], sizeof(long));
160 |   }
161 |   
162 |   printf("Encoding Complete:\n\n");
163 |   print_data_and_coding(k, m, w, sizeof(long), data, coding);
164 | 
165 |   erasures = talloc(int, (m+1));
166 |   erased = talloc(int, (k+m));
167 |   for (i = 0; i < m+k; i++) erased[i] = 0;
168 |   l = 0;
169 |   for (i = 0; i < m; ) {
170 |     erasures[i] = MOA_Random_W(31, 0)%(k+m);
171 |     if (erased[erasures[i]] == 0) {
172 |       erased[erasures[i]] = 1;
173 |       memcpy((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], &l, sizeof(long));
174 |       i++;
175 |     }
176 |   }
177 |   erasures[i] = -1;
178 | 
179 |   printf("Erased %d random devices:\n\n", m);
180 |   print_data_and_coding(k, m, w, sizeof(long), data, coding);
181 |   
182 |   i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, sizeof(long));
183 | 
184 |   printf("State of the system after decoding:\n\n");
185 |   print_data_and_coding(k, m, w, sizeof(long), data, coding);
186 |   
187 |   for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)) != 0) {
188 |     printf("ERROR: D%x after decoding does not match its state before decoding!
\n", i); 189 | } 190 | for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)) != 0) { 191 | printf("ERROR: C%x after decoding does not match its state before decoding!
\n", i); 192 | } 193 | 194 | return 0; 195 | } 196 | -------------------------------------------------------------------------------- /Examples/reed_sol_02.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan. 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank. 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include "jerasure.h" 51 | #include "reed_sol.h" 52 | 53 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 54 | 55 | static void usage(char *s) 56 | { 57 | fprintf(stderr, "usage: reed_sol_02 k m w - Vandermonde matrices in GF(2^w).\n"); 58 | fprintf(stderr, " \n"); 59 | fprintf(stderr, " k+m must be <= 2^w. This simply prints out the \n"); 60 | fprintf(stderr, " Vandermonde matrix in GF(2^w), and then the generator\n"); 61 | fprintf(stderr, " matrix that is constructed from it. See [Plank-Ding-05] for\n"); 62 | fprintf(stderr, " information on how this construction proceeds\n"); 63 | fprintf(stderr, " \n"); 64 | fprintf(stderr, "This demonstrates: reed_sol_extended_vandermonde_matrix()\n"); 65 | fprintf(stderr, " reed_sol_big_vandermonde_coding_matrix()\n"); 66 | fprintf(stderr, " reed_sol_vandermonde_coding_matrix()\n"); 67 | fprintf(stderr, " jerasure_print_matrix()\n"); 68 | if (s != NULL) fprintf(stderr, "%s\n", s); 69 | exit(1); 70 | } 71 | 72 | int main(int argc, char **argv) 73 | { 74 | int k, w, m; 75 | int *matrix; 76 | 77 | if (argc != 4) usage(NULL); 78 | if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); 79 | if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m"); 80 | if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w"); 81 | if (w <= 30 && k + m > (1 << w)) usage("k + m is too big"); 82 | 83 | matrix = reed_sol_extended_vandermonde_matrix(k+m, k, w); 84 | 85 | printf("reed_sol_02 %d %d %d\n", k, m, w); 86 | printf("

reed_sol_02 %d %d %d

\n", k, m, w); 87 | printf("
\n");
 88 |   printf("Extended Vandermonde Matrix:\n\n");
 89 |   jerasure_print_matrix(matrix, k+m, k, w);
 90 |   printf("\n");
 91 | 
 92 |   matrix = reed_sol_big_vandermonde_distribution_matrix(k+m, k, w);
 93 |   printf("Vandermonde Generator Matrix (G^T):\n\n");
 94 |   jerasure_print_matrix(matrix, k+m, k, w);
 95 |   printf("\n");
 96 | 
 97 |   matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
 98 |   printf("Vandermonde Coding Matrix:\n\n");
 99 |   jerasure_print_matrix(matrix, m, k, w);
100 |   printf("\n");
101 | 
102 |   
103 |   return 0;
104 | }
105 | 


--------------------------------------------------------------------------------
/Examples/reed_sol_03.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank.
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include 
 51 | #include "jerasure.h"
 52 | #include "reed_sol.h"
 53 | 
 54 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
 55 | 
 56 | static void usage(char *s)
 57 | {
 58 |   fprintf(stderr, "usage: reed_sol_03 k w seed - Does a simple RAID-6 coding example in GF(2^w).\n");
 59 |   fprintf(stderr, "       \n");
 60 |   fprintf(stderr, "       w must be 8, 16 or 32.  k+2 must be <= 2^w.  It sets up a classic\n");
 61 |   fprintf(stderr, "       RAID-6 coding matrix based on Anvin's optimization and encodes\n");
 62 |   fprintf(stderr, "       %ld-byte devices with it.  Then it decodes.\n", sizeof(long));
 63 |   fprintf(stderr, "       \n");
 64 |   fprintf(stderr, "This demonstrates: reed_sol_r6_encode()\n");
 65 |   fprintf(stderr, "                   reed_sol_r6_coding_matrix()\n");
 66 |   fprintf(stderr, "                   jerasure_matrix_decode()\n");
 67 |   fprintf(stderr, "                   jerasure_print_matrix()\n");
 68 |   if (s != NULL) fprintf(stderr, "%s\n", s);
 69 |   exit(1);
 70 | }
 71 | 
 72 | 
 73 | static void print_data_and_coding(int k, int m, int w, int size, 
 74 | 		char **data, char **coding) 
 75 | {
 76 |   int i, j, x;
 77 |   int n, sp;
 78 | 
 79 |   if(k > m) n = k;
 80 |   else n = m;
 81 |   sp = size * 2 + size/(w/8) + 8;
 82 | 
 83 |   printf("%-*sCoding\n", sp, "Data");
 84 |   for(i = 0; i < n; i++) {
 85 | 	  if(i < k) {
 86 | 		  printf("D%-2d:", i);
 87 | 		  for(j=0;j< size; j+=(w/8)) { 
 88 | 			  printf(" ");
 89 | 			  for(x=0;x < w/8;x++){
 90 | 				printf("%02x", (unsigned char)data[i][j+x]);
 91 | 			  }
 92 | 		  }
 93 | 		  printf("    ");
 94 | 	  }
 95 | 	  else printf("%*s", sp, "");
 96 | 	  if(i < m) {
 97 | 		  printf("C%-2d:", i);
 98 | 		  for(j=0;j< size; j+=(w/8)) { 
 99 | 			  printf(" ");
100 | 			  for(x=0;x < w/8;x++){
101 | 				printf("%02x", (unsigned char)coding[i][j+x]);
102 | 			  }
103 | 		  }
104 | 	  }
105 | 	  printf("\n");
106 |   }
107 | 	printf("\n");
108 | }
109 | 
110 | int main(int argc, char **argv)
111 | {
112 |   long l;
113 |   unsigned char uc;
114 |   int k, w, i, j, m;
115 |   int *matrix;
116 |   char **data, **coding, **dcopy, **ccopy;
117 |   int *erasures, *erased;
118 |   uint32_t seed;
119 |   
120 |   if (argc != 4) usage(NULL);
121 |   if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
122 |   if (sscanf(argv[2], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
123 |   if (sscanf(argv[3], "%d", &seed) == 0) usage("Bad seed");
124 |   m = 2;
125 |   if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");
126 | 
127 |   MOA_Seed(seed);
128 |   matrix = reed_sol_r6_coding_matrix(k, w);
129 | 
130 |   printf("reed_sol_03 %d %d %d\n", k, w, seed);
131 |   printf("

reed_sol_03 %d %d %d

\n", k, w, seed); 132 | printf("
\n");
133 | 
134 |   printf("Last 2 rows of the Generator Matrix:\n\n");
135 |   jerasure_print_matrix(matrix, m, k, w);
136 |   printf("\n");
137 | 
138 |   data = talloc(char *, k);
139 |   dcopy = talloc(char *, k);
140 |   for (i = 0; i < k; i++) {
141 |     data[i] = talloc(char, sizeof(long));
142 |     dcopy[i] = talloc(char, sizeof(long));
143 |     for (j = 0; j < sizeof(long); j++) {
144 |       uc = MOA_Random_W(8, 1) %256;
145 |       data[i][j] = (char) uc;   
146 |     }
147 |     memcpy(dcopy[i], data[i], sizeof(long));
148 |   }
149 | 
150 |   coding = talloc(char *, m);
151 |   ccopy = talloc(char *, m);
152 |   for (i = 0; i < m; i++) {
153 |     coding[i] = talloc(char, sizeof(long));
154 |     ccopy[i] = talloc(char, sizeof(long));
155 |   }
156 | 
157 |   reed_sol_r6_encode(k, w, data, coding, sizeof(long));
158 |   for (i = 0; i < m; i++) {
159 |     memcpy(ccopy[i], coding[i], sizeof(long));
160 |   }
161 |   
162 |   printf("Encoding Complete:\n\n");
163 |   print_data_and_coding(k, m, w, sizeof(long), data, coding);
164 | 
165 |   erasures = talloc(int, (m+1));
166 |   erased = talloc(int, (k+m));
167 |   for (i = 0; i < m+k; i++) erased[i] = 0;
168 |   l = 0;
169 |   for (i = 0; i < m; ) {
170 |     erasures[i] = ((unsigned int) MOA_Random_W(w, 1))%(k+m);
171 |     if (erased[erasures[i]] == 0) {
172 |       erased[erasures[i]] = 1;
173 |       memcpy((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], &l, sizeof(long));
174 |       i++;
175 |     }
176 |   }
177 |   erasures[i] = -1;
178 | 
179 |   printf("Erased %d random devices:\n\n", m);
180 |   print_data_and_coding(k, m, w, sizeof(long), data, coding);
181 |   
182 |   i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, sizeof(long));
183 | 
184 |   printf("State of the system after decoding:\n\n");
185 |   print_data_and_coding(k, m, w, sizeof(long), data, coding);
186 |   
187 |   for (i = 0; i < k; i++) if (memcmp(data[i], dcopy[i], sizeof(long)) != 0) {
188 |     printf("ERROR: D%x after decoding does not match its state before decoding!
\n", i); 189 | } 190 | for (i = 0; i < m; i++) if (memcmp(coding[i], ccopy[i], sizeof(long)) != 0) { 191 | printf("ERROR: C%x after decoding does not match its state before decoding!
\n", i); 192 | } 193 | 194 | return 0; 195 | } 196 | -------------------------------------------------------------------------------- /Examples/reed_sol_04.c: -------------------------------------------------------------------------------- 1 | /* * 2 | * Copyright (c) 2014, James S. Plank and Kevin Greenan 3 | * All rights reserved. 4 | * 5 | * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure 6 | * Coding Techniques 7 | * 8 | * Revision 2.0: Galois Field backend now links to GF-Complete 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 14 | * - Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 17 | * - Redistributions in binary form must reproduce the above copyright 18 | * notice, this list of conditions and the following disclaimer in 19 | * the documentation and/or other materials provided with the 20 | * distribution. 21 | * 22 | * - Neither the name of the University of Tennessee nor the names of its 23 | * contributors may be used to endorse or promote products derived 24 | * from this software without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 33 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 34 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 36 | * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | * POSSIBILITY OF SUCH DAMAGE. 38 | */ 39 | 40 | /* Jerasure's authors: 41 | 42 | Revision 2.x - 2014: James S. Plank and Kevin M. Greenan. 43 | Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman. 44 | Revision 1.0 - 2007: James S. Plank. 45 | */ 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "jerasure.h" 53 | #include "reed_sol.h" 54 | 55 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) 56 | 57 | static void usage(char *s) 58 | { 59 | fprintf(stderr, "usage: reed_sol_04 w seed - Shows reed_sol_galois_wXX_region_multby_2\n"); 60 | fprintf(stderr, " \n"); 61 | fprintf(stderr, " w must be 8, 16 or 32. Sets up an array of 4 random words in\n"); 62 | fprintf(stderr, " GF(2^w) and multiplies them by two. \n"); 63 | fprintf(stderr, " \n"); 64 | fprintf(stderr, "This demonstrates: reed_sol_galois_w08_region_multby_2()\n"); 65 | fprintf(stderr, " reed_sol_galois_w16_region_multby_2()\n"); 66 | fprintf(stderr, " reed_sol_galois_w32_region_multby_2()\n"); 67 | if (s != NULL) fprintf(stderr, "%s\n", s); 68 | exit(1); 69 | } 70 | 71 | int main(int argc, char **argv) 72 | { 73 | unsigned char *x, *y; 74 | unsigned short *xs, *ys; 75 | unsigned int *xi, *yi; 76 | uint32_t seed; 77 | int *a32, *copy; 78 | int i; 79 | int w; 80 | 81 | if (argc != 3) usage(NULL); 82 | if (sscanf(argv[1], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w"); 83 | if (sscanf(argv[2], "%d", &seed) == 0) usage("Bad seed"); 84 | 85 | printf("reed_sol_04 %d %d\n", w, seed); 86 | printf("

reed_sol_04 %d %d

\n", w, seed); 87 | printf("
\n");
 88 | 
 89 |   MOA_Seed(seed);
 90 |   a32 = talloc(int, 4);
 91 |   copy = talloc(int, 4);
 92 |   y = (unsigned char *) a32;
 93 |   for (i = 0; i < 4*sizeof(int); i++) y[i] = MOA_Random_W(8, 1);
 94 |   memcpy(copy, a32, sizeof(int)*4);
 95 | 
 96 |   if (w == 8) {
 97 |     x = (unsigned char *) copy;
 98 |     y = (unsigned char *) a32;
 99 |     reed_sol_galois_w08_region_multby_2((char *) a32, sizeof(int)*4);
100 |     for (i = 0; i < 4*sizeof(int)/sizeof(char); i++) {
101 |        printf("Char %2d: %3u *2 = %3u\n", i, x[i], y[i]);
102 |     }
103 |   } else if (w == 16) {
104 |     xs = (unsigned short *) copy;
105 |     ys = (unsigned short *) a32;
106 |     reed_sol_galois_w16_region_multby_2((char *) a32, sizeof(int)*4);
107 |     for (i = 0; i < 4*sizeof(int)/sizeof(short); i++) {
108 |        printf("Short %2d: %5u *2 = %5u\n", i, xs[i], ys[i]);
109 |     }
110 |   } else if (w == 32) {
111 |     xi = (unsigned int *) copy;
112 |     yi = (unsigned int *) a32;
113 |     reed_sol_galois_w16_region_multby_2((char *) a32, sizeof(int)*4);
114 |     for (i = 0; i < 4*sizeof(int)/sizeof(int); i++) {
115 |        printf("Int %2d: %10u *2 = %10u\n", i, xi[i], yi[i]);
116 |     }
117 |   } 
118 | 
119 |   return 0;
120 | }
121 | 


--------------------------------------------------------------------------------
/Examples/reed_sol_test_gf.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank.
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include 
 51 | #include 
 52 | #include 
 53 | #include 
 54 | #include 
 55 | #include "jerasure.h"
 56 | #include "reed_sol.h"
 57 | 
 58 | #define BUFSIZE 4096
 59 | 
 60 | static void *malloc16(int size) {
 61 |     void *mem = malloc(size+16+sizeof(void*));
 62 |     void **ptr = (void**)((long)(mem+16+sizeof(void*)) & ~(15));
 63 |     ptr[-1] = mem;
 64 |     return ptr;
 65 | }
 66 | 
 67 | #if 0
 68 | // Unused for now.
 69 | static void free16(void *ptr) {
 70 |     free(((void**)ptr)[-1]);
 71 | }
 72 | #endif
 73 | 
 74 | #define talloc(type, num) (type *) malloc16(sizeof(type)*(num))
 75 | 
 76 | static void usage(char *s)
 77 | {
 78 |   fprintf(stderr, "usage: reed_sol_test_gf k m w seed (additional GF args) - Tests Reed-Solomon in GF(2^w).\n");
 79 |   fprintf(stderr, "       \n");
 80 |   fprintf(stderr, "       w must be 8, 16 or 32.  k+m must be <= 2^w.\n");
 81 |   fprintf(stderr, "       See the README for information on the additional GF args.\n");
 82 |   fprintf(stderr, "       Set up a Vandermonde-based distribution matrix and encodes k devices of\n");
 83 |   fprintf(stderr, "       %d bytes each with it.  Then it decodes.\n", BUFSIZE);
 84 |   fprintf(stderr, "       \n");
 85 |   fprintf(stderr, "This tests:        jerasure_matrix_encode()\n");
 86 |   fprintf(stderr, "                   jerasure_matrix_decode()\n");
 87 |   fprintf(stderr, "                   jerasure_print_matrix()\n");
 88 |   fprintf(stderr, "                   galois_change_technique()\n");
 89 |   fprintf(stderr, "                   reed_sol_vandermonde_coding_matrix()\n");
 90 |   if (s != NULL) fprintf(stderr, "%s\n", s);
 91 |   exit(1);
 92 | }
 93 | 
 94 | gf_t* get_gf(int w, int argc, char **argv, int starting)
 95 | {
 96 |   gf_t *gf = (gf_t*)malloc(sizeof(gf_t));
 97 |   if (create_gf_from_argv(gf, w, argc, argv, starting) == 0) {
 98 |     free(gf);
 99 |     gf = NULL;
100 |   }
101 |   return gf;
102 | }
103 | 
104 | int main(int argc, char **argv)
105 | {
106 |   int k, w, i, m;
107 |   int *matrix;
108 |   char **data, **coding, **old_values;
109 |   int *erasures, *erased;
110 |   gf_t *gf = NULL;
111 |   uint32_t seed;
112 |   
113 |   if (argc < 6) usage("Not enough command line arguments");  
114 |   if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
115 |   if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
116 |   if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
117 |   if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed");
118 |   if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");
119 | 
120 |   MOA_Seed(seed);
121 | 
122 |   gf = get_gf(w, argc, argv, 5); 
123 | 
124 |   if (gf == NULL) {
125 |     usage("Invalid arguments given for GF!\n");
126 |   }
127 | 
128 |   galois_change_technique(gf, w); 
129 | 
130 |   matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
131 | 
132 |   printf("reed_sol_test_gf");
133 |   for (i = 1; i < argc; i++) printf(" %s", argv[i]);
134 |   printf("\n");
135 |   printf("

reed_sol_test_gf"); 136 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 137 | printf("

\n"); 138 | printf("
\n");
139 | 
140 |   printf("Last m rows of the generator matrix (G^T):\n\n");
141 |   jerasure_print_matrix(matrix, m, k, w);
142 |   printf("\n");
143 | 
144 |   data = talloc(char *, k);
145 |   for (i = 0; i < k; i++) {
146 |     data[i] = talloc(char, BUFSIZE);
147 |     MOA_Fill_Random_Region(data[i], BUFSIZE);
148 |   }
149 | 
150 |   coding = talloc(char *, m);
151 |   old_values = talloc(char *, m);
152 |   for (i = 0; i < m; i++) {
153 |     coding[i] = talloc(char, BUFSIZE);
154 |     old_values[i] = talloc(char, BUFSIZE);
155 |   }
156 | 
157 |   jerasure_matrix_encode(k, m, w, matrix, data, coding, BUFSIZE);
158 |   
159 |   erasures = talloc(int, (m+1));
160 |   erased = talloc(int, (k+m));
161 |   for (i = 0; i < m+k; i++) erased[i] = 0;
162 |   for (i = 0; i < m; ) {
163 |     erasures[i] = ((unsigned int)MOA_Random_W(w,1))%(k+m);
164 |     if (erased[erasures[i]] == 0) {
165 |       erased[erasures[i]] = 1;
166 |       memcpy(old_values[i], (erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], BUFSIZE);
167 |       bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], BUFSIZE);
168 |       i++;
169 |     }
170 |   }
171 |   erasures[i] = -1;
172 | 
173 |   i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, BUFSIZE);
174 | 
175 |   for (i = 0; i < m; i++) {
176 |     if (erasures[i] < k) {
177 |       if (memcmp(data[erasures[i]], old_values[i], BUFSIZE)) {
178 |         fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
179 |         exit(1);
180 |       }
181 |     } else {
182 |       if (memcmp(coding[erasures[i]-k], old_values[i], BUFSIZE)) {
183 |         fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
184 |         exit(1);
185 |       }
186 |     }
187 |   }
188 |   
189 |   printf("Encoding and decoding were both successful.\n");
190 |   return 0;
191 | }
192 | 


--------------------------------------------------------------------------------
/Examples/reed_sol_time_gf.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank.
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include 
 51 | #include 
 52 | #include 
 53 | #include 
 54 | #include 
 55 | #include "jerasure.h"
 56 | #include "reed_sol.h"
 57 | #include "timing.h"
 58 | 
 59 | static void *malloc16(int size) {
 60 |     void *mem = malloc(size+16+sizeof(void*));
 61 |     void **ptr = (void**)((long)(mem+16+sizeof(void*)) & ~(15));
 62 |     ptr[-1] = mem;
 63 |     return ptr;
 64 | }
 65 | 
 66 | #if 0
 67 | // Unused for now.
 68 | static void free16(void *ptr) {
 69 |     free(((void**)ptr)[-1]);
 70 | }
 71 | #endif
 72 | 
 73 | #define talloc(type, num) (type *) malloc16(sizeof(type)*(num))
 74 | 
 75 | static void usage(char *s)
 76 | {
 77 |   fprintf(stderr, "usage: reed_sol_time_gf k m w seed iterations bufsize (additional GF args) - Test and time Reed-Solomon in a particular GF(2^w).\n");
 78 |   fprintf(stderr, "       \n");
 79 |   fprintf(stderr, "       w must be 8, 16 or 32.  k+m must be <= 2^w.\n");
 80 |   fprintf(stderr, "       See the README for information on the additional GF args.\n");
 81 |   fprintf(stderr, "       Set up a Vandermonde-based distribution matrix and encodes k devices of\n");
 82 |   fprintf(stderr, "       bufsize bytes each with it.  Then it decodes.\n");
 83 |   fprintf(stderr, "       \n");
 84 |   fprintf(stderr, "This tests:        jerasure_matrix_encode()\n");
 85 |   fprintf(stderr, "                   jerasure_matrix_decode()\n");
 86 |   fprintf(stderr, "                   jerasure_print_matrix()\n");
 87 |   fprintf(stderr, "                   galois_change_technique()\n");
 88 |   fprintf(stderr, "                   reed_sol_vandermonde_coding_matrix()\n");
 89 |   if (s != NULL) fprintf(stderr, "%s\n", s);
 90 |   exit(1);
 91 | }
 92 | 
 93 | gf_t* get_gf(int w, int argc, char **argv, int starting)
 94 | {
 95 |   gf_t *gf = (gf_t*)malloc(sizeof(gf_t));
 96 |   if (create_gf_from_argv(gf, w, argc, argv, starting) == 0) {
 97 |     free(gf);
 98 |     gf = NULL;
 99 |   }
100 |   return gf;
101 | }
102 | 
103 | int main(int argc, char **argv)
104 | {
105 |   int k, w, i, m, iterations, bufsize;
106 |   int *matrix;
107 |   char **data, **coding, **old_values;
108 |   int *erasures, *erased;
109 |   uint32_t seed;
110 |   double t = 0, total_time = 0;
111 |   gf_t *gf = NULL;
112 |   
113 |   if (argc < 8) usage(NULL);  
114 |   if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
115 |   if (sscanf(argv[2], "%d", &m) == 0 || m <= 0) usage("Bad m");
116 |   if (sscanf(argv[3], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
117 |   if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed");
118 |   if (sscanf(argv[5], "%d", &iterations) == 0) usage("Bad iterations");
119 |   if (sscanf(argv[6], "%d", &bufsize) == 0) usage("Bad bufsize");
120 |   if (w <= 16 && k + m > (1 << w)) usage("k + m is too big");
121 | 
122 |   MOA_Seed(seed);
123 | 
124 |   gf = get_gf(w, argc, argv, 7); 
125 | 
126 |   if (gf == NULL) {
127 |     usage("Invalid arguments given for GF!\n");
128 |   }
129 | 
130 |   galois_change_technique(gf, w); 
131 | 
132 |   matrix = reed_sol_vandermonde_coding_matrix(k, m, w);
133 | 
134 |   printf("reed_sol_time_gf");
135 |   for (i = 1; i < argc; i++) printf(" %s", argv[i]);
136 |   printf("\n");
137 |   printf("

reed_sol_time_gf"); 138 | for (i = 1; i < argc; i++) printf(" %s", argv[i]); 139 | printf("

\n"); 140 | printf("
\n");
141 | 
142 |   printf("Last m rows of the generator matrix (G^T):\n\n");
143 |   jerasure_print_matrix(matrix, m, k, w);
144 |   printf("\n");
145 | 
146 |   data = talloc(char *, k);
147 |   for (i = 0; i < k; i++) {
148 |     data[i] = talloc(char, bufsize);
149 |     MOA_Fill_Random_Region(data[i], bufsize);
150 |   }
151 | 
152 |   coding = talloc(char *, m);
153 |   old_values = talloc(char *, m);
154 |   for (i = 0; i < m; i++) {
155 |     coding[i] = talloc(char, bufsize);
156 |     old_values[i] = talloc(char, bufsize);
157 |   }
158 | 
159 |   for (i = 0; i < iterations; i++) {
160 |     t = timing_now();
161 |     jerasure_matrix_encode(k, m, w, matrix, data, coding, bufsize);
162 |     total_time += timing_now() - t;
163 |   }
164 | 
165 |   printf("Encode throughput for %d iterations: %.2f MB/s (%.2f sec)\n", iterations, (double)(k*iterations*bufsize/1024/1024) / total_time, total_time);
166 |   
167 |   erasures = talloc(int, (m+1));
168 |   erased = talloc(int, (k+m));
169 |   for (i = 0; i < m+k; i++) erased[i] = 0;
170 |   for (i = 0; i < m; ) {
171 |     erasures[i] = ((unsigned int)MOA_Random_W(w, 1))%(k+m);
172 |     if (erased[erasures[i]] == 0) {
173 |       erased[erasures[i]] = 1;
174 |       memcpy(old_values[i], (erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], bufsize);
175 |       bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], bufsize);
176 |       i++;
177 |     }
178 |   }
179 |   erasures[i] = -1;
180 | 
181 |   for (i = 0; i < iterations; i++) {
182 |     t = timing_now();
183 |     jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, bufsize);
184 |     total_time += timing_now() - t;
185 |   }
186 |   
187 |   printf("Decode throughput for %d iterations: %.2f MB/s (%.2f sec)\n", iterations, (double)(k*iterations*bufsize/1024/1024) / total_time, total_time);
188 | 
189 |   for (i = 0; i < m; i++) {
190 |     if (erasures[i] < k) {
191 |       if (memcmp(data[erasures[i]], old_values[i], bufsize)) {
192 |         fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
193 |         exit(1);
194 |       }
195 |     } else {
196 |       if (memcmp(coding[erasures[i]-k], old_values[i], bufsize)) {
197 |         fprintf(stderr, "Decoding failed for %d!\n", erasures[i]);
198 |         exit(1);
199 |       }
200 |     }
201 |   }
202 |   
203 |   return 0;
204 | }
205 | 


--------------------------------------------------------------------------------
/Examples/test_all_gfs.sh:
--------------------------------------------------------------------------------
 1 | #!/bin/bash
 2 | #
 3 | # Copyright (c) 2013, James S. Plank and Kevin Greenan
 4 | # All rights reserved.
 5 | #
 6 | # Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
 7 | # Coding Techniques
 8 | #
 9 | # Revision 2.0: Galois Field backend now links to GF-Complete
10 | #
11 | # Redistribution and use in source and binary forms, with or without
12 | # modification, are permitted provided that the following conditions
13 | # are met:
14 | #
15 | #  - Redistributions of source code must retain the above copyright
16 | #    notice, this list of conditions and the following disclaimer.
17 | #
18 | #  - Redistributions in binary form must reproduce the above copyright
19 | #    notice, this list of conditions and the following disclaimer in
20 | #    the documentation and/or other materials provided with the
21 | #    distribution.
22 | #
23 | #  - Neither the name of the University of Tennessee nor the names of its
24 | #    contributors may be used to endorse or promote products derived
25 | #    from this software without specific prior written permission.
26 | #
27 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
35 | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
37 | # WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 | # POSSIBILITY OF SUCH DAMAGE.
39 | #
40 | GF_METHODS=${GF_COMPLETE_DIR:-/usr/local/bin}/gf_methods
41 | k=12
42 | m=3
43 | seed=1370
44 | 
45 | if ! test -x ${GF_METHODS} ; then
46 |     ${GF_METHODS}
47 |     exit 1
48 | fi
49 | 
50 | # Test all w=8
51 | ${GF_METHODS} 8 -B -L | awk -F: '{ if ($1 == "w=8") print $2; }' |
52 | while read method; do
53 |   echo "Testing ${k} ${m} 8 $seed ${method}"
54 |   $VALGRIND ./reed_sol_test_gf ${k} ${m} 8 $seed ${method} | tail -n 1
55 |   if [[ $? != "0" ]]; then
56 |     echo "Failed test for ${k} ${m} 8 $seed ${method}"
57 |     exit 1
58 |   fi
59 | done
60 | 
61 | if [[ $? == "1" ]]; then
62 |   exit 1
63 | fi
64 | 
65 | 
66 | # Test all w=16
67 | ${GF_METHODS} 16 -B -L | awk -F: '{ if ($1 == "w=16") print $2; }' |
68 | while read method; do
69 |   echo "Testing ${k} ${m} 16 $seed ${method}"
70 |   $VALGRIND ./reed_sol_test_gf ${k} ${m} 16 $seed ${method} | tail -n 1
71 |   if [[ $? != "0" ]]; then
72 |     echo "Failed test for ${k} ${m} 16 $seed ${method}"
73 |     exit 1
74 |   fi
75 | done
76 | 
77 | 
78 | if [[ $? == "1" ]]; then
79 |   exit 1
80 | fi
81 | 
82 | # Test all w=32
83 | ${GF_METHODS} 32 -B -L | awk -F: '{ if ($1 == "w=32") print $2; }' |
84 | while read method; do
85 |   echo "Testing ${k} ${m} 32 $seed ${method}"
86 |   $VALGRIND ./reed_sol_test_gf ${k} ${m} 32 $seed ${method} | tail -n 1
87 |   if [[ $? != "0" ]]; then
88 |     echo "Failed test for ${k} ${m} 32 $seed ${method}"
89 |     exit 1
90 |   fi
91 | done
92 | 
93 | 
94 | if [[ $? == "1" ]]; then
95 |   exit 1
96 | fi
97 | 
98 | echo "Passed all tests!"
99 | 


--------------------------------------------------------------------------------
/Examples/test_galois.c:
--------------------------------------------------------------------------------
 1 | #include 
 2 | #include "galois.h"
 3 | 
 4 | int main(int argc, char **argv)
 5 | {
 6 |   assert(galois_init_default_field(4) == 0);
 7 |   assert(galois_uninit_field(4) == 0);
 8 |   assert(galois_init_default_field(4) == 0);
 9 |   assert(galois_uninit_field(4) == 0);
10 | 
11 |   assert(galois_init_default_field(8) == 0);
12 |   assert(galois_uninit_field(8) == 0);
13 |   assert(galois_init_default_field(8) == 0);
14 |   assert(galois_uninit_field(8) == 0);
15 | 
16 |   return 0;
17 | }
18 | /*
19 |  * Local Variables:
20 |  * compile-command: "make test_galois && 
21 |  *    libtool --mode=execute valgrind --tool=memcheck --leak-check=full ./test_galois"
22 |  * End:
23 |  */
24 | 


--------------------------------------------------------------------------------
/Examples/time_all_gfs_argv_init.sh:
--------------------------------------------------------------------------------
 1 | #
 2 | #
 3 | # Copyright (c) 2013, James S. Plank and Kevin Greenan
 4 | # All rights reserved.
 5 | #
 6 | # Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
 7 | # Coding Techniques
 8 | #
 9 | # Revision 2.0: Galois Field backend now links to GF-Complete
10 | #
11 | # Redistribution and use in source and binary forms, with or without
12 | # modification, are permitted provided that the following conditions
13 | # are met:
14 | #
15 | #  - Redistributions of source code must retain the above copyright
16 | #    notice, this list of conditions and the following disclaimer.
17 | #
18 | #  - Redistributions in binary form must reproduce the above copyright
19 | #    notice, this list of conditions and the following disclaimer in
20 | #    the documentation and/or other materials provided with the
21 | #    distribution.
22 | #
23 | #  - Neither the name of the University of Tennessee nor the names of its
24 | #    contributors may be used to endorse or promote products derived
25 | #    from this software without specific prior written permission.
26 | #
27 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 | # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 | # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
35 | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
37 | # WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 | # POSSIBILITY OF SUCH DAMAGE.
39 | #
40 | GF_COMPLETE_DIR=/usr/local/bin
41 | GF_METHODS=${GF_COMPLETE_DIR}/gf_methods
42 | ITERATIONS=128
43 | BUFSIZE=65536
44 | k=12
45 | m=3
46 | seed=1370
47 | 
48 | for w in 8 16 32 ; do 
49 |   ${GF_METHODS} $w -B -L | awk -F: '{ if ($1 == "w='$w'") print $2; }' |
50 |   while read method; do
51 |     echo "Testing ${k} ${m} ${w} ${seed} ${ITERATIONS} ${BUFSIZE} ${method}"
52 |     ./reed_sol_time_gf ${k} ${m} ${w} ${seed} ${ITERATIONS} ${BUFSIZE} ${method} | tail -n 2
53 |     if [[ $? != "0" ]]; then
54 |       echo "Failed test for ${k} ${m} ${w} ${seed} ${ITERATIONS} ${BUFSIZE} ${method}"
55 |       exit 1
56 |     fi
57 |   done
58 | 
59 |   if [[ $? == "1" ]]; then
60 |     exit 1
61 |   fi
62 | done
63 | 
64 | echo "Passed all tests!"
65 | 


--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
 1 | 
 2 | Copyright (c) 2013, James S. Plank and Kevin Greenan
 3 | All rights reserved.
 4 | 
 5 | Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure Coding Techniques
 6 | 
 7 | Revision 2.0: Galois Field backend now links to GF-Complete
 8 | 
 9 | Redistribution and use in source and binary forms, with or without
10 | modification, are permitted provided that the following conditions
11 | are met:
12 | 
13 |  - Redistributions of source code must retain the above copyright
14 |    notice, this list of conditions and the following disclaimer.
15 | 
16 |  - Redistributions in binary form must reproduce the above copyright
17 |    notice, this list of conditions and the following disclaimer in
18 |    the documentation and/or other materials provided with the
19 |    distribution.
20 | 
21 |  - Neither the name of the University of Tennessee nor the names of its
22 |    contributors may be used to endorse or promote products derived
23 |    from this software without specific prior written permission.
24 | 
25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
32 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
35 | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 | POSSIBILITY OF SUCH DAMAGE.
37 | 
38 | 


--------------------------------------------------------------------------------
/Makefile.am:
--------------------------------------------------------------------------------
1 | # Jerasure Automake file
2 | 
3 | SUBDIRS = src Examples
4 | 
5 | EXTRA_DIST = Manual.pdf PERF.txt
6 | 


--------------------------------------------------------------------------------
/Manual.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceph/jerasure/de1739cc8483696506829b52e7fda4f6bb195e6a/Manual.pdf


--------------------------------------------------------------------------------
/NEWS:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ceph/jerasure/de1739cc8483696506829b52e7fda4f6bb195e6a/NEWS


--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
 1 | This is revision 2.0 of Jerasure.  This is pretty much Jerasure 1.2 without the
 2 | original Galois Field backend.  Version 2.0 links directly to GF-Complete, which
 3 | is more flexible than the original, and *much* faster, because it leverages SIMD
 4 | instructions.
 5 | Authors: James S. Plank (University of Tennessee)
 6 |          Kevin M. Greenan (Box)
 7 | 
 8 | ------------------------------------------------------------
 9 | 
10 | The online home for jerasure is:
11 | 
12 |   - http://jerasure.org/jerasure/jerasure
13 | 
14 | ------------------------------------------------------------
15 | 
16 | External Documentation:
17 | 
18 | See the file Manual.pdf for the programmer's manual and tutorial.
19 | 
20 | See http://jerasure.org/jerasure/gf-complete for GF-Complete.
21 | 
22 | NOTE: You must have GF-Complete installed (or compiled) in order to use Jerasure 2.0.
23 | 
24 | There are two directories of source code:
25 | 
26 | The src directory contains the jerasure code.
27 | The Examples directory contains the example programs.
28 | 
29 | ------------------------------------------------------------
30 | 
31 | If you do not have Autoconf 2.65 or later installed, you can simply build
32 | from the tarball distribution:
33 | 
34 | http://www.kaymgee.com/Kevin_Greenan/Software_files/jerasure.tar.gz
35 | 
36 | Installing if you are allowed to install GF-Complete on your machine:
37 | (You can skip the autoreconf step if you're using a tarball distribution.)
38 | 
39 | 1.) Install GF-Complete
40 | 2.) autoreconf --force --install (*skip* if you are building from tarball)
41 | 3.) ./configure
42 | 4.) make
43 | 5.) sudo make install
44 | 
45 | This will install the library into your machine's lib directory,
46 | the headers into include, and the example programs into bin.
47 | 
48 | The configuration process assumes shared objects are searched for in
49 | /usr/local/lib. If this is not the case on your system, you can specify a
50 | search path at configuration time. For example:
51 |   ./configure LD_LIBRARY_PATH=/usr/local/lib
52 | 
53 | ------------------------------------------------------------
54 | 
55 | Installing if you can compile GF-Complete, but you cannot install it:
56 | 
57 | 1.) Install GF-Complete.  Let's suppose the full path to GF-Complete is
58 |     in the environment variable  GFP
59 | 2A.) On Linux, set the environment variable LD_LIBRARY_PATH so that it
60 |      includes $GFP/src/.libs
61 | 2B.) On a mac, set the environment variable DYLD_LIBRARY_PATH so that it
62 |      includes $GFP/src/.libs
63 | 2.) ./configure LDFLAGS=-L$GFP/src/.libs/ CPPFLAGS=-I$GFP/include
64 | 3.) make
65 | 
66 | The examples will be in the directory Examples.  The include files will
67 | be in the directory include, and the library will be called libJerasure.a
68 | in the directory src/.libs.
69 | 
70 | ------------------------------------------------------------
71 | 
72 | As long as GF-Complete is installed, Jerasure 2.0 can be used just as previous
73 | versions.  There is no need to define custom Galois Fields.  Jerasure will
74 | determine the default field to use, if one is not specified.
75 | 
76 | If you would like to explore a using a different Galois Field implementation,
77 | please see the manual.
78 | 
79 | ------------------------------------------------------------
80 | 
81 | Testing GF-Complete
82 | 
83 | If the GF-Complete tools are installed in /usr/local/bin
84 | 
85 |   make check
86 | 
87 | If the GF-Complete tools are installed elsewhere
88 | 
89 |   make GF_COMPLETE_DIR=$(pwd)/../gf-complete/tools check
90 | 
91 | To run some tests with valgrind
92 | 
93 |   make VALGRIND='valgrind --tool=memcheck --quiet' \
94 |        GF_COMPLETE_DIR=$(pwd)/../gf-complete/tools \
95 |        check
96 | 


--------------------------------------------------------------------------------
/configure.ac:
--------------------------------------------------------------------------------
 1 | # Jerasure autoconf template
 2 | 
 3 | AC_PREREQ([2.65])
 4 | AC_INIT([Jerasure], [2.0], [], [],
 5 |         [https://jerasure.org/jerasure/jerasure])
 6 | AC_CONFIG_SRCDIR([src/jerasure.c])
 7 | AC_CONFIG_HEADERS([include/config.h])
 8 | 
 9 | AC_CONFIG_AUX_DIR([build-aux])
10 | AC_CONFIG_MACRO_DIR([m4])
11 | 
12 | AM_INIT_AUTOMAKE([1.13 -Wall -Wno-extra-portability])
13 | 
14 | # Package default C compiler flags.
15 | dnl This must be before LT_INIT and AC_PROG_CC.
16 | : ${CFLAGS='-g -O3 -Wall'}
17 | 
18 | LT_INIT([disable-static])
19 | 
20 | # Checks for programs.
21 | AC_PROG_CC
22 | 
23 | # Checks for libraries.
24 | AC_CHECK_LIB([gf_complete], [gf_init_easy], [],
25 |              [AC_MSG_FAILURE(
26 |                [You need to have gf_complete installed.
27 |                   gf_complete is available from http://jerasure.org/jerasure/gf-complete])
28 |              ])
29 | 
30 | # Checks for header files.
31 | AC_CHECK_HEADERS([stddef.h stdint.h stdlib.h string.h sys/time.h unistd.h])
32 | AC_CHECK_HEADERS([gf_complete.h gf_general.h gf_method.h gf_rand.h])
33 | 
34 | # Checks for typedefs, structures, and compiler characteristics.
35 | AC_TYPE_UINT32_T
36 | AC_TYPE_UINT64_T
37 | AX_EXT
38 | 
39 | AC_ARG_ENABLE([sse],
40 |               AS_HELP_STRING([--disable-sse], [Build without SSE optimizations]),
41 |               [if   test "x$enableval" = "xno" ; then
42 |                 SIMD_FLAGS=""
43 |                 echo "DISABLED SSE!!!"
44 |               fi]
45 | )
46 | 
47 | # Checks for library functions.
48 | AC_FUNC_MALLOC
49 | AC_CHECK_FUNCS([bzero getcwd gettimeofday mkdir strchr strdup strrchr])
50 | 
51 | AC_CONFIG_FILES([Examples/Makefile
52 |                  Makefile
53 |                  src/Makefile])
54 | AC_OUTPUT
55 | 


--------------------------------------------------------------------------------
/include/cauchy.h:
--------------------------------------------------------------------------------
 1 | /* *
 2 |  * Copyright (c) 2013, James S. Plank and Kevin Greenan
 3 |  * All rights reserved.
 4 |  *
 5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
 6 |  * Coding Techniques
 7 |  *
 8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
 9 |  *
10 |  * Redistribution and use in source and binary forms, with or without
11 |  * modification, are permitted provided that the following conditions
12 |  * are met:
13 |  *
14 |  *  - Redistributions of source code must retain the above copyright
15 |  *    notice, this list of conditions and the following disclaimer.
16 |  *
17 |  *  - Redistributions in binary form must reproduce the above copyright
18 |  *    notice, this list of conditions and the following disclaimer in
19 |  *    the documentation and/or other materials provided with the
20 |  *    distribution.
21 |  *
22 |  *  - Neither the name of the University of Tennessee nor the names of its
23 |  *    contributors may be used to endorse or promote products derived
24 |  *    from this software without specific prior written permission.
25 |  *
26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 |  * POSSIBILITY OF SUCH DAMAGE.
38 |  */
39 | 
40 | #pragma once
41 | 
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 | 
46 | extern int *cauchy_original_coding_matrix(int k, int m, int w);
47 | extern int *cauchy_xy_coding_matrix(int k, int m, int w, int *x, int *y);
48 | extern void cauchy_improve_coding_matrix(int k, int m, int w, int *matrix);
49 | extern int *cauchy_good_general_coding_matrix(int k, int m, int w);
50 | extern int cauchy_n_ones(int n, int w);
51 | 
52 | #ifdef __cplusplus
53 | }
54 | #endif
55 | 


--------------------------------------------------------------------------------
/include/galois.h:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2013, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | #pragma once
 41 | 
 42 | #include 
 43 | #include 
 44 | 
 45 | #ifdef __cplusplus
 46 | extern "C" {
 47 | #endif
 48 | 
 49 | extern int galois_init_default_field(int w);
 50 | extern int galois_uninit_field(int w);
 51 | extern void galois_change_technique(gf_t *gf, int w);
 52 | 
 53 | extern int galois_single_multiply(int a, int b, int w);
 54 | extern int galois_single_divide(int a, int b, int w);
 55 | extern int galois_inverse(int x, int w);
 56 | 
 57 | void galois_region_xor(           char *src,         /* Source Region */
 58 |                                   char *dest,        /* Dest Region (holds result) */
 59 |                                   int nbytes);      /* Number of bytes in region */
 60 | 
 61 | /* These multiply regions in w=8, w=16 and w=32.  They are much faster
 62 |    than calling galois_single_multiply.  The regions must be long word aligned. */
 63 | 
 64 | void galois_w08_region_multiply(char *region,       /* Region to multiply */
 65 |                                   int multby,       /* Number to multiply by */
 66 |                                   int nbytes,       /* Number of bytes in region */
 67 |                                   char *r2,         /* If r2 != NULL, products go here.  
 68 |                                                        Otherwise region is overwritten */
 69 |                                   int add);         /* If (r2 != NULL && add) the produce is XOR'd with r2 */
 70 | 
 71 | void galois_w16_region_multiply(char *region,       /* Region to multiply */
 72 |                                   int multby,       /* Number to multiply by */
 73 |                                   int nbytes,       /* Number of bytes in region */
 74 |                                   char *r2,         /* If r2 != NULL, products go here.  
 75 |                                                        Otherwise region is overwritten */
 76 |                                   int add);         /* If (r2 != NULL && add) the produce is XOR'd with r2 */
 77 | 
 78 | void galois_w32_region_multiply(char *region,       /* Region to multiply */
 79 |                                   int multby,       /* Number to multiply by */
 80 |                                   int nbytes,       /* Number of bytes in region */
 81 |                                   char *r2,         /* If r2 != NULL, products go here.  
 82 |                                                        Otherwise region is overwritten */
 83 |                                   int add);         /* If (r2 != NULL && add) the produce is XOR'd with r2 */
 84 | 
 85 | gf_t* galois_init_field(int w,
 86 |                              int mult_type,
 87 |                              int region_type,
 88 |                              int divide_type,
 89 |                              uint64_t prim_poly,
 90 |                              int arg1,
 91 |                              int arg2);
 92 | 
 93 | gf_t* galois_init_composite_field(int w,
 94 |                                 int region_type,
 95 |                                 int divide_type,
 96 |                                 int degree,
 97 |                                 gf_t* base_gf);
 98 | 
 99 | gf_t * galois_get_field_ptr(int w);
100 | 
101 | #ifdef __cplusplus
102 | }
103 | #endif
104 | 


--------------------------------------------------------------------------------
/include/liberation.h:
--------------------------------------------------------------------------------
 1 | /* *
 2 |  * Copyright (c) 2013, James S. Plank and Kevin Greenan
 3 |  * All rights reserved.
 4 |  *
 5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
 6 |  * Coding Techniques
 7 |  *
 8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
 9 |  *
10 |  * Redistribution and use in source and binary forms, with or without
11 |  * modification, are permitted provided that the following conditions
12 |  * are met:
13 |  *
14 |  *  - Redistributions of source code must retain the above copyright
15 |  *    notice, this list of conditions and the following disclaimer.
16 |  *
17 |  *  - Redistributions in binary form must reproduce the above copyright
18 |  *    notice, this list of conditions and the following disclaimer in
19 |  *    the documentation and/or other materials provided with the
20 |  *    distribution.
21 |  *
22 |  *  - Neither the name of the University of Tennessee nor the names of its
23 |  *    contributors may be used to endorse or promote products derived
24 |  *    from this software without specific prior written permission.
25 |  *
26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 |  * POSSIBILITY OF SUCH DAMAGE.
38 |  */
39 | 
40 | #pragma once
41 | 
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 | 
46 | extern int *liberation_coding_bitmatrix(int k, int w);
47 | extern int *liber8tion_coding_bitmatrix(int k);
48 | extern int *blaum_roth_coding_bitmatrix(int k, int w);
49 | 
50 | #ifdef __cplusplus
51 | }
52 | #endif
53 | 


--------------------------------------------------------------------------------
/include/reed_sol.h:
--------------------------------------------------------------------------------
 1 | /* *
 2 |  * Copyright (c) 2013, James S. Plank and Kevin Greenan
 3 |  * All rights reserved.
 4 |  *
 5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
 6 |  * Coding Techniques
 7 |  *
 8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
 9 |  *
10 |  * Redistribution and use in source and binary forms, with or without
11 |  * modification, are permitted provided that the following conditions
12 |  * are met:
13 |  *
14 |  *  - Redistributions of source code must retain the above copyright
15 |  *    notice, this list of conditions and the following disclaimer.
16 |  *
17 |  *  - Redistributions in binary form must reproduce the above copyright
18 |  *    notice, this list of conditions and the following disclaimer in
19 |  *    the documentation and/or other materials provided with the
20 |  *    distribution.
21 |  *
22 |  *  - Neither the name of the University of Tennessee nor the names of its
23 |  *    contributors may be used to endorse or promote products derived
24 |  *    from this software without specific prior written permission.
25 |  *
26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 |  * POSSIBILITY OF SUCH DAMAGE.
38 |  */
39 | 
40 | #pragma once
41 | 
42 | #ifdef __cplusplus
43 | extern "C" {
44 | #endif
45 | 
46 | extern int *reed_sol_vandermonde_coding_matrix(int k, int m, int w);
47 | extern int *reed_sol_extended_vandermonde_matrix(int rows, int cols, int w);
48 | extern int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w);
49 | 
50 | extern int reed_sol_r6_encode(int k, int w, char **data_ptrs, char **coding_ptrs, int size);
51 | extern int *reed_sol_r6_coding_matrix(int k, int w);
52 | 
53 | extern void reed_sol_galois_w08_region_multby_2(char *region, int nbytes);
54 | extern void reed_sol_galois_w16_region_multby_2(char *region, int nbytes);
55 | extern void reed_sol_galois_w32_region_multby_2(char *region, int nbytes);
56 | 
57 | #ifdef __cplusplus
58 | }
59 | #endif
60 | 


--------------------------------------------------------------------------------
/include/timing.h:
--------------------------------------------------------------------------------
 1 | // Timing measurement utilities.
 2 | 
 3 | #ifndef JERASURE_INCLUDED__TIMING_H
 4 | #define JERASURE_INCLUDED__TIMING_H
 5 | 
 6 | // Define USE_CLOCK to use clock(). Otherwise use gettimeofday().
 7 | #define USE_CLOCK
 8 | 
 9 | #ifdef USE_CLOCK
10 | #include 
11 | #else
12 | #include 
13 | #endif
14 | 
15 | struct timing {
16 | #ifdef USE_CLOCK
17 |   clock_t clock;
18 | #else
19 |   struct timeval tv;
20 | #endif
21 | };
22 | 
23 | // Get the current time as a double in seconds.
24 | double
25 | timing_now(
26 |   void);
27 | 
28 | // Set *t to the current time.
29 | void
30 | timing_set(
31 |   struct timing * t);
32 | 
33 | // Get *t as a double in seconds.
34 | double
35 | timing_get(
36 |   struct timing * t);
37 | 
38 | // Return *t2 - *t1 as a double in seconds.
39 | double
40 | timing_delta(
41 |   struct timing * t1,
42 |   struct timing * t2);
43 | #endif
44 | 


--------------------------------------------------------------------------------
/m4/ax_check_compile_flag.m4:
--------------------------------------------------------------------------------
 1 | # ===========================================================================
 2 | #   http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
 3 | # ===========================================================================
 4 | #
 5 | # SYNOPSIS
 6 | #
 7 | #   AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
 8 | #
 9 | # DESCRIPTION
10 | #
11 | #   Check whether the given FLAG works with the current language's compiler
12 | #   or gives an error.  (Warnings, however, are ignored)
13 | #
14 | #   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
15 | #   success/failure.
16 | #
17 | #   If EXTRA-FLAGS is defined, it is added to the current language's default
18 | #   flags (e.g. CFLAGS) when the check is done.  The check is thus made with
19 | #   the flags: "CFLAGS EXTRA-FLAGS FLAG".  This can for example be used to
20 | #   force the compiler to issue an error when a bad flag is given.
21 | #
22 | #   INPUT gives an alternative input source to AC_COMPILE_IFELSE.
23 | #
24 | #   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
25 | #   macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
26 | #
27 | # LICENSE
28 | #
29 | #   Copyright (c) 2008 Guido U. Draheim 
30 | #   Copyright (c) 2011 Maarten Bosmans 
31 | #
32 | #   This program is free software: you can redistribute it and/or modify it
33 | #   under the terms of the GNU General Public License as published by the
34 | #   Free Software Foundation, either version 3 of the License, or (at your
35 | #   option) any later version.
36 | #
37 | #   This program is distributed in the hope that it will be useful, but
38 | #   WITHOUT ANY WARRANTY; without even the implied warranty of
39 | #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40 | #   Public License for more details.
41 | #
42 | #   You should have received a copy of the GNU General Public License along
43 | #   with this program. If not, see .
44 | #
45 | #   As a special exception, the respective Autoconf Macro's copyright owner
46 | #   gives unlimited permission to copy, distribute and modify the configure
47 | #   scripts that are the output of Autoconf when processing the Macro. You
48 | #   need not follow the terms of the GNU General Public License when using
49 | #   or distributing such scripts, even though portions of the text of the
50 | #   Macro appear in them. The GNU General Public License (GPL) does govern
51 | #   all other use of the material that constitutes the Autoconf Macro.
52 | #
53 | #   This special exception to the GPL applies to versions of the Autoconf
54 | #   Macro released by the Autoconf Archive. When you make and distribute a
55 | #   modified version of the Autoconf Macro, you may extend this special
56 | #   exception to the GPL to apply to your modified version as well.
57 | 
58 | #serial 3
59 | 
60 | AC_DEFUN([AX_CHECK_COMPILE_FLAG],
61 | [AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX
62 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
63 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
64 |   ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
65 |   _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
66 |   AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
67 |     [AS_VAR_SET(CACHEVAR,[yes])],
68 |     [AS_VAR_SET(CACHEVAR,[no])])
69 |   _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
70 | AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
71 |   [m4_default([$2], :)],
72 |   [m4_default([$3], :)])
73 | AS_VAR_POPDEF([CACHEVAR])dnl
74 | ])dnl AX_CHECK_COMPILE_FLAGS
75 | 


--------------------------------------------------------------------------------
/m4/ax_ext.m4:
--------------------------------------------------------------------------------
  1 | #
  2 | # Modified from autoconf-archive to replace AC_REQUIRE([AX_GCC_X86_*]) with
  3 | # AX_REQUIRE_DEFINED(...).
  4 | #
  5 | # ===========================================================================
  6 | #          http://www.gnu.org/software/autoconf-archive/ax_ext.html
  7 | # ===========================================================================
  8 | #
  9 | # SYNOPSIS
 10 | #
 11 | #   AX_EXT
 12 | #
 13 | # DESCRIPTION
 14 | #
 15 | #   Find supported SIMD extensions by requesting cpuid. When an SIMD
 16 | #   extension is found, the -m"simdextensionname" is added to SIMD_FLAGS if
 17 | #   compiler supports it. For example, if "sse2" is available, then "-msse2"
 18 | #   is added to SIMD_FLAGS.
 19 | #
 20 | #   This macro calls:
 21 | #
 22 | #     AC_SUBST(SIMD_FLAGS)
 23 | #
 24 | #   And defines:
 25 | #
 26 | #     HAVE_MMX / HAVE_SSE / HAVE_SSE2 / HAVE_SSE3 / HAVE_SSSE3 / HAVE_SSE4.1 / HAVE_SSE4.2 / HAVE_AVX
 27 | #
 28 | # LICENSE
 29 | #
 30 | #   Copyright (c) 2007 Christophe Tournayre 
 31 | #   Copyright (c) 2013 Michael Petch 
 32 | #
 33 | #   Copying and distribution of this file, with or without modification, are
 34 | #   permitted in any medium without royalty provided the copyright notice
 35 | #   and this notice are preserved. This file is offered as-is, without any
 36 | #   warranty.
 37 | 
 38 | #serial 13.1
 39 | 
 40 | AC_DEFUN([AX_EXT],
 41 | [
 42 |   AC_REQUIRE([AC_CANONICAL_HOST])
 43 | 
 44 |   case $host_cpu in
 45 |     powerpc*)
 46 |       AC_CACHE_CHECK([whether altivec is supported], [ax_cv_have_altivec_ext],
 47 |           [
 48 |             if test `/usr/sbin/sysctl -a 2>/dev/null| grep -c hw.optional.altivec` != 0; then
 49 |                 if test `/usr/sbin/sysctl -n hw.optional.altivec` = 1; then
 50 |                   ax_cv_have_altivec_ext=yes
 51 |                 fi
 52 |             fi
 53 |           ])
 54 | 
 55 |           if test "$ax_cv_have_altivec_ext" = yes; then
 56 |             AC_DEFINE(HAVE_ALTIVEC,,[Support Altivec instructions])
 57 |             AX_CHECK_COMPILE_FLAG(-faltivec, SIMD_FLAGS="$SIMD_FLAGS -faltivec", [])
 58 |           fi
 59 |     ;;
 60 | 
 61 | 
 62 |     i[[3456]]86*|x86_64*|amd64*)
 63 | 
 64 |       AX_REQUIRE_DEFINED([AX_GCC_X86_CPUID])
 65 |       AX_REQUIRE_DEFINED([AX_GCC_X86_AVX_XGETBV])
 66 | 
 67 |       AX_GCC_X86_CPUID(0x00000001)
 68 |       ecx=0
 69 |       edx=0
 70 |       if test "$ax_cv_gcc_x86_cpuid_0x00000001" != "unknown";
 71 |       then
 72 |         ecx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 3`
 73 |         edx=`echo $ax_cv_gcc_x86_cpuid_0x00000001 | cut -d ":" -f 4`
 74 |       fi
 75 | 
 76 |       AC_CACHE_CHECK([whether mmx is supported], [ax_cv_have_mmx_ext],
 77 |       [
 78 |         ax_cv_have_mmx_ext=no
 79 |         if test "$((0x$edx>>23&0x01))" = 1; then
 80 |           ax_cv_have_mmx_ext=yes
 81 |         fi
 82 |       ])
 83 | 
 84 |       AC_CACHE_CHECK([whether sse is supported], [ax_cv_have_sse_ext],
 85 |       [
 86 |         ax_cv_have_sse_ext=no
 87 |         if test "$((0x$edx>>25&0x01))" = 1; then
 88 |           ax_cv_have_sse_ext=yes
 89 |         fi
 90 |       ])
 91 | 
 92 |       AC_CACHE_CHECK([whether sse2 is supported], [ax_cv_have_sse2_ext],
 93 |       [
 94 |         ax_cv_have_sse2_ext=no
 95 |         if test "$((0x$edx>>26&0x01))" = 1; then
 96 |           ax_cv_have_sse2_ext=yes
 97 |         fi
 98 |       ])
 99 | 
100 |       AC_CACHE_CHECK([whether sse3 is supported], [ax_cv_have_sse3_ext],
101 |       [
102 |         ax_cv_have_sse3_ext=no
103 |         if test "$((0x$ecx&0x01))" = 1; then
104 |           ax_cv_have_sse3_ext=yes
105 |         fi
106 |       ])
107 | 
108 |       AC_CACHE_CHECK([whether ssse3 is supported], [ax_cv_have_ssse3_ext],
109 |       [
110 |         ax_cv_have_ssse3_ext=no
111 |         if test "$((0x$ecx>>9&0x01))" = 1; then
112 |           ax_cv_have_ssse3_ext=yes
113 |         fi
114 |       ])
115 | 
116 |       AC_CACHE_CHECK([whether sse4.1 is supported], [ax_cv_have_sse41_ext],
117 |       [
118 |         ax_cv_have_sse41_ext=no
119 |         if test "$((0x$ecx>>19&0x01))" = 1; then
120 |           ax_cv_have_sse41_ext=yes
121 |         fi
122 |       ])
123 | 
124 |       AC_CACHE_CHECK([whether sse4.2 is supported], [ax_cv_have_sse42_ext],
125 |       [
126 |         ax_cv_have_sse42_ext=no
127 |         if test "$((0x$ecx>>20&0x01))" = 1; then
128 |           ax_cv_have_sse42_ext=yes
129 |         fi
130 |       ])
131 | 
132 |       AC_CACHE_CHECK([whether avx is supported by processor], [ax_cv_have_avx_cpu_ext],
133 |       [
134 |         ax_cv_have_avx_cpu_ext=no
135 |         if test "$((0x$ecx>>28&0x01))" = 1; then
136 |           ax_cv_have_avx_cpu_ext=yes
137 |         fi
138 |       ])
139 | 
140 |       if test x"$ax_cv_have_avx_cpu_ext" = x"yes"; then
141 |         AX_GCC_X86_AVX_XGETBV(0x00000000)
142 | 
143 |         xgetbv_eax="0"
144 |         if test x"$ax_cv_gcc_x86_avx_xgetbv_0x00000000" != x"unknown"; then
145 |           xgetbv_eax=`echo $ax_cv_gcc_x86_avx_xgetbv_0x00000000 | cut -d ":" -f 1`
146 |         fi
147 | 
148 |         AC_CACHE_CHECK([whether avx is supported by operating system], [ax_cv_have_avx_ext],
149 |         [
150 |           ax_cv_have_avx_ext=no
151 | 
152 |           if test "$((0x$ecx>>27&0x01))" = 1; then
153 |             if test "$((0x$xgetbv_eax&0x6))" = 6; then
154 |               ax_cv_have_avx_ext=yes
155 |             fi
156 |           fi
157 |         ])
158 |         if test x"$ax_cv_have_avx_ext" = x"no"; then
159 |           AC_MSG_WARN([Your processor supports AVX, but your operating system doesn't])
160 |         fi
161 |       fi
162 | 
163 |       if test "$ax_cv_have_mmx_ext" = yes; then
164 |         AX_CHECK_COMPILE_FLAG(-mmmx, ax_cv_support_mmx_ext=yes, [])
165 |         if test x"$ax_cv_support_mmx_ext" = x"yes"; then
166 |           SIMD_FLAGS="$SIMD_FLAGS -mmmx"
167 |           AC_DEFINE(HAVE_MMX,,[Support mmx instructions])
168 |         else
169 |           AC_MSG_WARN([Your processor supports mmx instructions but not your compiler, can you try another compiler?])
170 |         fi
171 |       fi
172 | 
173 |       if test "$ax_cv_have_sse_ext" = yes; then
174 |         AX_CHECK_COMPILE_FLAG(-msse, ax_cv_support_sse_ext=yes, [])
175 |         if test x"$ax_cv_support_sse_ext" = x"yes"; then
176 |           SIMD_FLAGS="$SIMD_FLAGS -msse"
177 |           AC_DEFINE(HAVE_SSE,,[Support SSE (Streaming SIMD Extensions) instructions])
178 |         else
179 |           AC_MSG_WARN([Your processor supports sse instructions but not your compiler, can you try another compiler?])
180 |         fi
181 |       fi
182 | 
183 |       if test "$ax_cv_have_sse2_ext" = yes; then
184 |         AX_CHECK_COMPILE_FLAG(-msse2, ax_cv_support_sse2_ext=yes, [])
185 |         if test x"$ax_cv_support_sse2_ext" = x"yes"; then
186 |           SIMD_FLAGS="$SIMD_FLAGS -msse2"
187 |           AC_DEFINE(HAVE_SSE2,,[Support SSE2 (Streaming SIMD Extensions 2) instructions])
188 |         else
189 |           AC_MSG_WARN([Your processor supports sse2 instructions but not your compiler, can you try another compiler?])
190 |         fi
191 |       fi
192 | 
193 |       if test "$ax_cv_have_sse3_ext" = yes; then
194 |         AX_CHECK_COMPILE_FLAG(-msse3, ax_cv_support_sse3_ext=yes, [])
195 |         if test x"$ax_cv_support_sse3_ext" = x"yes"; then
196 |           SIMD_FLAGS="$SIMD_FLAGS -msse3"
197 |           AC_DEFINE(HAVE_SSE3,,[Support SSE3 (Streaming SIMD Extensions 3) instructions])
198 |         else
199 |           AC_MSG_WARN([Your processor supports sse3 instructions but not your compiler, can you try another compiler?])
200 |         fi
201 |       fi
202 | 
203 |       if test "$ax_cv_have_ssse3_ext" = yes; then
204 |         AX_CHECK_COMPILE_FLAG(-mssse3, ax_cv_support_ssse3_ext=yes, [])
205 |         if test x"$ax_cv_support_ssse3_ext" = x"yes"; then
206 |           SIMD_FLAGS="$SIMD_FLAGS -mssse3"
207 |           AC_DEFINE(HAVE_SSSE3,,[Support SSSE3 (Supplemental Streaming SIMD Extensions 3) instructions])
208 |         else
209 |           AC_MSG_WARN([Your processor supports ssse3 instructions but not your compiler, can you try another compiler?])
210 |         fi
211 |       fi
212 | 
213 |       if test "$ax_cv_have_sse41_ext" = yes; then
214 |         AX_CHECK_COMPILE_FLAG(-msse4.1, ax_cv_support_sse41_ext=yes, [])
215 |         if test x"$ax_cv_support_sse41_ext" = x"yes"; then
216 |           SIMD_FLAGS="$SIMD_FLAGS -msse4.1"
217 |           AC_DEFINE(HAVE_SSE4_1,,[Support SSSE4.1 (Streaming SIMD Extensions 4.1) instructions])
218 |         else
219 |           AC_MSG_WARN([Your processor supports sse4.1 instructions but not your compiler, can you try another compiler?])
220 |         fi
221 |       fi
222 | 
223 |       if test "$ax_cv_have_sse42_ext" = yes; then
224 |         AX_CHECK_COMPILE_FLAG(-msse4.2, ax_cv_support_sse42_ext=yes, [])
225 |         if test x"$ax_cv_support_sse42_ext" = x"yes"; then
226 |           SIMD_FLAGS="$SIMD_FLAGS -msse4.2"
227 |           AC_DEFINE(HAVE_SSE4_2,,[Support SSSE4.2 (Streaming SIMD Extensions 4.2) instructions])
228 |         else
229 |           AC_MSG_WARN([Your processor supports sse4.2 instructions but not your compiler, can you try another compiler?])
230 |         fi
231 |       fi
232 | 
233 |       if test "$ax_cv_have_avx_ext" = yes; then
234 |         AX_CHECK_COMPILE_FLAG(-mavx, ax_cv_support_avx_ext=yes, [])
235 |         if test x"$ax_cv_support_avx_ext" = x"yes"; then
236 |           SIMD_FLAGS="$SIMD_FLAGS -mavx"
237 |           AC_DEFINE(HAVE_AVX,,[Support AVX (Advanced Vector Extensions) instructions])
238 |         else
239 |           AC_MSG_WARN([Your processor supports avx instructions but not your compiler, can you try another compiler?])
240 |         fi
241 |       fi
242 | 
243 |   ;;
244 |   esac
245 | 
246 |   AC_SUBST(SIMD_FLAGS)
247 | ])
248 | 


--------------------------------------------------------------------------------
/m4/ax_gcc_x86_avx_xgetbv.m4:
--------------------------------------------------------------------------------
 1 | # ===========================================================================
 2 | #   http://www.gnu.org/software/autoconf-archive/ax_gcc_x86_avx_xgetbv.html
 3 | # ===========================================================================
 4 | #
 5 | # SYNOPSIS
 6 | #
 7 | #   AX_GCC_X86_AVX_XGETBV
 8 | #
 9 | # DESCRIPTION
10 | #
11 | #   On later x86 processors with AVX SIMD support, with gcc or a compiler
12 | #   that has a compatible syntax for inline assembly instructions, run a
13 | #   small program that executes the xgetbv instruction with input OP. This
14 | #   can be used to detect if the OS supports AVX instruction usage.
15 | #
16 | #   On output, the values of the eax and edx registers are stored as
17 | #   hexadecimal strings as "eax:edx" in the cache variable
18 | #   ax_cv_gcc_x86_avx_xgetbv.
19 | #
20 | #   If the xgetbv instruction fails (because you are running a
21 | #   cross-compiler, or because you are not using gcc, or because you are on
22 | #   a processor that doesn't have this instruction),
23 | #   ax_cv_gcc_x86_avx_xgetbv_OP is set to the string "unknown".
24 | #
25 | #   This macro mainly exists to be used in AX_EXT.
26 | #
27 | # LICENSE
28 | #
29 | #   Copyright (c) 2013 Michael Petch 
30 | #
31 | #   This program is free software: you can redistribute it and/or modify it
32 | #   under the terms of the GNU General Public License as published by the
33 | #   Free Software Foundation, either version 3 of the License, or (at your
34 | #   option) any later version.
35 | #
36 | #   This program is distributed in the hope that it will be useful, but
37 | #   WITHOUT ANY WARRANTY; without even the implied warranty of
38 | #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
39 | #   Public License for more details.
40 | #
41 | #   You should have received a copy of the GNU General Public License along
42 | #   with this program. If not, see .
43 | #
44 | #   As a special exception, the respective Autoconf Macro's copyright owner
45 | #   gives unlimited permission to copy, distribute and modify the configure
46 | #   scripts that are the output of Autoconf when processing the Macro. You
47 | #   need not follow the terms of the GNU General Public License when using
48 | #   or distributing such scripts, even though portions of the text of the
49 | #   Macro appear in them. The GNU General Public License (GPL) does govern
50 | #   all other use of the material that constitutes the Autoconf Macro.
51 | #
52 | #   This special exception to the GPL applies to versions of the Autoconf
53 | #   Macro released by the Autoconf Archive. When you make and distribute a
54 | #   modified version of the Autoconf Macro, you may extend this special
55 | #   exception to the GPL to apply to your modified version as well.
56 | 
57 | #serial 1
58 | 
59 | AC_DEFUN([AX_GCC_X86_AVX_XGETBV],
60 | [AC_REQUIRE([AC_PROG_CC])
61 | AC_LANG_PUSH([C])
62 | AC_CACHE_CHECK(for x86-AVX xgetbv $1 output, ax_cv_gcc_x86_avx_xgetbv_$1,
63 |  [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include ], [
64 |      int op = $1, eax, edx;
65 |      FILE *f;
66 |       /* Opcodes for xgetbv */
67 |       __asm__(".byte 0x0f, 0x01, 0xd0"
68 |         : "=a" (eax), "=d" (edx)
69 |         : "c" (op));
70 |      f = fopen("conftest_xgetbv", "w"); if (!f) return 1;
71 |      fprintf(f, "%x:%x\n", eax, edx);
72 |      fclose(f);
73 |      return 0;
74 | ])],
75 |      [ax_cv_gcc_x86_avx_xgetbv_$1=`cat conftest_xgetbv`; rm -f conftest_xgetbv],
76 |      [ax_cv_gcc_x86_avx_xgetbv_$1=unknown; rm -f conftest_xgetbv],
77 |      [ax_cv_gcc_x86_avx_xgetbv_$1=unknown])])
78 | AC_LANG_POP([C])
79 | ])
80 | 


--------------------------------------------------------------------------------
/m4/ax_gcc_x86_cpuid.m4:
--------------------------------------------------------------------------------
 1 | # ===========================================================================
 2 | #     http://www.gnu.org/software/autoconf-archive/ax_gcc_x86_cpuid.html
 3 | # ===========================================================================
 4 | #
 5 | # SYNOPSIS
 6 | #
 7 | #   AX_GCC_X86_CPUID(OP)
 8 | #
 9 | # DESCRIPTION
10 | #
11 | #   On Pentium and later x86 processors, with gcc or a compiler that has a
12 | #   compatible syntax for inline assembly instructions, run a small program
13 | #   that executes the cpuid instruction with input OP. This can be used to
14 | #   detect the CPU type.
15 | #
16 | #   On output, the values of the eax, ebx, ecx, and edx registers are stored
17 | #   as hexadecimal strings as "eax:ebx:ecx:edx" in the cache variable
18 | #   ax_cv_gcc_x86_cpuid_OP.
19 | #
20 | #   If the cpuid instruction fails (because you are running a
21 | #   cross-compiler, or because you are not using gcc, or because you are on
22 | #   a processor that doesn't have this instruction), ax_cv_gcc_x86_cpuid_OP
23 | #   is set to the string "unknown".
24 | #
25 | #   This macro mainly exists to be used in AX_GCC_ARCHFLAG.
26 | #
27 | # LICENSE
28 | #
29 | #   Copyright (c) 2008 Steven G. Johnson 
30 | #   Copyright (c) 2008 Matteo Frigo
31 | #
32 | #   This program is free software: you can redistribute it and/or modify it
33 | #   under the terms of the GNU General Public License as published by the
34 | #   Free Software Foundation, either version 3 of the License, or (at your
35 | #   option) any later version.
36 | #
37 | #   This program is distributed in the hope that it will be useful, but
38 | #   WITHOUT ANY WARRANTY; without even the implied warranty of
39 | #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40 | #   Public License for more details.
41 | #
42 | #   You should have received a copy of the GNU General Public License along
43 | #   with this program. If not, see .
44 | #
45 | #   As a special exception, the respective Autoconf Macro's copyright owner
46 | #   gives unlimited permission to copy, distribute and modify the configure
47 | #   scripts that are the output of Autoconf when processing the Macro. You
48 | #   need not follow the terms of the GNU General Public License when using
49 | #   or distributing such scripts, even though portions of the text of the
50 | #   Macro appear in them. The GNU General Public License (GPL) does govern
51 | #   all other use of the material that constitutes the Autoconf Macro.
52 | #
53 | #   This special exception to the GPL applies to versions of the Autoconf
54 | #   Macro released by the Autoconf Archive. When you make and distribute a
55 | #   modified version of the Autoconf Macro, you may extend this special
56 | #   exception to the GPL to apply to your modified version as well.
57 | 
58 | #serial 7
59 | 
60 | AC_DEFUN([AX_GCC_X86_CPUID],
61 | [AC_REQUIRE([AC_PROG_CC])
62 | AC_LANG_PUSH([C])
63 | AC_CACHE_CHECK(for x86 cpuid $1 output, ax_cv_gcc_x86_cpuid_$1,
64 |  [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include ], [
65 |      int op = $1, eax, ebx, ecx, edx;
66 |      FILE *f;
67 |       __asm__("cpuid"
68 |         : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
69 |         : "a" (op));
70 |      f = fopen("conftest_cpuid", "w"); if (!f) return 1;
71 |      fprintf(f, "%x:%x:%x:%x\n", eax, ebx, ecx, edx);
72 |      fclose(f);
73 |      return 0;
74 | ])],
75 |      [ax_cv_gcc_x86_cpuid_$1=`cat conftest_cpuid`; rm -f conftest_cpuid],
76 |      [ax_cv_gcc_x86_cpuid_$1=unknown; rm -f conftest_cpuid],
77 |      [ax_cv_gcc_x86_cpuid_$1=unknown])])
78 | AC_LANG_POP([C])
79 | ])
80 | 


--------------------------------------------------------------------------------
/m4/ax_require_defined.m4:
--------------------------------------------------------------------------------
 1 | # ===========================================================================
 2 | #    http://www.gnu.org/software/autoconf-archive/ax_require_defined.html
 3 | # ===========================================================================
 4 | #
 5 | # SYNOPSIS
 6 | #
 7 | #   AX_REQUIRE_DEFINED(MACRO)
 8 | #
 9 | # DESCRIPTION
10 | #
11 | #   AX_REQUIRE_DEFINED is a simple helper for making sure other macros have
12 | #   been defined and thus are available for use.  This avoids random issues
13 | #   where a macro isn't expanded.  Instead the configure script emits a
14 | #   non-fatal:
15 | #
16 | #     ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found
17 | #
18 | #   It's like AC_REQUIRE except it doesn't expand the required macro.
19 | #
20 | #   Here's an example:
21 | #
22 | #     AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG])
23 | #
24 | # LICENSE
25 | #
26 | #   Copyright (c) 2014 Mike Frysinger 
27 | #
28 | #   Copying and distribution of this file, with or without modification, are
29 | #   permitted in any medium without royalty provided the copyright notice
30 | #   and this notice are preserved. This file is offered as-is, without any
31 | #   warranty.
32 | 
33 | #serial 1
34 | 
35 | AC_DEFUN([AX_REQUIRE_DEFINED], [dnl
36 |   m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])])
37 | ])dnl AX_REQUIRE_DEFINED
38 | 


--------------------------------------------------------------------------------
/src/Makefile.am:
--------------------------------------------------------------------------------
 1 | # Jerasure AM file
 2 | 
 3 | AM_CPPFLAGS = -I$(top_srcdir)/include
 4 | AM_CFLAGS = $(SIMD_FLAGS)
 5 | 
 6 | lib_LTLIBRARIES = libJerasure.la
 7 | libJerasure_la_SOURCES = galois.c jerasure.c reed_sol.c cauchy.c liberation.c
 8 | libJerasure_la_LDFLAGS = -version-info 2:0:0
 9 | libJerasure_la_LIBADD = -lgf_complete
10 | include_HEADERS = ../include/jerasure.h
11 | 
12 | # Install additional Jerasure header files in their own directory.
13 | jerasureincludedir = $(includedir)/jerasure
14 | jerasureinclude_HEADERS = \
15 |   ../include/cauchy.h \
16 |   ../include/galois.h \
17 |   ../include/liberation.h \
18 |   ../include/reed_sol.h
19 | 
20 | noinst_HEADERS = ../include/timing.h
21 | noinst_LIBRARIES = libtiming.a
22 | libtiming_a_SOURCES = timing.c
23 | 


--------------------------------------------------------------------------------
/src/galois.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include 
 51 | #include 
 52 | 
 53 | #include "galois.h"
 54 | 
 55 | #define MAX_GF_INSTANCES 64
 56 | gf_t *gfp_array[MAX_GF_INSTANCES] = { 0 };
 57 | int  gfp_is_composite[MAX_GF_INSTANCES] = { 0 };
 58 | 
 59 | gf_t *galois_get_field_ptr(int w)
 60 | {
 61 |   if (gfp_array[w] != NULL) {
 62 |     return gfp_array[w];
 63 |   }
 64 | 
 65 |   return NULL;
 66 | }
 67 | 
 68 | gf_t* galois_init_field(int w,
 69 |                         int mult_type,
 70 |                         int region_type,
 71 |                         int divide_type,
 72 |                         uint64_t prim_poly,
 73 |                         int arg1,
 74 |                         int arg2)
 75 | {
 76 |   int scratch_size;
 77 |   void *scratch_memory;
 78 |   gf_t *gfp;
 79 | 
 80 |   if (w <= 0 || w > 32) {
 81 |     fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
 82 |     assert(0);
 83 |   }
 84 | 
 85 |   gfp = (gf_t *) malloc(sizeof(gf_t));
 86 |   if (!gfp) {
 87 |     fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
 88 |     assert(0);
 89 |   }
 90 | 
 91 |   scratch_size = gf_scratch_size(w, mult_type, region_type, divide_type, arg1, arg2);
 92 |   if (!scratch_size) {
 93 |     fprintf(stderr, "ERROR -- cannot get scratch size for base field w=%d\n", w);
 94 |     assert(0);
 95 |   }
 96 | 
 97 |   scratch_memory = malloc(scratch_size);
 98 |   if (!scratch_memory) {
 99 |     fprintf(stderr, "ERROR -- cannot get scratch memory for base field w=%d\n", w);
100 |     assert(0);
101 |   }
102 | 
103 |   if(!gf_init_hard(gfp,
104 |                    w, 
105 |                    mult_type, 
106 |                    region_type, 
107 |                    divide_type, 
108 |                    prim_poly, 
109 |                    arg1, 
110 |                    arg2, 
111 |                    NULL, 
112 |                    scratch_memory))
113 |   {
114 |     fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
115 |     assert(0);
116 |   }
117 | 
118 |   gfp_is_composite[w] = 0;
119 |   return gfp;
120 | }
121 | 
122 | gf_t* galois_init_composite_field(int w,
123 |                                 int region_type,
124 |                                 int divide_type,
125 |                                 int degree,
126 |                                 gf_t* base_gf)
127 | {
128 |   int scratch_size;
129 |   void *scratch_memory;
130 |   gf_t *gfp;
131 |   
132 |   if (w <= 0 || w > 32) {
133 |     fprintf(stderr, "ERROR -- cannot init composite field for w=%d\n", w);
134 |     assert(0);
135 |   }
136 |   
137 |   gfp = (gf_t *) malloc(sizeof(gf_t));
138 |   if (!gfp) {
139 |     fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
140 |     assert(0);
141 |   }
142 | 
143 |   scratch_size = gf_scratch_size(w, GF_MULT_COMPOSITE, region_type, divide_type, degree, 0);
144 |   if (!scratch_size) {
145 |     fprintf(stderr, "ERROR -- cannot get scratch size for composite field w=%d\n", w);
146 |     assert(0);
147 |   }
148 | 
149 |   scratch_memory = malloc(scratch_size);
150 |   if (!scratch_memory) {
151 |     fprintf(stderr, "ERROR -- cannot get scratch memory for composite field w=%d\n", w);
152 |     assert(0);
153 |   }
154 | 
155 |   if(!gf_init_hard(gfp,
156 |                    w,
157 |                    GF_MULT_COMPOSITE,
158 |                    region_type,
159 |                    divide_type,
160 |                    0, 
161 |                    degree, 
162 |                    0, 
163 |                    base_gf,
164 |                    scratch_memory))
165 |   {
166 |     fprintf(stderr, "ERROR -- cannot init default composite field for w=%d\n", w);
167 |     assert(0);
168 |   }
169 |   gfp_is_composite[w] = 1;
170 |   return gfp;
171 | }
172 | 
173 | int galois_init_default_field(int w)
174 | {
175 |   if (gfp_array[w] == NULL) {
176 |     gfp_array[w] = (gf_t*)malloc(sizeof(gf_t));
177 |     if(gfp_array[w] == NULL)
178 |       return ENOMEM;
179 |     if (!gf_init_easy(gfp_array[w], w))
180 |       return EINVAL;
181 |   }
182 |   return 0;
183 | }
184 | 
185 | int galois_uninit_field(int w)
186 | {
187 |   int ret = 0;
188 |   if (gfp_array[w] != NULL) {
189 |     int recursive = 1;
190 |     ret = gf_free(gfp_array[w], recursive);
191 |     free(gfp_array[w]);
192 |     gfp_array[w] = NULL;
193 |   }
194 |   return ret;
195 | }
196 | 
197 | static void galois_init(int w)
198 | {
199 |   if (w <= 0 || w > 32) {
200 |     fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
201 |     assert(0);
202 |   }
203 | 
204 |   switch (galois_init_default_field(w)) {
205 |   case ENOMEM:
206 |     fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
207 |     assert(0);
208 |     break;
209 |   case EINVAL:
210 |     fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
211 |     assert(0);
212 |     break;
213 |   }
214 | }
215 | 
216 | 
217 | static int is_valid_gf(gf_t *gf, int w)
218 | {
219 |   // TODO: I assume we may eventually
220 |   // want to do w=64 and 128, so w
221 |   // will be needed to perform this check
222 |   (void)w;
223 | 
224 |   if (gf == NULL) {
225 |     return 0;
226 |   }
227 |   if (gf->multiply.w32 == NULL) {
228 |     return 0;
229 |   }
230 |   if (gf->multiply_region.w32 == NULL) {
231 |     return 0;
232 |   }
233 |   if (gf->divide.w32 == NULL) {
234 |     return 0;
235 |   }
236 |   if (gf->inverse.w32 == NULL) {
237 |     return 0;
238 |   }
239 |   if (gf->extract_word.w32 == NULL) {
240 |     return 0;
241 |   }
242 | 
243 |   return 1;
244 | }
245 | 
246 | void galois_change_technique(gf_t *gf, int w)
247 | {
248 |   if (w <= 0 || w > 32) {
249 |     fprintf(stderr, "ERROR -- cannot support Galois field for w=%d\n", w);
250 |     assert(0);
251 |   }
252 | 
253 |   if (!is_valid_gf(gf, w)) {
254 |     fprintf(stderr, "ERROR -- overriding with invalid Galois field for w=%d\n", w);
255 |     assert(0);
256 |   }
257 | 
258 |   if (gfp_array[w] != NULL) {
259 |     gf_free(gfp_array[w], gfp_is_composite[w]);
260 |   }
261 | 
262 |   gfp_array[w] = gf;
263 | }
264 | 
265 | int galois_single_multiply(int x, int y, int w)
266 | {
267 |   if (x == 0 || y == 0) return 0;
268 |   
269 |   if (gfp_array[w] == NULL) {
270 |     galois_init(w);
271 |   }
272 | 
273 |   if (w <= 32) {
274 |     return gfp_array[w]->multiply.w32(gfp_array[w], x, y);
275 |   } else {
276 |     fprintf(stderr, "ERROR -- Galois field not implemented for w=%d\n", w);
277 |     return 0;
278 |   }
279 | }
280 | 
281 | int galois_single_divide(int x, int y, int w)
282 | {
283 |   if (x == 0) return 0;
284 |   if (y == 0) return -1;
285 | 
286 |   if (gfp_array[w] == NULL) {
287 |     galois_init(w);
288 |   }
289 | 
290 |   if (w <= 32) {
291 |     return gfp_array[w]->divide.w32(gfp_array[w], x, y);
292 |   } else {
293 |     fprintf(stderr, "ERROR -- Galois field not implemented for w=%d\n", w);
294 |     return 0;
295 |   }
296 | }
297 | 
298 | void galois_w08_region_multiply(char *region,      /* Region to multiply */
299 |                                   int multby,       /* Number to multiply by */
300 |                                   int nbytes,        /* Number of bytes in region */
301 |                                   char *r2,          /* If r2 != NULL, products go here */
302 |                                   int add)
303 | {
304 |   if (gfp_array[8] == NULL) {
305 |     galois_init(8);
306 |   }
307 |   gfp_array[8]->multiply_region.w32(gfp_array[8], region, r2, multby, nbytes, add);
308 | }
309 | 
310 | void galois_w16_region_multiply(char *region,      /* Region to multiply */
311 |                                   int multby,       /* Number to multiply by */
312 |                                   int nbytes,        /* Number of bytes in region */
313 |                                   char *r2,          /* If r2 != NULL, products go here */
314 |                                   int add)
315 | {
316 |   if (gfp_array[16] == NULL) {
317 |     galois_init(16);
318 |   }
319 |   gfp_array[16]->multiply_region.w32(gfp_array[16], region, r2, multby, nbytes, add);
320 | }
321 | 
322 | 
323 | void galois_w32_region_multiply(char *region,      /* Region to multiply */
324 |                                   int multby,       /* Number to multiply by */
325 |                                   int nbytes,        /* Number of bytes in region */
326 |                                   char *r2,          /* If r2 != NULL, products go here */
327 |                                   int add)
328 | {
329 |   if (gfp_array[32] == NULL) {
330 |     galois_init(32);
331 |   }
332 |   gfp_array[32]->multiply_region.w32(gfp_array[32], region, r2, multby, nbytes, add);
333 | }
334 | 
335 | void galois_w8_region_xor(void *src, void *dest, int nbytes)
336 | {
337 |   if (gfp_array[8] == NULL) {
338 |     galois_init(8);
339 |   }
340 |   gfp_array[8]->multiply_region.w32(gfp_array[32], src, dest, 1, nbytes, 1);
341 | }
342 | 
343 | void galois_w16_region_xor(void *src, void *dest, int nbytes)
344 | {
345 |   if (gfp_array[16] == NULL) {
346 |     galois_init(16);
347 |   }
348 |   gfp_array[16]->multiply_region.w32(gfp_array[16], src, dest, 1, nbytes, 1);
349 | }
350 | 
351 | void galois_w32_region_xor(void *src, void *dest, int nbytes)
352 | {
353 |   if (gfp_array[32] == NULL) {
354 |     galois_init(32);
355 |   }
356 |   gfp_array[32]->multiply_region.w32(gfp_array[32], src, dest, 1, nbytes, 1);
357 | }
358 | 
359 | void galois_region_xor(char *src, char *dest, int nbytes)
360 | {
361 |   if (nbytes >= 16) {
362 |     galois_w32_region_xor(src, dest, nbytes);
363 |   } else {
364 |     int i = 0;
365 |     for (i = 0; i < nbytes; i++) {
366 |       *dest ^= *src;
367 |       dest++;
368 |       src++;
369 |     } 
370 |   }
371 | }
372 | 
373 | int galois_inverse(int y, int w)
374 | {
375 |   if (y == 0) return -1;
376 |   return galois_single_divide(1, y, w);
377 | }
378 | 


--------------------------------------------------------------------------------
/src/liberation.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | 
 51 | #include "galois.h"
 52 | #include "jerasure.h"
 53 | #include "liberation.h"
 54 | 
 55 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
 56 | 
 57 | int *liberation_coding_bitmatrix(int k, int w)
 58 | {
 59 |   int *matrix, i, j, index;
 60 | 
 61 |   if (k > w) return NULL;
 62 |   matrix = talloc(int, 2*k*w*w);
 63 |   if (matrix == NULL) return NULL;
 64 |   bzero(matrix, sizeof(int)*2*k*w*w);
 65 |   
 66 |   /* Set up identity matrices */
 67 | 
 68 |   for(i = 0; i < w; i++) {
 69 |     index = i*k*w+i;
 70 |     for (j = 0; j < k; j++) {
 71 |       matrix[index] = 1;
 72 |       index += w;
 73 |     }
 74 |   }
 75 | 
 76 |   /* Set up liberation matrices */
 77 | 
 78 |   for (j = 0; j < k; j++) {
 79 |     index = k*w*w+j*w;
 80 |     for (i = 0; i < w; i++) {
 81 |       matrix[index+(j+i)%w] = 1;
 82 |       index += (k*w);
 83 |     }
 84 |     if (j > 0) {
 85 |       i = (j*((w-1)/2))%w;
 86 |       matrix[k*w*w+j*w+i*k*w+(i+j-1)%w] = 1;
 87 |     }
 88 |   }
 89 |   return matrix;
 90 | }
 91 |   
 92 | 
 93 | int *liber8tion_coding_bitmatrix(int k)
 94 | {
 95 |   int *matrix, i, j, index;
 96 |   int w;
 97 | 
 98 |   w = 8;
 99 |   if (k > w) return NULL;
100 |   matrix = talloc(int, 2*k*w*w);
101 |   if (matrix == NULL) return NULL;
102 |   bzero(matrix, sizeof(int)*2*k*w*w);
103 |   
104 |   /* Set up identity matrices */
105 | 
106 |   for(i = 0; i < w; i++) {
107 |     index = i*k*w+i;
108 |     for (j = 0; j < k; j++) {
109 |       matrix[index] = 1;
110 |       index += w;
111 |     }
112 |   }
113 | 
114 |   /* Set up liber8tion matrices */
115 | 
116 |   index = k*w*w;
117 | 
118 |   if (k == 0) return matrix;
119 |   matrix[index+0*k*w+0*w+0] = 1;
120 |   matrix[index+1*k*w+0*w+1] = 1;
121 |   matrix[index+2*k*w+0*w+2] = 1;
122 |   matrix[index+3*k*w+0*w+3] = 1;
123 |   matrix[index+4*k*w+0*w+4] = 1;
124 |   matrix[index+5*k*w+0*w+5] = 1;
125 |   matrix[index+6*k*w+0*w+6] = 1;
126 |   matrix[index+7*k*w+0*w+7] = 1;
127 | 
128 |   if (k == 1) return matrix;
129 |   matrix[index+0*k*w+1*w+7] = 1;
130 |   matrix[index+1*k*w+1*w+3] = 1;
131 |   matrix[index+2*k*w+1*w+0] = 1;
132 |   matrix[index+3*k*w+1*w+2] = 1;
133 |   matrix[index+4*k*w+1*w+6] = 1;
134 |   matrix[index+5*k*w+1*w+1] = 1;
135 |   matrix[index+6*k*w+1*w+5] = 1;
136 |   matrix[index+7*k*w+1*w+4] = 1;
137 |   matrix[index+4*k*w+1*w+7] = 1;
138 | 
139 |   if (k == 2) return matrix;
140 |   matrix[index+0*k*w+2*w+6] = 1;
141 |   matrix[index+1*k*w+2*w+2] = 1;
142 |   matrix[index+2*k*w+2*w+4] = 1;
143 |   matrix[index+3*k*w+2*w+0] = 1;
144 |   matrix[index+4*k*w+2*w+7] = 1;
145 |   matrix[index+5*k*w+2*w+3] = 1;
146 |   matrix[index+6*k*w+2*w+1] = 1;
147 |   matrix[index+7*k*w+2*w+5] = 1;
148 |   matrix[index+1*k*w+2*w+3] = 1;
149 | 
150 |   if (k == 3) return matrix;
151 |   matrix[index+0*k*w+3*w+2] = 1;
152 |   matrix[index+1*k*w+3*w+5] = 1;
153 |   matrix[index+2*k*w+3*w+7] = 1;
154 |   matrix[index+3*k*w+3*w+6] = 1;
155 |   matrix[index+4*k*w+3*w+0] = 1;
156 |   matrix[index+5*k*w+3*w+3] = 1;
157 |   matrix[index+6*k*w+3*w+4] = 1;
158 |   matrix[index+7*k*w+3*w+1] = 1;
159 |   matrix[index+5*k*w+3*w+4] = 1;
160 | 
161 |   if (k == 4) return matrix;
162 |   matrix[index+0*k*w+4*w+5] = 1;
163 |   matrix[index+1*k*w+4*w+6] = 1;
164 |   matrix[index+2*k*w+4*w+1] = 1;
165 |   matrix[index+3*k*w+4*w+7] = 1;
166 |   matrix[index+4*k*w+4*w+2] = 1;
167 |   matrix[index+5*k*w+4*w+4] = 1;
168 |   matrix[index+6*k*w+4*w+3] = 1;
169 |   matrix[index+7*k*w+4*w+0] = 1;
170 |   matrix[index+2*k*w+4*w+0] = 1;
171 | 
172 |   if (k == 5) return matrix;
173 |   matrix[index+0*k*w+5*w+1] = 1;
174 |   matrix[index+1*k*w+5*w+2] = 1;
175 |   matrix[index+2*k*w+5*w+3] = 1;
176 |   matrix[index+3*k*w+5*w+4] = 1;
177 |   matrix[index+4*k*w+5*w+5] = 1;
178 |   matrix[index+5*k*w+5*w+6] = 1;
179 |   matrix[index+6*k*w+5*w+7] = 1;
180 |   matrix[index+7*k*w+5*w+0] = 1;
181 |   matrix[index+7*k*w+5*w+2] = 1;
182 | 
183 |   if (k == 6) return matrix;
184 |   matrix[index+0*k*w+6*w+3] = 1;
185 |   matrix[index+1*k*w+6*w+0] = 1;
186 |   matrix[index+2*k*w+6*w+6] = 1;
187 |   matrix[index+3*k*w+6*w+5] = 1;
188 |   matrix[index+4*k*w+6*w+1] = 1;
189 |   matrix[index+5*k*w+6*w+7] = 1;
190 |   matrix[index+6*k*w+6*w+4] = 1;
191 |   matrix[index+7*k*w+6*w+2] = 1;
192 |   matrix[index+6*k*w+6*w+5] = 1;
193 | 
194 |   if (k == 7) return matrix;
195 |   matrix[index+0*k*w+7*w+4] = 1;
196 |   matrix[index+1*k*w+7*w+7] = 1;
197 |   matrix[index+2*k*w+7*w+1] = 1;
198 |   matrix[index+3*k*w+7*w+5] = 1;
199 |   matrix[index+4*k*w+7*w+3] = 1;
200 |   matrix[index+5*k*w+7*w+2] = 1;
201 |   matrix[index+6*k*w+7*w+0] = 1;
202 |   matrix[index+7*k*w+7*w+6] = 1;
203 |   matrix[index+3*k*w+7*w+1] = 1;
204 | 
205 |   return matrix;
206 | }
207 |   
208 | int *blaum_roth_coding_bitmatrix(int k, int w)
209 | {
210 |   int *matrix, i, j, index, l, m, p;
211 | 
212 |   if (k > w) return NULL ;
213 | 
214 |   matrix = talloc(int, 2*k*w*w);
215 |   if (matrix == NULL) return NULL;
216 |   bzero(matrix, sizeof(int)*2*k*w*w);
217 |   
218 |   /* Set up identity matrices */
219 | 
220 |   for(i = 0; i < w; i++) {
221 |     index = i*k*w+i;
222 |     for (j = 0; j < k; j++) {
223 |       matrix[index] = 1;
224 |       index += w;
225 |     }
226 |   }
227 | 
228 |   /* Set up blaum_roth matrices -- Ignore identity */
229 | 
230 |   p = w+1;
231 |   for (j = 0; j < k; j++) {
232 |     index = k*w*w+j*w;
233 |     if (j == 0) {
234 |       for (l = 0; l < w; l++) {
235 |         matrix[index+l] = 1;
236 |         index += k*w;
237 |       }
238 |     } else {
239 |       i = j;
240 |       for (l = 1; l <= w; l++) {
241 |         if (l != p-i) {
242 |           m = l+i;
243 |           if (m >= p) m -= p;
244 |           m--;
245 |           matrix[index+m] = 1;
246 |         } else {
247 |           matrix[index+i-1] = 1;
248 |           if (i%2 == 0) {
249 |             m = i/2;
250 |           } else {
251 |             m = (p/2) + 1 + (i/2);
252 |           }
253 |           m--;
254 |           matrix[index+m] = 1;
255 |         }
256 |         index += k*w;
257 |       }
258 |     }
259 |   }
260 | 
261 |   return matrix;
262 | }
263 | 


--------------------------------------------------------------------------------
/src/reed_sol.c:
--------------------------------------------------------------------------------
  1 | /* *
  2 |  * Copyright (c) 2014, James S. Plank and Kevin Greenan
  3 |  * All rights reserved.
  4 |  *
  5 |  * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
  6 |  * Coding Techniques
  7 |  *
  8 |  * Revision 2.0: Galois Field backend now links to GF-Complete
  9 |  *
 10 |  * Redistribution and use in source and binary forms, with or without
 11 |  * modification, are permitted provided that the following conditions
 12 |  * are met:
 13 |  *
 14 |  *  - Redistributions of source code must retain the above copyright
 15 |  *    notice, this list of conditions and the following disclaimer.
 16 |  *
 17 |  *  - Redistributions in binary form must reproduce the above copyright
 18 |  *    notice, this list of conditions and the following disclaimer in
 19 |  *    the documentation and/or other materials provided with the
 20 |  *    distribution.
 21 |  *
 22 |  *  - Neither the name of the University of Tennessee nor the names of its
 23 |  *    contributors may be used to endorse or promote products derived
 24 |  *    from this software without specific prior written permission.
 25 |  *
 26 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 27 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 28 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 29 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 30 |  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 31 |  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 32 |  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 33 |  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 34 |  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 35 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
 36 |  * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 37 |  * POSSIBILITY OF SUCH DAMAGE.
 38 |  */
 39 | 
 40 | /* Jerasure's authors:
 41 | 
 42 |    Revision 2.x - 2014: James S. Plank and Kevin M. Greenan
 43 |    Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
 44 |    Revision 1.0 - 2007: James S. Plank
 45 |  */
 46 | 
 47 | #include 
 48 | #include 
 49 | #include 
 50 | #include 
 51 | 
 52 | #include 
 53 | #include "galois.h"
 54 | #include "jerasure.h"
 55 | #include "reed_sol.h"
 56 | 
 57 | #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
 58 | 
 59 | int *reed_sol_r6_coding_matrix(int k, int w)
 60 | {
 61 |   int *matrix;
 62 |   int i, tmp;
 63 | 
 64 |   if (w != 8 && w != 16 && w != 32) return NULL;
 65 | 
 66 |   matrix = talloc(int, 2*k);
 67 |   if (matrix == NULL) return NULL;
 68 | 
 69 |   for (i = 0; i < k; i++) matrix[i] = 1;
 70 |   matrix[k] = 1;
 71 |   tmp = 1;
 72 |   for (i = 1; i < k; i++) {
 73 |     tmp = galois_single_multiply(tmp, 2, w);
 74 |     matrix[k+i] = tmp;
 75 |   }
 76 |   return matrix;
 77 | }
 78 | 
 79 | int *reed_sol_vandermonde_coding_matrix(int k, int m, int w)
 80 | {
 81 |   int i, j;
 82 |   int *vdm, *dist;
 83 | 
 84 |   vdm = reed_sol_big_vandermonde_distribution_matrix(k+m, k, w);
 85 |   if (vdm == NULL) return NULL;
 86 |   dist = talloc(int, m*k);
 87 |   if (dist == NULL) {
 88 |     free(vdm);
 89 |     return NULL;
 90 |   }
 91 | 
 92 |   i = k*k;
 93 |   for (j = 0; j < m*k; j++) {
 94 |     dist[j] = vdm[i];
 95 |     i++;
 96 |   }
 97 |   free(vdm);
 98 |   return dist;
 99 | }
100 | 
101 | static int prim08 = -1;
102 | static gf_t GF08;
103 | 
104 | void reed_sol_galois_w08_region_multby_2(char *region, int nbytes)
105 | {
106 |   if (prim08 == -1) {
107 |     prim08 = galois_single_multiply((1 << 7), 2, 8);
108 |     if (!gf_init_hard(&GF08, 8, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
109 |                       prim08, 0, 0, NULL, NULL)) {
110 |       fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w08_region_multby_2\n");
111 |       assert(0);
112 |     }
113 |   }
114 |   GF08.multiply_region.w32(&GF08, region, region, 2, nbytes, 0);
115 | }
116 | 
117 | static int prim16 = -1;
118 | static gf_t GF16;
119 | 
120 | void reed_sol_galois_w16_region_multby_2(char *region, int nbytes)
121 | {
122 |   if (prim16 == -1) {
123 |     prim16 = galois_single_multiply((1 << 15), 2, 16);
124 |     if (!gf_init_hard(&GF16, 16, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
125 |                       prim16, 0, 0, NULL, NULL)) {
126 |       fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w16_region_multby_2\n");
127 |       assert(0);
128 |     }
129 |   }
130 |   GF16.multiply_region.w32(&GF16, region, region, 2, nbytes, 0);
131 | }
132 | 
133 | static int prim32 = -1;
134 | static gf_t GF32;
135 | 
136 | void reed_sol_galois_w32_region_multby_2(char *region, int nbytes)
137 | {
138 |   if (prim32 == -1) {
139 |     prim32 = galois_single_multiply(((gf_val_32_t)1 << 31), 2, 32);
140 |     if (!gf_init_hard(&GF32, 32, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
141 |                       prim32, 0, 0, NULL, NULL)) {
142 |       fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w32_region_multby_2\n");
143 |       assert(0);
144 |     }
145 |   }
146 |   GF32.multiply_region.w32(&GF32, region, region, 2, nbytes, 0);
147 | }
148 | 
149 | int reed_sol_r6_encode(int k, int w, char **data_ptrs, char **coding_ptrs, int size)
150 | {
151 |   int i;
152 | 
153 |   /* First, put the XOR into coding region 0 */
154 | 
155 |   memcpy(coding_ptrs[0], data_ptrs[0], size);
156 | 
157 |   for (i = 1; i < k; i++) galois_region_xor(data_ptrs[i], coding_ptrs[0], size);
158 | 
159 |   /* Next, put the sum of (2^j)*Dj into coding region 1 */
160 | 
161 |   memcpy(coding_ptrs[1], data_ptrs[k-1], size);
162 | 
163 |   for (i = k-2; i >= 0; i--) {
164 |     switch (w) {
165 |       case 8:  reed_sol_galois_w08_region_multby_2(coding_ptrs[1], size); break;
166 |       case 16: reed_sol_galois_w16_region_multby_2(coding_ptrs[1], size); break;
167 |       case 32: reed_sol_galois_w32_region_multby_2(coding_ptrs[1], size); break;
168 |       default: return 0;
169 |     }
170 | 
171 |     galois_region_xor(data_ptrs[i], coding_ptrs[1], size);
172 |   }
173 |   return 1;
174 | }
175 | 
176 | int *reed_sol_extended_vandermonde_matrix(int rows, int cols, int w)
177 | {
178 |   int *vdm;
179 |   int i, j, k;
180 | 
181 |   if (w < 30 && (1 << w) < rows) return NULL;
182 |   if (w < 30 && (1 << w) < cols) return NULL;
183 | 
184 |   vdm = talloc(int, rows*cols);
185 |   if (vdm == NULL) { return NULL; }
186 |   
187 |   vdm[0] = 1;
188 |   for (j = 1; j < cols; j++) vdm[j] = 0;
189 |   if (rows == 1) return vdm;
190 | 
191 |   i=(rows-1)*cols;
192 |   for (j = 0; j < cols-1; j++) vdm[i+j] = 0;
193 |   vdm[i+j] = 1;
194 |   if (rows == 2) return vdm;
195 | 
196 |   for (i = 1; i < rows-1; i++) {
197 |     k = 1;
198 |     for (j = 0; j < cols; j++) {
199 |       vdm[i*cols+j] = k;
200 |       k = galois_single_multiply(k, i, w);
201 |     }
202 |   }
203 |   return vdm;
204 | }
205 | 
206 | int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w)
207 | {
208 |   int *dist;
209 |   int i, j, k;
210 |   int sindex, srindex, siindex, tmp;
211 | 
212 |   if (cols >= rows) return NULL;
213 |   
214 |   dist = reed_sol_extended_vandermonde_matrix(rows, cols, w);
215 |   if (dist == NULL) return NULL;
216 | 
217 |   sindex = 0;
218 |   for (i = 1; i < cols; i++) {
219 |     sindex += cols;
220 | 
221 |     /* Find an appropriate row -- where i,i != 0 */
222 |     srindex = sindex+i;
223 |     for (j = i; j < rows && dist[srindex] == 0; j++) srindex += cols;
224 |     if (j >= rows) {   /* This should never happen if rows/w are correct */
225 |       fprintf(stderr, "reed_sol_big_vandermonde_distribution_matrix(%d,%d,%d) - couldn't make matrix\n", 
226 |              rows, cols, w);
227 |       assert(0);
228 |     }
229 |  
230 |     /* If necessary, swap rows */
231 |     if (j != i) {
232 |       srindex -= i;
233 |       for (k = 0; k < cols; k++) {
234 |         tmp = dist[srindex+k];
235 |         dist[srindex+k] = dist[sindex+k];
236 |         dist[sindex+k] = tmp;
237 |       }
238 |     }
239 |   
240 |     /* If Element i,i is not equal to 1, multiply the column by 1/i */
241 | 
242 |     if (dist[sindex+i] != 1) {
243 |       tmp = galois_single_divide(1, dist[sindex+i], w);
244 |       srindex = i;
245 |       for (j = 0; j < rows; j++) {
246 |         dist[srindex] = galois_single_multiply(tmp, dist[srindex], w);
247 |         srindex += cols;
248 |       }
249 |     }
250 |  
251 |     /* Now, for each element in row i that is not in column 1, you need
252 |        to make it zero.  Suppose that this is column j, and the element
253 |        at i,j = e.  Then you want to replace all of column j with 
254 |        (col-j + col-i*e).   Note, that in row i, col-i = 1 and col-j = e.
255 |        So (e + 1e) = 0, which is indeed what we want. */
256 | 
257 |     for (j = 0; j < cols; j++) {
258 |       tmp = dist[sindex+j];
259 |       if (j != i && tmp != 0) {
260 |         srindex = j;
261 |         siindex = i;
262 |         for (k = 0; k < rows; k++) {
263 |           dist[srindex] = dist[srindex] ^ galois_single_multiply(tmp, dist[siindex], w);
264 |           srindex += cols;
265 |           siindex += cols;
266 |         }
267 |       }
268 |     }
269 |   }
270 |   /* We desire to have row k be all ones.  To do that, multiply
271 |      the entire column j by 1/dist[k,j].  Then row j by 1/dist[j,j]. */
272 | 
273 |   sindex = cols*cols;
274 |   for (j = 0; j < cols; j++) {
275 |     tmp = dist[sindex];
276 |     if (tmp != 1) { 
277 |       tmp = galois_single_divide(1, tmp, w);
278 |       srindex = sindex;
279 |       for (i = cols; i < rows; i++) {
280 |         dist[srindex] = galois_single_multiply(tmp, dist[srindex], w);
281 |         srindex += cols;
282 |       }
283 |     }
284 |     sindex++;
285 |   }
286 | 
287 |   /* Finally, we'd like the first column of each row to be all ones.  To
288 |      do that, we multiply the row by the inverse of the first element. */
289 | 
290 |   sindex = cols*(cols+1);
291 |   for (i = cols+1; i < rows; i++) {
292 |     tmp = dist[sindex];
293 |     if (tmp != 1) { 
294 |       tmp = galois_single_divide(1, tmp, w);
295 |       for (j = 0; j < cols; j++) dist[sindex+j] = galois_single_multiply(dist[sindex+j], tmp, w);
296 |     }
297 |     sindex += cols;
298 |   }
299 | 
300 |   return dist;
301 | }
302 | 
303 | 


--------------------------------------------------------------------------------
/src/timing.c:
--------------------------------------------------------------------------------
 1 | // Timing measurement utilities implementation.
 2 | 
 3 | #include "timing.h"
 4 | #include 
 5 | 
 6 | void
 7 | timing_set(
 8 |   struct timing * t)
 9 | {
10 | #ifdef USE_CLOCK
11 |   t->clock = clock();
12 | #else
13 |   gettimeofday(&t->tv, NULL);
14 | #endif
15 | }
16 | 
17 | double
18 | timing_get(
19 |   struct timing * t)
20 | {
21 | #ifdef USE_CLOCK
22 |   // The clock_t type is an "arithmetic type", which could be
23 |   // integral, double, long double, or others.
24 |   //
25 |   // Add 0.0 to make it a double or long double, then divide (in
26 |   // double or long double), then convert to double for our purposes.
27 |   return (double) ((t->clock + 0.0) / CLOCKS_PER_SEC);
28 | #else
29 |   return (double) t->tv.tv_sec + ((double) t->tv.tv_usec) / 1000000.0;
30 | #endif
31 | }
32 | 
33 | double
34 | timing_now()
35 | {
36 | #ifdef USE_CLOCK
37 |   return (double) ((clock() + 0.0) / CLOCKS_PER_SEC);
38 | #else
39 |   struct timeval tv;
40 |   gettimeofday(&tv, NULL);
41 |   return (double) tv.tv_sec + ((double) tv.tv_usec) / 1000000.0;
42 | #endif
43 | }
44 | 
45 | double
46 | timing_delta(
47 |   struct timing * t1,
48 |   struct timing * t2)
49 | {
50 | #ifdef USE_CLOCK
51 |   // The clock_t type is an "arithmetic type", which could be
52 |   // integral, double, long double, or others.
53 |   //
54 |   // Subtract first, resulting in another clock_t, then add 0.0 to
55 |   // make it a double or long double, then divide (in double or long
56 |   // double), then convert to double for our purposes.
57 |   return (double) (((t2->clock - t1->clock) + 0.0) / CLOCKS_PER_SEC);
58 | #else
59 |   double const d2 = (double) t2->tv.tv_sec + ((double) t2->tv.tv_usec) / 1000000.0;
60 |   double const d1 = (double) t1->tv.tv_sec + ((double) t1->tv.tv_usec) / 1000000.0;
61 |   return d2 - d1;
62 | #endif
63 | }
64 | 


--------------------------------------------------------------------------------