#include <iostream> #include <string> #include <cctype> #include "message.h" #include "poszukiwania.h" #ifdef __DEB #include <fstream> #include <cstdio> #endif using namespace std; #define MAX_HASHE 10000 //maksymalna długość hashy, bo to potem trzeba przesłać dalej #define MAX_WZOR 30 //maksymalna długość wzorca przypadająca na jeden komputer poniżej której liczymy lokalnie #define MAX_PRZESUNIECIE 10000000000 //maksymalna ilość przesunięć aby dość do końca poniżej której liczymy tę część lokalnie int main() { int ilosc_procesow = NumberOfNodes(); uint64_t *hashe; //uint64_t &hash[][7] = (uint64_t)hashe; uint64_t hash[ilosc_procesow][7]; uint64_t dl_sekw = SeqLength(); uint64_t dl_wzorca = SignalLength(); //przy tak małej ilości pamięci (całe 128MB teoretycznie na instancje), //gdzie nie mieści się ani wzorzec ani sekwencja maksymalna w pamięci //opracowywanie jakiegoś KMP czy coś to szkoda czasu //bo nie dość, że trzeba optymalizować do równoległości //to jeszcze ograniczenia pamięci, ograniczenia ilości wysyłanych komunikatów //ogólnie dużo za dużo ograniczeń jak na coś co szybko da się napisać /* Przyjęto więc przeszukiwanie Karpa-Rabina ale bez końcowego sprawdzania czy przypadkiem hash się nie nakłada na inną kombinację. Zamiast tego zastosowano na wszelki wypadek 6 hashy których zadaniem jest teoretyczne polepszenie wyszukiwania Ponieważ O(n+m) bez końcowego sprawdzania to trzeba wziąć pod uwagę 4 przypadki mały wzorzec i mała sekwencja mały wzorzec i duża sekwencja duża sekwencja i mały wzorzec duża sekwencja i duzy wzorzec to co występuje duże to dzielimy na komputery to co występuje małe robimy na jednym komputerze (lub wszystkich to samo dla małego wzorca) najgorzej jest oczywiście z dużą sekwencja i wzorcem, bo trzeba jedno i drugie zrobić rozproszone */ int nasz_proces = MyNodeId(); //dl_wzorca = 1793; #ifdef __DEB char nazwa_pliku[20]; sprintf(nazwa_pliku, "deb_%d.txt", nasz_proces); std::ofstream deb (nazwa_pliku, std::ofstream::out); #endif /* uint64_t tab[] = { 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL, 1073741827LL, };*/ uint64_t hash1 = 0; uint64_t hash2 = 0; uint64_t hash3 = 0; uint64_t hash4 = 0; uint64_t hash5 = 0; uint64_t hash6 = 0; uint64_t hashsek1 = 0; uint64_t hashsek2 = 0; uint64_t hashsek3 = 0; uint64_t hashsek4 = 0; uint64_t hashsek5 = 0; uint64_t hashsek6 = 0; uint64_t hbp3 = 1, hbp5 = 1, hbp6 = 1; uint64_t hbe = 0; /*int a = 1; while(a <= dl_wzorca) { deb << SeqAt(a) ; a++; } deb <<endl; a = 1; while(a <= dl_sekw) { deb << SignalAt(a) ; a++; } deb <<endl;*/ int obcehashe = 0; /*4 29999994 1621159664 32212248367549038 288236599 1431849023 4 29999994 1621159664 32212248367549038 288236599 1431849023*/ uint64_t ild = 1;// mnożnik "liczby procesow", bo to za cholere nie da się wysłać 1/100 wzorca //jak będzie max, więc trzeba jeszcze ekstra podzielić na mniejsze wzorce jak zajdzie potrzeba if ((dl_wzorca/ilosc_procesow) > MAX_WZOR) { obcehashe = 1; uint64_t dlugosc_hasha = dl_wzorca/ilosc_procesow; if (dlugosc_hasha > MAX_HASHE) { //hashy będzie za duzo żeby je wysłać //więc trzeba będzie je jeszcze bardziej podzielić ild = (dlugosc_hasha/MAX_HASHE+1); } uint64_t _ilosc_procesow = ilosc_procesow * ild; hashe = new uint64_t[_ilosc_procesow*7]; uint64_t _nasz_proces = nasz_proces * ild; uint64_t _ild = ild; while(_ild--) { uint64_t a = (dl_wzorca) * _nasz_proces / _ilosc_procesow; uint64_t b = (dl_wzorca) * (_nasz_proces+1) / _ilosc_procesow -1; #ifdef __DEB2 deb << "EXTRA " << a << " " << b << endl; #endif uint64_t h1 = 0; uint64_t h2 = 0; uint64_t h3 = 0; uint64_t h4 = 0; uint64_t h5 = 0; uint64_t h6 = 0; uint64_t i = a+1; b++; while(i <= b) { uint64_t tmp = SignalAt(i); h1 ^= tmp; h2 += tmp; h3 = (h3 * 1073741789LL % 2147483587LL +tmp% 2147483587LL ) % 2147483587LL; h4 += tmp * 1073741827LL;// % 9007199254740997LL; h5 = (h5 * 2017413581LL % 2117413583LL+tmp% 2117413583LL) % 2117413583LL; h6 = (h6 * 1073741827LL % 2147483629LL+tmp% 2147483629LL) % 2147483629LL; i++; } hashe[_nasz_proces*7+0] = h1; hashe[_nasz_proces*7+1] = h2; hashe[_nasz_proces*7+2] = h3; hashe[_nasz_proces*7+3] = h4; hashe[_nasz_proces*7+4] = h5; hashe[_nasz_proces*7+5] = h6; hashe[_nasz_proces*7+6] = b-a; hbp3 = 1; hbp5 = 1; hbp6 = 1; uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; for(uint64_t x=1; x<=dl_wzorca-b; x<<=1) { if ((dl_wzorca-b) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; //deb << "&" << hbp3 << endl; } h3 = h3 * hbp3 % 2147483587LL;// +tmp% 2147483587LL ) % 2147483587LL; h5 = h5 * hbp5 % 2117413583LL;//+tmp% 2117413583LL) % 2117413583LL; h6 = h6 * hbp6 % 2147483629LL;//+tmp% 2147483629LL) % 2147483629LL; hash1 ^= h1; hash2 += h2; hash3 += h3; hash3 %= 2147483587LL; hash4 += h4; hash5 += h5; hash5 %= 2117413583LL; hash6 += h6; hash6 %= 2147483629LL; _nasz_proces++; } /* uint64_t a = dl_wzorca * nasz_proces / ilosc_procesow; uint64_t b = dl_wzorca * (nasz_proces+1) / ilosc_procesow -1; #ifdef __DEB deb << a << " " << b << endl; #endif uint64_t i = a+1; b++; while(i <= b) { uint64_t tmp = SignalAt(i); hash1 ^= tmp; hash2 += tmp; hash3 = (hash3 * 1073741789LL % 2147483587LL +tmp% 2147483587LL ) % 2147483587LL; hash4 += tmp * 1073741827LL;// % 9007199254740997LL; hash5 = (hash5 * 2017413581LL % 2117413583LL+tmp% 2117413583LL) % 2117413583LL; hash6 = (hash6 * 1073741827LL % 2147483629LL+tmp% 2147483629LL) % 2147483629LL; i++; } #ifdef __DEB deb << "H1: " << hash1 << endl; deb << "H2: " << hash2 << endl; deb << "H3: " << hash3 << endl; deb << "H4: " << hash4 << endl; deb << "H5: " << hash5 << endl; deb << "H6: " << hash6 << endl; #endif hash[nasz_proces][0] = hash1; hash[nasz_proces][1] = hash2; hash[nasz_proces][2] = hash3; hash[nasz_proces][3] = hash4; hash[nasz_proces][4] = hash5; hash[nasz_proces][5] = hash6; hash[nasz_proces][6] = b-a+1; uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; for(uint64_t x=1; x<=dl_wzorca-b; x<<=1) { if ((dl_wzorca-b) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; //deb << "&" << hbp3 << endl; } hash3 = hash3 * hbp3 % 2147483587LL;// +tmp% 2147483587LL ) % 2147483587LL; hash5 = hash5 * hbp5 % 2117413583LL;//+tmp% 2117413583LL) % 2117413583LL; hash6 = hash6 * hbp6 % 2147483629LL;//+tmp% 2147483629LL) % 2147483629LL; */ int i = 0; while(i < ilosc_procesow) { if (i != nasz_proces) { PutLL(i, hash1); PutLL(i, hash2); PutLL(i, hash3); PutLL(i, hash4); PutLL(i, hash5); PutLL(i, hash6); uint64_t przeznaczenie = nasz_proces * ild; uint64_t _ild = ild; while(_ild--) { // if (!nasz_proces)cerr << hashe[przeznaczenie*7+0] << endl; PutLL(i, hashe[przeznaczenie*7+0]); PutLL(i, hashe[przeznaczenie*7+1]); PutLL(i, hashe[przeznaczenie*7+2]); PutLL(i, hashe[przeznaczenie*7+3]); PutLL(i, hashe[przeznaczenie*7+4]); PutLL(i, hashe[przeznaczenie*7+5]); PutLL(i, hashe[przeznaczenie*7+6]); przeznaczenie++; } Send(i); } i++; } // cerr << "NADANE"; i = 0; while(i < ilosc_procesow) { if (i != nasz_proces) { Receive(i); uint64_t h1 = GetLL(i); uint64_t h2 = GetLL(i); uint64_t h3 = GetLL(i); uint64_t h4 = GetLL(i); uint64_t h5 = GetLL(i); uint64_t h6 = GetLL(i); hash1 ^= h1; hash2 += h2; hash3 += h3; hash3 %= 2147483587LL; hash4 += h4; hash5 += h5; hash5 %= 2117413583LL; hash6 += h6; hash6 %= 2147483629LL; uint64_t przeznaczenie = i * ild; uint64_t _ild = ild; while(_ild--) { hashe[przeznaczenie*7+0] = GetLL(i); hashe[przeznaczenie*7+1] = GetLL(i); hashe[przeznaczenie*7+2] = GetLL(i); hashe[przeznaczenie*7+3] = GetLL(i); hashe[przeznaczenie*7+4] = GetLL(i); hashe[przeznaczenie*7+5] = GetLL(i); hashe[przeznaczenie*7+6] = GetLL(i); przeznaczenie++; } } i++; } //wysyłamy do każdego nasze hashe //i odbieramy od każdego hashe /*deb << "%" << hbp3 << endl; deb << "%" << hbp5 << endl; deb << "%" << hbp6 << endl;*/ /* i--; nasz_proces++; hash1a ^= hash1; hash2a += hash2; hash3a += hash3; hash4a += hash4; hash5a += hash5; hash6a += hash6;*/ //} //uint64_t tmp = SignalAt(0); //hash4 = hash3 - tmp * 144115188075855881LL % 9007199254740997LL; /* #ifdef __DEB deb << hash1a << endl; deb << hash2a << endl; deb << hash3a << endl; deb << hash4a << endl; deb << hash5a << endl; deb << hash6a << endl << endl; #endif */ #ifdef __DEB /* * * 4 29999994 1621159664 32212248367549038 288236599 1431849023 4 29999994 1621159664 32212248367549038 288236599 1431849023 * */ #endif } else { //sami liczymy hashe, bo nie ma co równoleglić //uint64_t a = dl_wzorca * nasz_proces / ilosc_procesow; // uint64_t b = dl_wzorca * (nasz_proces+1) / ilosc_procesow -1; #ifdef __DEB deb << "JEDEN" << endl; #endif //nasz_proces++; //} // hbe = 1; uint64_t i =0; while(i < dl_wzorca) { uint64_t tmp = SignalAt(i+1); hash1 ^= tmp; hash2 += tmp; hash3 = (hash3 * 1073741789LL % 2147483587LL +tmp% 2147483587LL ) % 2147483587LL; hash4 += tmp * 1073741827LL;// % 9007199254740997LL; hash5 = (hash5 * 2017413581LL % 2117413583LL+tmp% 2117413583LL) % 2117413583LL; hash6 = (hash6 * 1073741827LL % 2147483629LL+tmp% 2147483629LL) % 2147483629LL; i++; } uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; for(uint64_t x=1; x<=dl_wzorca-1; x<<=1) { if ((dl_wzorca-1) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; //deb << "&" << hbp3 << endl; } } #ifdef __DEB2 if (obcehashe) { int i = 0; while(i < ilosc_procesow*ild) { deb << "H["<<i<<"][0]: " << hashe[i*7+0] << endl; deb << "H["<<i<<"][1]: " << hashe[i*7+1] << endl; deb << "H["<<i<<"][2]: " << hashe[i*7+2] << endl; deb << "H["<<i<<"][3]: " << hashe[i*7+3] << endl; deb << "H["<<i<<"][4]: " << hashe[i*7+4] << endl; deb << "H["<<i<<"][5]: " << hashe[i*7+5] << endl; deb << "H["<<i<<"][6] dlugosc: " << hashe[i*7+6] << endl; i++; } } #endif // deb << "&" << hbp3 << endl; //deb << "&" << hbp5 << endl; //deb << "&" << hbp6 << endl; uint64_t p = 0; if (((dl_sekw-dl_wzorca)/ilosc_procesow) > MAX_PRZESUNIECIE) { //długi wzorzec //uint64_t a = dl_wzorca * nasz_proces / ilosc_procesow; //uint64_t b = dl_wzorca * (nasz_proces+1) / ilosc_procesow -1; int dlugosc_hasha = hashe[6]; int i = 1; while(i < ilosc_procesow*ild) { if (dlugosc_hasha < hashe[i*7+6]) { dlugosc_hasha = hashe[i*7+6]; } i++; } #ifdef __DEB deb << "Hash max " << dlugosc_hasha << endl; #endif int64_t a = (dl_sekw-dlugosc_hasha) * nasz_proces / ilosc_procesow; int64_t b = (dl_sekw-dlugosc_hasha) * (nasz_proces+1) / ilosc_procesow-1 + dlugosc_hasha; #ifdef __DEB deb << "SZUKANIE " << a << " " << b << endl; #endif } else { //obcehashe = 0; //wiele nie ma do przeszukiwania if (obcehashe) { //ale hash był długi więc musimy go jeszcze policzyć takze we wzorcu zanim przeszukiwanie rozpoczniemy uint64_t a = (dl_wzorca-1) * nasz_proces / ilosc_procesow; uint64_t b = (dl_wzorca-1) * (nasz_proces+1) / ilosc_procesow -1; // if (b == dl_wzorca-1)b--; #ifdef __DEB deb << " ** " << a << " " << b << endl; #endif uint64_t i = a+1; b++; while(i <= b) { uint64_t tmp = SignalAt(i); hashsek1 ^= tmp; hashsek2 += tmp; hashsek3 = (hashsek3 * 1073741789LL % 2147483587LL +tmp% 2147483587LL ) % 2147483587LL; hashsek4 += tmp * 1073741827LL;// % 9007199254740997LL; hashsek5 = (hashsek5 * 2017413581LL % 2117413583LL+tmp% 2117413583LL) % 2117413583LL; hashsek6 = (hashsek6 * 1073741827LL % 2147483629LL+tmp% 2147483629LL) % 2147483629LL; i++; } uint64_t hbp3 = 1, hbp5 = 1, hbp6 = 1; uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; // b--; for(uint64_t x=1; x<=dl_wzorca-b-1; x<<=1) { if ((dl_wzorca-b-1) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; //deb << "&" << hbp3 << endl; } hashsek3 = hashsek3 * hbp3 % 2147483587LL;// +tmp% 2147483587LL ) % 2147483587LL; hashsek5 = hashsek5 * hbp5 % 2117413583LL;//+tmp% 2117413583LL) % 2117413583LL; hashsek6 = hashsek6 * hbp6 % 2147483629LL;//+tmp% 2147483629LL) % 2147483629LL; /* deb << hashsek1 << endl; deb << hashsek2 << endl; deb << hashsek3 << endl; deb << hashsek4 << endl; deb << hashsek5 << endl; deb << hashsek6 << endl << endl;*/ i = 0; while(i < ilosc_procesow) { if (i != nasz_proces) { PutLL(i, hashsek1); PutLL(i, hashsek2); PutLL(i, hashsek3); PutLL(i, hashsek4); PutLL(i, hashsek5); PutLL(i, hashsek6); Send(i); } i++; } i = 0; while(i < ilosc_procesow) { if (i != nasz_proces) { Receive(i); uint64_t h1 = GetLL(i); uint64_t h2 = GetLL(i); uint64_t h3 = GetLL(i); uint64_t h4 = GetLL(i); uint64_t h5 = GetLL(i); uint64_t h6 = GetLL(i); hashsek1 ^= h1; hashsek2 += h2; hashsek3 += h3; hashsek3 %= 2147483587LL; hashsek4 += h4; hashsek5 += h5; hashsek5 %= 2117413583LL; hashsek6 += h6; hashsek6 %= 2147483629LL; } i++; } } if (!nasz_proces) { #ifdef __DEB deb << "JEDEN"<<endl; #endif uint64_t i = 0; if (!obcehashe) { while(i < dl_wzorca-1) { uint64_t tmp2 = SeqAt(i+1); hashsek1 ^= tmp2; hashsek2 += tmp2; hashsek3 = (hashsek3 * 1073741789LL % 2147483587LL +tmp2% 2147483587LL ) % 2147483587LL; hashsek4 += tmp2 * 1073741827LL;// % 9007199254740997LL; hashsek5 = (hashsek5 * 2017413581LL % 2117413583LL+tmp2% 2117413583LL) % 2117413583LL; hashsek6 = (hashsek6 * 1073741827LL % 2147483629LL+tmp2 % 2147483629LL) % 2147483629LL; i++; } //deb << "&" << hbp3 << endl; } else { hbp3 = 1; hbp5 = 1; hbp6 = 1; uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; for(uint64_t x=1; x<=dl_wzorca-1; x<<=1) { if ((dl_wzorca-1) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; } i = dl_wzorca - 1; } // 4057608999 222781835 poprawny // 1917413584 222781835 // 315378610023172087 /* deb << "EXTRA HASH 1" << endl << hashsek1 << endl; deb << hashsek2 << endl; deb << hashsek3 << endl; deb << hashsek4 << endl; deb << hashsek5 << endl; deb << hashsek6 << endl << endl; */ //wstępne hashe policzone p = 0; uint64_t j = 0; while(i < dl_sekw) { uint64_t tmp2 = SeqAt(i+1); hashsek1 ^= tmp2; hashsek2 += tmp2; hashsek3 = (hashsek3 * 1073741789LL % 2147483587LL +tmp2 % 2147483587LL ) % 2147483587LL; hashsek4 += tmp2 * 1073741827LL;// % 9007199254740997LL; hashsek5 = (hashsek5 * 2017413581LL % 2117413583LL+tmp2% 2117413583LL) % 2117413583LL; hashsek6 = (hashsek6 * 1073741827LL % 2147483629LL+tmp2 % 2147483629LL) % 2147483629LL; //hashsek6 += (tmp2 ^ 0xAA55A55AFF1312) * 1073741827LL ; /* deb << "EXTRA HASH 2" << endl << hashsek1 << endl; deb << hashsek2 << endl; deb << hashsek3 << endl; deb << hashsek4 << endl; deb << hashsek5 << endl; deb << hashsek6 << endl << endl; if (j > 20) break; */ if(hashsek6 == hash6) if(hashsek5 == hash5) if(hashsek4 == hash4) if(hashsek3 == hash3) if(hashsek2 == hash2) if(hashsek1 == hash1) { // deb << "*" << j << " " << SeqAt(j) << " " << SeqAt(j+1) << " " << SeqAt(j+2) <<endl; p++; } tmp2 = SeqAt(j+1); hashsek1 ^= tmp2; hashsek2 -= tmp2; hashsek4 -= tmp2 * 1073741827LL;// % 9007199254740997LL; int64_t x = ((int64_t)hashsek6- ((int64_t)tmp2 % 2147483629LL) * (int64_t)hbp6) % 2147483629LL; if (x<0) x+=2147483629LL; hashsek6 = x;//(hashsek6 ) % 2147483629LL;// * 1073741827LL % 2147483629LL+tmp) % 2147483629LL; x = ((int64_t)hashsek3 - ((int64_t)tmp2 % 2147483587LL) * (int64_t)hbp3) % 2147483587LL; if (x<0) x+=2147483587LL; hashsek3 = x;//(hashsek3 * 1073741789LL % 2147483587LL +tmp2 ) % 2147483587LL; x = ((int64_t)hashsek5 - ((int64_t)tmp2 % 2117413583LL) * (int64_t)hbp5) % 2117413583LL; if (x<0) x+=2117413583LL; hashsek5 = x;//(hashsek3 * 1073741789LL % 2147483587LL +tmp2 ) % 2147483587LL; // deb << "**" << hashsek3 << endl << endl; // hashsek6 -= tmp2 * tab[j%13]; //hashsek6 -= (tmp2 ^ 0xAA55A55AFF1312) * 1073741827LL ; i++; j++; } cout << p<<endl; } } /* 4 29999994 1621159664 32212248367549038 288236599 1431849023 1292250785 67909 948363714 4 29999994 1621159664 32212248367549038 288236599 1431849023 1292250785 67909 948363714 */ #ifdef __DEB deb << hash1 << endl; deb << hash2 << endl; deb << hash3 << endl; deb << hash4 << endl; deb << hash5 << endl; deb << hash6 << endl << endl; deb << hbp3 << endl; deb << hbp5 << endl; deb << hbp6 << endl << endl; deb << hashsek1 << endl; deb << hashsek2 << endl; deb << hashsek3 << endl; deb << hashsek4 << endl; deb << hashsek5 << endl; deb << hashsek6 << endl << endl; #endif //cout << p << endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | #include <iostream> #include <string> #include <cctype> #include "message.h" #include "poszukiwania.h" #ifdef __DEB #include <fstream> #include <cstdio> #endif using namespace std; #define MAX_HASHE 10000 //maksymalna długość hashy, bo to potem trzeba przesłać dalej #define MAX_WZOR 30 //maksymalna długość wzorca przypadająca na jeden komputer poniżej której liczymy lokalnie #define MAX_PRZESUNIECIE 10000000000 //maksymalna ilość przesunięć aby dość do końca poniżej której liczymy tę część lokalnie int main() { int ilosc_procesow = NumberOfNodes(); uint64_t *hashe; //uint64_t &hash[][7] = (uint64_t)hashe; uint64_t hash[ilosc_procesow][7]; uint64_t dl_sekw = SeqLength(); uint64_t dl_wzorca = SignalLength(); //przy tak małej ilości pamięci (całe 128MB teoretycznie na instancje), //gdzie nie mieści się ani wzorzec ani sekwencja maksymalna w pamięci //opracowywanie jakiegoś KMP czy coś to szkoda czasu //bo nie dość, że trzeba optymalizować do równoległości //to jeszcze ograniczenia pamięci, ograniczenia ilości wysyłanych komunikatów //ogólnie dużo za dużo ograniczeń jak na coś co szybko da się napisać /* Przyjęto więc przeszukiwanie Karpa-Rabina ale bez końcowego sprawdzania czy przypadkiem hash się nie nakłada na inną kombinację. Zamiast tego zastosowano na wszelki wypadek 6 hashy których zadaniem jest teoretyczne polepszenie wyszukiwania Ponieważ O(n+m) bez końcowego sprawdzania to trzeba wziąć pod uwagę 4 przypadki mały wzorzec i mała sekwencja mały wzorzec i duża sekwencja duża sekwencja i mały wzorzec duża sekwencja i duzy wzorzec to co występuje duże to dzielimy na komputery to co występuje małe robimy na jednym komputerze (lub wszystkich to samo dla małego wzorca) najgorzej jest oczywiście z dużą sekwencja i wzorcem, bo trzeba jedno i drugie zrobić rozproszone */ int nasz_proces = MyNodeId(); //dl_wzorca = 1793; #ifdef __DEB char nazwa_pliku[20]; sprintf(nazwa_pliku, "deb_%d.txt", nasz_proces); std::ofstream deb (nazwa_pliku, std::ofstream::out); #endif /* uint64_t tab[] = { 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL*1073741827LL, 1073741827LL*1073741827LL, 1073741827LL, };*/ uint64_t hash1 = 0; uint64_t hash2 = 0; uint64_t hash3 = 0; uint64_t hash4 = 0; uint64_t hash5 = 0; uint64_t hash6 = 0; uint64_t hashsek1 = 0; uint64_t hashsek2 = 0; uint64_t hashsek3 = 0; uint64_t hashsek4 = 0; uint64_t hashsek5 = 0; uint64_t hashsek6 = 0; uint64_t hbp3 = 1, hbp5 = 1, hbp6 = 1; uint64_t hbe = 0; /*int a = 1; while(a <= dl_wzorca) { deb << SeqAt(a) ; a++; } deb <<endl; a = 1; while(a <= dl_sekw) { deb << SignalAt(a) ; a++; } deb <<endl;*/ int obcehashe = 0; /*4 29999994 1621159664 32212248367549038 288236599 1431849023 4 29999994 1621159664 32212248367549038 288236599 1431849023*/ uint64_t ild = 1;// mnożnik "liczby procesow", bo to za cholere nie da się wysłać 1/100 wzorca //jak będzie max, więc trzeba jeszcze ekstra podzielić na mniejsze wzorce jak zajdzie potrzeba if ((dl_wzorca/ilosc_procesow) > MAX_WZOR) { obcehashe = 1; uint64_t dlugosc_hasha = dl_wzorca/ilosc_procesow; if (dlugosc_hasha > MAX_HASHE) { //hashy będzie za duzo żeby je wysłać //więc trzeba będzie je jeszcze bardziej podzielić ild = (dlugosc_hasha/MAX_HASHE+1); } uint64_t _ilosc_procesow = ilosc_procesow * ild; hashe = new uint64_t[_ilosc_procesow*7]; uint64_t _nasz_proces = nasz_proces * ild; uint64_t _ild = ild; while(_ild--) { uint64_t a = (dl_wzorca) * _nasz_proces / _ilosc_procesow; uint64_t b = (dl_wzorca) * (_nasz_proces+1) / _ilosc_procesow -1; #ifdef __DEB2 deb << "EXTRA " << a << " " << b << endl; #endif uint64_t h1 = 0; uint64_t h2 = 0; uint64_t h3 = 0; uint64_t h4 = 0; uint64_t h5 = 0; uint64_t h6 = 0; uint64_t i = a+1; b++; while(i <= b) { uint64_t tmp = SignalAt(i); h1 ^= tmp; h2 += tmp; h3 = (h3 * 1073741789LL % 2147483587LL +tmp% 2147483587LL ) % 2147483587LL; h4 += tmp * 1073741827LL;// % 9007199254740997LL; h5 = (h5 * 2017413581LL % 2117413583LL+tmp% 2117413583LL) % 2117413583LL; h6 = (h6 * 1073741827LL % 2147483629LL+tmp% 2147483629LL) % 2147483629LL; i++; } hashe[_nasz_proces*7+0] = h1; hashe[_nasz_proces*7+1] = h2; hashe[_nasz_proces*7+2] = h3; hashe[_nasz_proces*7+3] = h4; hashe[_nasz_proces*7+4] = h5; hashe[_nasz_proces*7+5] = h6; hashe[_nasz_proces*7+6] = b-a; hbp3 = 1; hbp5 = 1; hbp6 = 1; uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; for(uint64_t x=1; x<=dl_wzorca-b; x<<=1) { if ((dl_wzorca-b) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; //deb << "&" << hbp3 << endl; } h3 = h3 * hbp3 % 2147483587LL;// +tmp% 2147483587LL ) % 2147483587LL; h5 = h5 * hbp5 % 2117413583LL;//+tmp% 2117413583LL) % 2117413583LL; h6 = h6 * hbp6 % 2147483629LL;//+tmp% 2147483629LL) % 2147483629LL; hash1 ^= h1; hash2 += h2; hash3 += h3; hash3 %= 2147483587LL; hash4 += h4; hash5 += h5; hash5 %= 2117413583LL; hash6 += h6; hash6 %= 2147483629LL; _nasz_proces++; } /* uint64_t a = dl_wzorca * nasz_proces / ilosc_procesow; uint64_t b = dl_wzorca * (nasz_proces+1) / ilosc_procesow -1; #ifdef __DEB deb << a << " " << b << endl; #endif uint64_t i = a+1; b++; while(i <= b) { uint64_t tmp = SignalAt(i); hash1 ^= tmp; hash2 += tmp; hash3 = (hash3 * 1073741789LL % 2147483587LL +tmp% 2147483587LL ) % 2147483587LL; hash4 += tmp * 1073741827LL;// % 9007199254740997LL; hash5 = (hash5 * 2017413581LL % 2117413583LL+tmp% 2117413583LL) % 2117413583LL; hash6 = (hash6 * 1073741827LL % 2147483629LL+tmp% 2147483629LL) % 2147483629LL; i++; } #ifdef __DEB deb << "H1: " << hash1 << endl; deb << "H2: " << hash2 << endl; deb << "H3: " << hash3 << endl; deb << "H4: " << hash4 << endl; deb << "H5: " << hash5 << endl; deb << "H6: " << hash6 << endl; #endif hash[nasz_proces][0] = hash1; hash[nasz_proces][1] = hash2; hash[nasz_proces][2] = hash3; hash[nasz_proces][3] = hash4; hash[nasz_proces][4] = hash5; hash[nasz_proces][5] = hash6; hash[nasz_proces][6] = b-a+1; uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; for(uint64_t x=1; x<=dl_wzorca-b; x<<=1) { if ((dl_wzorca-b) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; //deb << "&" << hbp3 << endl; } hash3 = hash3 * hbp3 % 2147483587LL;// +tmp% 2147483587LL ) % 2147483587LL; hash5 = hash5 * hbp5 % 2117413583LL;//+tmp% 2117413583LL) % 2117413583LL; hash6 = hash6 * hbp6 % 2147483629LL;//+tmp% 2147483629LL) % 2147483629LL; */ int i = 0; while(i < ilosc_procesow) { if (i != nasz_proces) { PutLL(i, hash1); PutLL(i, hash2); PutLL(i, hash3); PutLL(i, hash4); PutLL(i, hash5); PutLL(i, hash6); uint64_t przeznaczenie = nasz_proces * ild; uint64_t _ild = ild; while(_ild--) { // if (!nasz_proces)cerr << hashe[przeznaczenie*7+0] << endl; PutLL(i, hashe[przeznaczenie*7+0]); PutLL(i, hashe[przeznaczenie*7+1]); PutLL(i, hashe[przeznaczenie*7+2]); PutLL(i, hashe[przeznaczenie*7+3]); PutLL(i, hashe[przeznaczenie*7+4]); PutLL(i, hashe[przeznaczenie*7+5]); PutLL(i, hashe[przeznaczenie*7+6]); przeznaczenie++; } Send(i); } i++; } // cerr << "NADANE"; i = 0; while(i < ilosc_procesow) { if (i != nasz_proces) { Receive(i); uint64_t h1 = GetLL(i); uint64_t h2 = GetLL(i); uint64_t h3 = GetLL(i); uint64_t h4 = GetLL(i); uint64_t h5 = GetLL(i); uint64_t h6 = GetLL(i); hash1 ^= h1; hash2 += h2; hash3 += h3; hash3 %= 2147483587LL; hash4 += h4; hash5 += h5; hash5 %= 2117413583LL; hash6 += h6; hash6 %= 2147483629LL; uint64_t przeznaczenie = i * ild; uint64_t _ild = ild; while(_ild--) { hashe[przeznaczenie*7+0] = GetLL(i); hashe[przeznaczenie*7+1] = GetLL(i); hashe[przeznaczenie*7+2] = GetLL(i); hashe[przeznaczenie*7+3] = GetLL(i); hashe[przeznaczenie*7+4] = GetLL(i); hashe[przeznaczenie*7+5] = GetLL(i); hashe[przeznaczenie*7+6] = GetLL(i); przeznaczenie++; } } i++; } //wysyłamy do każdego nasze hashe //i odbieramy od każdego hashe /*deb << "%" << hbp3 << endl; deb << "%" << hbp5 << endl; deb << "%" << hbp6 << endl;*/ /* i--; nasz_proces++; hash1a ^= hash1; hash2a += hash2; hash3a += hash3; hash4a += hash4; hash5a += hash5; hash6a += hash6;*/ //} //uint64_t tmp = SignalAt(0); //hash4 = hash3 - tmp * 144115188075855881LL % 9007199254740997LL; /* #ifdef __DEB deb << hash1a << endl; deb << hash2a << endl; deb << hash3a << endl; deb << hash4a << endl; deb << hash5a << endl; deb << hash6a << endl << endl; #endif */ #ifdef __DEB /* * * 4 29999994 1621159664 32212248367549038 288236599 1431849023 4 29999994 1621159664 32212248367549038 288236599 1431849023 * */ #endif } else { //sami liczymy hashe, bo nie ma co równoleglić //uint64_t a = dl_wzorca * nasz_proces / ilosc_procesow; // uint64_t b = dl_wzorca * (nasz_proces+1) / ilosc_procesow -1; #ifdef __DEB deb << "JEDEN" << endl; #endif //nasz_proces++; //} // hbe = 1; uint64_t i =0; while(i < dl_wzorca) { uint64_t tmp = SignalAt(i+1); hash1 ^= tmp; hash2 += tmp; hash3 = (hash3 * 1073741789LL % 2147483587LL +tmp% 2147483587LL ) % 2147483587LL; hash4 += tmp * 1073741827LL;// % 9007199254740997LL; hash5 = (hash5 * 2017413581LL % 2117413583LL+tmp% 2117413583LL) % 2117413583LL; hash6 = (hash6 * 1073741827LL % 2147483629LL+tmp% 2147483629LL) % 2147483629LL; i++; } uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; for(uint64_t x=1; x<=dl_wzorca-1; x<<=1) { if ((dl_wzorca-1) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; //deb << "&" << hbp3 << endl; } } #ifdef __DEB2 if (obcehashe) { int i = 0; while(i < ilosc_procesow*ild) { deb << "H["<<i<<"][0]: " << hashe[i*7+0] << endl; deb << "H["<<i<<"][1]: " << hashe[i*7+1] << endl; deb << "H["<<i<<"][2]: " << hashe[i*7+2] << endl; deb << "H["<<i<<"][3]: " << hashe[i*7+3] << endl; deb << "H["<<i<<"][4]: " << hashe[i*7+4] << endl; deb << "H["<<i<<"][5]: " << hashe[i*7+5] << endl; deb << "H["<<i<<"][6] dlugosc: " << hashe[i*7+6] << endl; i++; } } #endif // deb << "&" << hbp3 << endl; //deb << "&" << hbp5 << endl; //deb << "&" << hbp6 << endl; uint64_t p = 0; if (((dl_sekw-dl_wzorca)/ilosc_procesow) > MAX_PRZESUNIECIE) { //długi wzorzec //uint64_t a = dl_wzorca * nasz_proces / ilosc_procesow; //uint64_t b = dl_wzorca * (nasz_proces+1) / ilosc_procesow -1; int dlugosc_hasha = hashe[6]; int i = 1; while(i < ilosc_procesow*ild) { if (dlugosc_hasha < hashe[i*7+6]) { dlugosc_hasha = hashe[i*7+6]; } i++; } #ifdef __DEB deb << "Hash max " << dlugosc_hasha << endl; #endif int64_t a = (dl_sekw-dlugosc_hasha) * nasz_proces / ilosc_procesow; int64_t b = (dl_sekw-dlugosc_hasha) * (nasz_proces+1) / ilosc_procesow-1 + dlugosc_hasha; #ifdef __DEB deb << "SZUKANIE " << a << " " << b << endl; #endif } else { //obcehashe = 0; //wiele nie ma do przeszukiwania if (obcehashe) { //ale hash był długi więc musimy go jeszcze policzyć takze we wzorcu zanim przeszukiwanie rozpoczniemy uint64_t a = (dl_wzorca-1) * nasz_proces / ilosc_procesow; uint64_t b = (dl_wzorca-1) * (nasz_proces+1) / ilosc_procesow -1; // if (b == dl_wzorca-1)b--; #ifdef __DEB deb << " ** " << a << " " << b << endl; #endif uint64_t i = a+1; b++; while(i <= b) { uint64_t tmp = SignalAt(i); hashsek1 ^= tmp; hashsek2 += tmp; hashsek3 = (hashsek3 * 1073741789LL % 2147483587LL +tmp% 2147483587LL ) % 2147483587LL; hashsek4 += tmp * 1073741827LL;// % 9007199254740997LL; hashsek5 = (hashsek5 * 2017413581LL % 2117413583LL+tmp% 2117413583LL) % 2117413583LL; hashsek6 = (hashsek6 * 1073741827LL % 2147483629LL+tmp% 2147483629LL) % 2147483629LL; i++; } uint64_t hbp3 = 1, hbp5 = 1, hbp6 = 1; uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; // b--; for(uint64_t x=1; x<=dl_wzorca-b-1; x<<=1) { if ((dl_wzorca-b-1) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; //deb << "&" << hbp3 << endl; } hashsek3 = hashsek3 * hbp3 % 2147483587LL;// +tmp% 2147483587LL ) % 2147483587LL; hashsek5 = hashsek5 * hbp5 % 2117413583LL;//+tmp% 2117413583LL) % 2117413583LL; hashsek6 = hashsek6 * hbp6 % 2147483629LL;//+tmp% 2147483629LL) % 2147483629LL; /* deb << hashsek1 << endl; deb << hashsek2 << endl; deb << hashsek3 << endl; deb << hashsek4 << endl; deb << hashsek5 << endl; deb << hashsek6 << endl << endl;*/ i = 0; while(i < ilosc_procesow) { if (i != nasz_proces) { PutLL(i, hashsek1); PutLL(i, hashsek2); PutLL(i, hashsek3); PutLL(i, hashsek4); PutLL(i, hashsek5); PutLL(i, hashsek6); Send(i); } i++; } i = 0; while(i < ilosc_procesow) { if (i != nasz_proces) { Receive(i); uint64_t h1 = GetLL(i); uint64_t h2 = GetLL(i); uint64_t h3 = GetLL(i); uint64_t h4 = GetLL(i); uint64_t h5 = GetLL(i); uint64_t h6 = GetLL(i); hashsek1 ^= h1; hashsek2 += h2; hashsek3 += h3; hashsek3 %= 2147483587LL; hashsek4 += h4; hashsek5 += h5; hashsek5 %= 2117413583LL; hashsek6 += h6; hashsek6 %= 2147483629LL; } i++; } } if (!nasz_proces) { #ifdef __DEB deb << "JEDEN"<<endl; #endif uint64_t i = 0; if (!obcehashe) { while(i < dl_wzorca-1) { uint64_t tmp2 = SeqAt(i+1); hashsek1 ^= tmp2; hashsek2 += tmp2; hashsek3 = (hashsek3 * 1073741789LL % 2147483587LL +tmp2% 2147483587LL ) % 2147483587LL; hashsek4 += tmp2 * 1073741827LL;// % 9007199254740997LL; hashsek5 = (hashsek5 * 2017413581LL % 2117413583LL+tmp2% 2117413583LL) % 2117413583LL; hashsek6 = (hashsek6 * 1073741827LL % 2147483629LL+tmp2 % 2147483629LL) % 2147483629LL; i++; } //deb << "&" << hbp3 << endl; } else { hbp3 = 1; hbp5 = 1; hbp6 = 1; uint64_t tmp3 = 1073741789LL; uint64_t tmp5 = 2017413581LL; uint64_t tmp6 = 1073741827LL; for(uint64_t x=1; x<=dl_wzorca-1; x<<=1) { if ((dl_wzorca-1) & x) { hbp3 *= tmp3; hbp3 %= 2147483587LL; hbp5 *= tmp5; hbp5 %= 2117413583LL; hbp6 *= tmp6; hbp6 %= 2147483629LL; } tmp3 *= tmp3; tmp3 %= 2147483587LL; tmp5 *= tmp5; tmp5 %= 2117413583LL; tmp6 *= tmp6; tmp6 %= 2147483629LL; } i = dl_wzorca - 1; } // 4057608999 222781835 poprawny // 1917413584 222781835 // 315378610023172087 /* deb << "EXTRA HASH 1" << endl << hashsek1 << endl; deb << hashsek2 << endl; deb << hashsek3 << endl; deb << hashsek4 << endl; deb << hashsek5 << endl; deb << hashsek6 << endl << endl; */ //wstępne hashe policzone p = 0; uint64_t j = 0; while(i < dl_sekw) { uint64_t tmp2 = SeqAt(i+1); hashsek1 ^= tmp2; hashsek2 += tmp2; hashsek3 = (hashsek3 * 1073741789LL % 2147483587LL +tmp2 % 2147483587LL ) % 2147483587LL; hashsek4 += tmp2 * 1073741827LL;// % 9007199254740997LL; hashsek5 = (hashsek5 * 2017413581LL % 2117413583LL+tmp2% 2117413583LL) % 2117413583LL; hashsek6 = (hashsek6 * 1073741827LL % 2147483629LL+tmp2 % 2147483629LL) % 2147483629LL; //hashsek6 += (tmp2 ^ 0xAA55A55AFF1312) * 1073741827LL ; /* deb << "EXTRA HASH 2" << endl << hashsek1 << endl; deb << hashsek2 << endl; deb << hashsek3 << endl; deb << hashsek4 << endl; deb << hashsek5 << endl; deb << hashsek6 << endl << endl; if (j > 20) break; */ if(hashsek6 == hash6) if(hashsek5 == hash5) if(hashsek4 == hash4) if(hashsek3 == hash3) if(hashsek2 == hash2) if(hashsek1 == hash1) { // deb << "*" << j << " " << SeqAt(j) << " " << SeqAt(j+1) << " " << SeqAt(j+2) <<endl; p++; } tmp2 = SeqAt(j+1); hashsek1 ^= tmp2; hashsek2 -= tmp2; hashsek4 -= tmp2 * 1073741827LL;// % 9007199254740997LL; int64_t x = ((int64_t)hashsek6- ((int64_t)tmp2 % 2147483629LL) * (int64_t)hbp6) % 2147483629LL; if (x<0) x+=2147483629LL; hashsek6 = x;//(hashsek6 ) % 2147483629LL;// * 1073741827LL % 2147483629LL+tmp) % 2147483629LL; x = ((int64_t)hashsek3 - ((int64_t)tmp2 % 2147483587LL) * (int64_t)hbp3) % 2147483587LL; if (x<0) x+=2147483587LL; hashsek3 = x;//(hashsek3 * 1073741789LL % 2147483587LL +tmp2 ) % 2147483587LL; x = ((int64_t)hashsek5 - ((int64_t)tmp2 % 2117413583LL) * (int64_t)hbp5) % 2117413583LL; if (x<0) x+=2117413583LL; hashsek5 = x;//(hashsek3 * 1073741789LL % 2147483587LL +tmp2 ) % 2147483587LL; // deb << "**" << hashsek3 << endl << endl; // hashsek6 -= tmp2 * tab[j%13]; //hashsek6 -= (tmp2 ^ 0xAA55A55AFF1312) * 1073741827LL ; i++; j++; } cout << p<<endl; } } /* 4 29999994 1621159664 32212248367549038 288236599 1431849023 1292250785 67909 948363714 4 29999994 1621159664 32212248367549038 288236599 1431849023 1292250785 67909 948363714 */ #ifdef __DEB deb << hash1 << endl; deb << hash2 << endl; deb << hash3 << endl; deb << hash4 << endl; deb << hash5 << endl; deb << hash6 << endl << endl; deb << hbp3 << endl; deb << hbp5 << endl; deb << hbp6 << endl << endl; deb << hashsek1 << endl; deb << hashsek2 << endl; deb << hashsek3 << endl; deb << hashsek4 << endl; deb << hashsek5 << endl; deb << hashsek6 << endl << endl; #endif //cout << p << endl; return 0; } |