/* * @@name: affinity_display.3.c * @@type: C * @@compilable: yes, omp_5.0 * @@linkable: yes * @@expect: success */ #include #include // also null is in #include #include #include #define FORMAT_STORE 80 #define BUFFER_STORE 80 int main(void){ int i, n, thrd_num, max_req_store; size_t nchars; char default_format[FORMAT_STORE]; char my_format[] = "host=%20H thrd_num=%0.4n binds_to=%A"; char **buffer; // CODE SEGMENT 1 AFFINITY FORMAT // Get and Display Default Affinity Format nchars = omp_get_affinity_format(default_format,(size_t)FORMAT_STORE); printf("Default Affinity Format is: %s\n",default_format); if(nchars >= FORMAT_STORE){ printf("Caution: Reported Format is truncated. Increase\n"); printf(" FORMAT_STORE to %d.\n", nchars+1); } // Set Affinity Format omp_set_affinity_format(my_format); printf("Affinity Format set to: %s\n",my_format); // CODE SEGMENT 2 CAPTURE AFFINITY // Set up buffer for affinity of n threads n = omp_get_num_procs(); buffer = (char **)malloc( sizeof(char *) * n ); for(i=0;in) exit(1); //safety: don't exceed # of buffers thrd_num=omp_get_thread_num(); nchars=omp_capture_affinity(buffer[thrd_num],(size_t)BUFFER_STORE,NULL); if(nchars > max_req_store) max_req_store=nchars; // ... } for(i=0;i=BUFFER_STORE){ printf("Caution: Affinity string truncated. Increase\n"); printf(" BUFFER_STORE to %d\n",max_req_store+1); } for(i=0;i