Skip to content

Iz 2#2

Open
Denactive wants to merge 30 commits intomainfrom
iz-2
Open

Iz 2#2
Denactive wants to merge 30 commits intomainfrom
iz-2

Conversation

@Denactive
Copy link
Owner

тесты пока не готовы, смейк для либ тоже

@codecov-io
Copy link

codecov-io commented Mar 28, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@ff2cf8c). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main       #2   +/-   ##
=======================================
  Coverage        ?   82.41%           
=======================================
  Files           ?        7           
  Lines           ?      887           
  Branches        ?        0           
=======================================
  Hits            ?      731           
  Misses          ?      156           
  Partials        ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff2cf8c...906de8c. Read the comment docs.

int main(int argc, const char** argv) {
if (argc < 3) {
printf("Please pass a source path and a word to search\n");
return -1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main не должен возвращать отрицательный код


//clock_t start = clock();
string_size_pair* res = (string_size_pair *)word_search_mt(argv[2], file_list, files_amount, num_tr);
//clock_t end = clock();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мертвого кода в гитхабе быть не должно

// return 0;
}

void clear_file_list(char*** file_list, size_t files_amount) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Проверка указателя?

// чтобы не писать еще одну сортировку
sorted_by_size = create_word_search_result(file_list, files_amount);
if (!sorted_by_size)
goto free_file_sizes;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Убирай, без вариантов

}
if (word_search(pattern, res, files_amount)) {
printf("Error | word_search failed in [%zu] thread \n", tr_no);
pthread_exit((void *) (2));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

что такое 2?

Copy link
Collaborator

@IlyaSaneev IlyaSaneev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавить результаты работы алгоритмов в ридми
Нет использования динамической библиотеки
Нет приемов по эффективной работе с кеш-памятью.

// create_word_search_result_mt separates the file list for threads so each has
// approximately equal bytes in total and initializes complicated structure string_sizex2 array with
// amount of files in a thread's file list and initializes a 'res' field to save a searching statistics
string_sizex2* create_word_search_result_mt(size_t num_tr, char** file_list, size_t files_amount) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Функцию нужно декомпозировать на несколько функций.

void* thread_searcher(void* args) {
if (!args)
pthread_exit((void*)(-1));
const char* pattern = ((thread_searcher_data*)args)->pattern;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thread_searcher_data* searcher_data = (thread_searcher_data*)args;
и далее searcher_data->

Comment on lines +201 to +204
if (exit_status == -1 && join_status == 0)
join_status = -1; // fatal
if (exit_status == 2 && join_status == 0)
join_status = 2; // NULL pattern or word_search_result addr | non fatal | impossible to get here
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А может ли быть такое что iый поток был fatal, а i + 1 уже не fatal? В этом случае join_status с -1 будет перезатерт на -2

pthread_exit((void*)15);
}

string_size_pair* word_search_mt(const char* pattern, char** file_list, size_t files_amount, size_t num_tr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично функцию декомпозировать

return (char*)content;
}

size_t check_str (const char* str, const char* pattern) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно много тестов на этот метод.

@IlyaSaneev IlyaSaneev removed their assignment Mar 29, 2021
@Denactive
Copy link
Owner Author

Исправил все замечания. Возможно, разбивка функции, создающей структуру, была ошибкой. Хоть она и занимала 90 строк, а не 60, как теперь, читать ее было легче.
Еще добавил динамическую линковку, стресс-тест. Тест на скорость - теперь отдельный тест.
Результаты времени прогона лежат в ридми. Задействовал кеш процессора реструктуризацией списка файлов - теперь каждый поток работает со своим собственным последовательным списком, а не списком адресов, что дало прирост к скорости в 40%, но все же однопоток работает быстрее. По крайней мере на небольшом числе больших файлов. Больше тестовых файлов делать не стал, т.к. с какого-то момента моим скриптом они создаются битые. На 500 маленьких файлах работает мгновенно, хотя однопоточная реализация все еще быстрее.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants