Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TEST_SIZE = 70000;
- // Comparing test1 and test2.
- // SINGLE-THREAD :
- bool test1()
- {
- double nonsense = 0;
- for (int i = 0; i < TEST_SIZE; ++i) {
- for (int j = 0; j < TEST_SIZE; ++j) {
- nonsense = sqrt(i + j);
- }
- }
- printf("ready");
- return true;
- }
- // MULI-THREAD :
- void* first_half(void* ptr)
- {
- double nonsense = 0;
- for (int i = 0; i < TEST_SIZE / 2 + 1; ++i) {
- for (int j = 0; j < TEST_SIZE / 2 + 1; ++j) {
- nonsense = sqrt(i + j);
- }
- }
- }
- void* second_half(void* ptr)
- {
- double nonsense = 0;
- for (int i = TEST_SIZE / 2 + 1; i < TEST_SIZE; ++i) {
- for (int j = TEST_SIZE / 2 + 1; j < TEST_SIZE; ++j) {
- nonsense = sqrt(i + j);
- }
- }
- }
- bool test2()
- {
- pthread_t t1, t2, t3, t4;
- int ret;
- ret = pthread_create(&t1, NULL, first_half, NULL);
- if (ret != 0)
- return false;
- ret = pthread_create(&t2, NULL, second_half, NULL);
- if (ret != 0)
- return false;
- // join shortest distance calculation :
- ret = pthread_join(t1, NULL);
- if (ret != 0)
- return false;
- // join shortest distance calculation :
- ret = pthread_join(t2, NULL);
- if (ret != 0)
- return false;
- printf("ready\n");
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement