Created
September 4, 2013 14:51
-
-
Save nattoheaven/6438054 to your computer and use it in GitHub Desktop.
Revisions
-
nattoheaven created this gist
Sep 4, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h> #include <immintrin.h> static volatile double zr = 0.0; static volatile double zi = 0.0; static const double cr = 0.1; static const double ci = 0.1; static void *run(void *arg) { for (int i = 0; i < 1000000; ++i) { while (true) { if (_xbegin() == _XBEGIN_STARTED) { double oldzr = zr; double oldzi = zi; double newzr = oldzr * oldzr - oldzi * oldzi + cr; double newzi = 2 * oldzr * oldzi + ci; zr = newzr; zi = newzi; _xend(); break; } _mm256_zeroall(); } } return 0; } int main(int argc, char **argv) { int n = atoi(argv[1]); pthread_t *threads = new pthread_t[n]; for (int i = 0; i < n; ++i) { pthread_create(&threads[i], 0, run, 0); } for (int i = 0; i < n; ++i) { pthread_join(threads[i], 0); } printf("%f + %fi\n", zr, zi); return 0; }