Created
November 7, 2017 08:34
-
-
Save kaityo256/c4fc64ffdd5a8725e0ed038bf09fe7bc to your computer and use it in GitHub Desktop.
malloc test on multithread
This file contains 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 characters
#include <cstdio> | |
#include <cstdlib> | |
#include <omp.h> | |
const int N = 16; | |
int | |
main(int argc, char **argv){ | |
char *buf[N]; | |
size_t size = atoi(argv[1]); | |
printf("digraph test_%d\n {\n",size); | |
#pragma omp parallel for | |
for(int i=0;i<N;i++) buf[i] = (char*)malloc(size); | |
#pragma omp parallel for | |
for(int i=0;i<N;i++){ | |
for(int j=0;j<size;j++)buf[i][j] = 0; | |
} | |
#pragma omp barrier | |
for(int i=0;i<N;i++){ | |
free(buf[i]); | |
size_t *p = (size_t*)(buf[i]); | |
printf("\"%lx\" -> \"%lx\"\n",(p-2),*p); | |
} | |
#pragma omp barrier | |
printf("}\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment