// Copyright 2021 Jeisson Hidalgo CC-BY 4.0 #include #include int main(int argc, char* argv[]) { const int thread_count = argc >= 2 ? atoi(argv[1]) : omp_get_max_threads(); std::string word; #pragma omp parallel num_threads(thread_count) \ default(none) shared(std::cin, std::cout, word) #pragma omp single { // First task: read and print first word of the sentence std::cin >> word; #pragma omp task untied if(false) \ default(none) shared(std::cout) firstprivate(word) std::cout << word; // Second task: shuffle remaining words of the sentence while (std::cin >> word) { #pragma omp task untied default(none) shared(std::cout) firstprivate(word) std::cout << ' ' + word; } // Third task: finish the sentence #pragma omp taskwait #pragma omp task untied default(none) shared(std::cout) std::cout << '.' << std::endl; } }