[154] | 1 | // Frequent (>1000) failure cause for different categories of events grouped by duration (short, medium, long) |
---|
| 2 | |
---|
| 3 | #include <stdio.h> |
---|
| 4 | #include <stdlib.h> |
---|
| 5 | #include <string.h> |
---|
| 6 | #include "mpi.h" |
---|
| 7 | |
---|
| 8 | #define CHUNK 20480 |
---|
| 9 | #define ENCODED_NO 33 |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | unsigned long* poz; |
---|
| 13 | unsigned long recv[2]; |
---|
| 14 | unsigned long poz_size = 0; |
---|
| 15 | unsigned long recv_m[ENCODED_NO]; |
---|
| 16 | unsigned long send_m[ENCODED_NO]; |
---|
| 17 | |
---|
| 18 | int failure_key[] = {-1, 0, 999, 1999, 2999, 3999, 4999, 5999, 6999, 7000, 7001}; |
---|
| 19 | char* failure_value[] = {"not reported", "reported as undetermined", "infrastructure", "hardware", "IO", "network", "software", "human error", |
---|
| 20 | "user", "end of measurement", "TYPING"}; |
---|
| 21 | long duration_key[] = {1000, 100000, 2147483647}; |
---|
| 22 | char* duration_value[] = {"short", "medium", "long"}; |
---|
| 23 | char* encoded_values[] = {"short-not reported", "medium-not reported", "long-not reported", "short-reported as undetermined", |
---|
| 24 | "medium-reported as undetermined", "long-reported as undetermined", "short-infrastructure", "medium-infrastructure", |
---|
| 25 | "long-infrastructure", "short-hardware", "medium-hardware", "long-hardware", "short-IO", "medium-IO", "long-IO", "short-network", |
---|
| 26 | "medium-network", "long-network", "short-software", "medium-software", "long-software", "short-human error", |
---|
| 27 | "medium-human error", "long-human error", "short-user", "medium-user", "long-user", "short-end of measurement", |
---|
| 28 | "medium-end of measurement", "long-end of measurement", "short-TYPING", "medium-TYPING", "long-TYPING"}; |
---|
| 29 | |
---|
| 30 | unsigned long file_length(FILE *f) { |
---|
| 31 | long pos; |
---|
| 32 | long end; |
---|
| 33 | |
---|
| 34 | pos = ftell (f); |
---|
| 35 | fseek (f, 0, SEEK_END); |
---|
| 36 | end = ftell (f); |
---|
| 37 | fseek (f, pos, SEEK_SET); |
---|
| 38 | |
---|
| 39 | return end; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | void write_result (char *filename) { |
---|
| 44 | FILE *f; |
---|
| 45 | int i; |
---|
| 46 | |
---|
| 47 | f = fopen(filename, "wt"); |
---|
| 48 | if (f == NULL) { |
---|
| 49 | fprintf(stderr, "Could not open file write.\n"); |
---|
| 50 | MPI_Abort(MPI_COMM_WORLD, 7777); |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | for(i = 0 ; i < ENCODED_NO ; i++) { |
---|
| 54 | fprintf(f, "%-40s", encoded_values[i]); |
---|
| 55 | fprintf(f, "%i\n", recv_m[i]); |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | int init(char *filename) { |
---|
| 60 | unsigned long file_len = 0; |
---|
| 61 | unsigned long i, j; |
---|
| 62 | FILE *f; |
---|
| 63 | size_t read = 0; |
---|
| 64 | |
---|
| 65 | f = fopen(filename, "rt"); |
---|
| 66 | if (f == NULL) { |
---|
| 67 | fprintf(stderr, "Could not open file init.\n"); |
---|
| 68 | MPI_Abort(MPI_COMM_WORLD, 7777); |
---|
| 69 | } |
---|
| 70 | file_len = file_length(f); |
---|
| 71 | poz_size = file_len / CHUNK + 1; |
---|
| 72 | |
---|
| 73 | poz = (unsigned long*) malloc(poz_size * sizeof(unsigned long)); |
---|
| 74 | poz[0] = 0; |
---|
| 75 | for (i = CHUNK, j = 1; j < poz_size - 1; i += CHUNK, j++) { |
---|
| 76 | poz[j] = i; |
---|
| 77 | } |
---|
| 78 | poz[j] = file_len; |
---|
| 79 | |
---|
| 80 | return 1; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | int main(int argc, char** argv) { |
---|
| 84 | |
---|
| 85 | int rank, size; |
---|
| 86 | MPI_Status status; |
---|
| 87 | MPI_Request request; |
---|
| 88 | int i, flag, j; |
---|
| 89 | |
---|
| 90 | MPI_Init(&argc, &argv); |
---|
| 91 | MPI_Comm_rank(MPI_COMM_WORLD, &rank); |
---|
| 92 | MPI_Comm_size(MPI_COMM_WORLD, &size); |
---|
| 93 | |
---|
| 94 | if (rank == 0) { |
---|
| 95 | // master inits |
---|
| 96 | init(argv[1]); |
---|
| 97 | } |
---|
| 98 | MPI_Barrier(MPI_COMM_WORLD); |
---|
| 99 | |
---|
| 100 | // master sends indexes, receives results |
---|
| 101 | if(rank == 0) { |
---|
| 102 | |
---|
| 103 | for(i = 0 ; i < ENCODED_NO ; i++) { |
---|
| 104 | recv_m[i] = 0; |
---|
| 105 | send_m[i] = 0; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | // sends indexes |
---|
| 109 | for (i = 0; i < poz_size - 1; i++) { |
---|
| 110 | MPI_Isend(poz+i, 2, MPI_UNSIGNED_LONG, i%(size-1)+1, 0, MPI_COMM_WORLD, &request); |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | // receive results |
---|
| 114 | unsigned long recv_temp[ENCODED_NO]; |
---|
| 115 | while(1) { |
---|
| 116 | |
---|
| 117 | for(i = 0 ; i < ENCODED_NO ; i++) |
---|
| 118 | recv_temp[i] = 0; |
---|
| 119 | MPI_Irecv(recv_temp, ENCODED_NO, MPI_UNSIGNED_LONG, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &request); |
---|
| 120 | |
---|
| 121 | MPI_Test(&request, &flag, &status); |
---|
| 122 | int times = 0; |
---|
| 123 | while(!flag && times < 10) { |
---|
| 124 | times++; |
---|
| 125 | sleep(1); |
---|
| 126 | MPI_Test(&request, &flag, &status); |
---|
| 127 | } |
---|
| 128 | if(!flag) |
---|
| 129 | break; |
---|
| 130 | |
---|
| 131 | for(i = 0 ; i < ENCODED_NO ; i++) { |
---|
| 132 | recv_m[i] += recv_temp[i]; |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | // write results |
---|
| 137 | write_result(argv[2]); |
---|
| 138 | free(poz); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | // slaves receive indexes, do computation |
---|
| 142 | else { |
---|
| 143 | while(1) { |
---|
| 144 | |
---|
| 145 | // receive until there's nothing left |
---|
| 146 | MPI_Irecv(recv, 2, MPI_UNSIGNED_LONG, 0, 0, MPI_COMM_WORLD, &request); |
---|
| 147 | |
---|
| 148 | MPI_Test(&request, &flag, &status); |
---|
| 149 | int times = 0; |
---|
| 150 | while(!flag && times < 10) { |
---|
| 151 | times++; |
---|
| 152 | sleep(1); |
---|
| 153 | MPI_Test(&request, &flag, &status); |
---|
| 154 | } |
---|
| 155 | if(!flag) |
---|
| 156 | break; |
---|
| 157 | |
---|
| 158 | // read file and do computation |
---|
| 159 | FILE *f; |
---|
| 160 | |
---|
| 161 | f = fopen(argv[1], "rt"); |
---|
| 162 | if (f == NULL) { |
---|
| 163 | fprintf(stderr, "Could not open file.\n"); |
---|
| 164 | MPI_Abort(MPI_COMM_WORLD, 7777); |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | fseek (f, recv[0], SEEK_SET); |
---|
| 168 | |
---|
| 169 | // go to the end of the line |
---|
| 170 | char * line = NULL; |
---|
| 171 | size_t len = 0; |
---|
| 172 | ssize_t read; |
---|
| 173 | unsigned long count = 0; |
---|
| 174 | |
---|
| 175 | for(i = 0 ; i < ENCODED_NO ; i++) { |
---|
| 176 | send_m[i] = 0; |
---|
| 177 | recv_m[i] = 0; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | while ((read = getline(&line, &len, f)) != -1) { |
---|
| 181 | |
---|
| 182 | // skip the comment line and the half lines |
---|
| 183 | count++; |
---|
| 184 | if(count == 1) |
---|
| 185 | continue; |
---|
| 186 | |
---|
| 187 | // compute |
---|
| 188 | char response; |
---|
| 189 | |
---|
| 190 | double start, end, duration; |
---|
| 191 | int fault = -2; |
---|
| 192 | char delims[] = " "; |
---|
| 193 | char *result = NULL; |
---|
| 194 | result = strtok( line, delims ); |
---|
| 195 | int token_no = 0; |
---|
| 196 | while( result != NULL ) { |
---|
| 197 | token_no++; |
---|
| 198 | if(token_no == 7) { |
---|
| 199 | start = atof(result); |
---|
| 200 | } |
---|
| 201 | if(token_no == 8) { |
---|
| 202 | end = atof(result); |
---|
| 203 | } |
---|
| 204 | if(token_no == 9) { |
---|
| 205 | if(strncmp(result, "NULL", 4) == 0) |
---|
| 206 | fault = -1; |
---|
| 207 | else |
---|
| 208 | fault = atoi(result); |
---|
| 209 | } |
---|
| 210 | result = strtok( NULL, delims ); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | int tag = 0; |
---|
| 214 | |
---|
| 215 | if(fault > failure_key[10]) { |
---|
| 216 | // detect typing fault |
---|
| 217 | fault = 7001; |
---|
| 218 | } |
---|
| 219 | for(i = 0 ; i < 11 ; i++) { |
---|
| 220 | if(fault <= failure_key[i]) { |
---|
| 221 | tag = i * 3; |
---|
| 222 | break; |
---|
| 223 | } |
---|
| 224 | } |
---|
| 225 | |
---|
| 226 | duration = end - start; |
---|
| 227 | for(i = 0 ; i < 3 ; i++) { |
---|
| 228 | if(duration <= duration_key[i]) { |
---|
| 229 | tag += i; |
---|
| 230 | break; |
---|
| 231 | } |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | send_m[tag]++; |
---|
| 235 | |
---|
| 236 | // finished reading chunk? |
---|
| 237 | if(ftell(f) > recv[1]) |
---|
| 238 | break; |
---|
| 239 | |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | // send result to master |
---|
| 243 | MPI_Isend(send_m, ENCODED_NO, MPI_UNSIGNED_LONG, 0, 0, MPI_COMM_WORLD, &request); |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | // block and finish |
---|
| 248 | MPI_Barrier(MPI_COMM_WORLD); |
---|
| 249 | MPI_Finalize(); |
---|
| 250 | } |
---|
| 251 | |
---|