char* logger:: format_header(const logger::msg& a_msg, char* a_buf, const char* a_end) { // Message mormat: Timestamp|Level|Ident|Category|Message|File:Line FunName // Write everything up to Message to the m_data: char* p = a_buf; // Write Timestamp if (timestamp_type() != stamp_type::NO_TIMESTAMP) { p += timestamp::format(timestamp_type(), a_msg.m_timestamp, p, a_end - p); *p++ = '|'; } // Write Level *p++ = logger::log_level_to_str(a_msg.m_level)[0]; *p++ = '|'; if (show_ident()) { p = stpncpy(p, ident().c_str(), ident().size()); *p++ = '|'; } if (show_thread()) { if (a_msg.m_thread_name[0] == '\0') { char* q = const_cast<char*>(a_msg.m_thread_name); itoa(a_msg.m_thread_id, q, 10); } p = stpcpy(p, a_msg.m_thread_name); *p++ = '|'; } if (show_category()) { if (!a_msg.m_category.empty()) p = stpncpy(p, a_msg.m_category.c_str(), a_msg.m_category.size()); *p++ = '|'; } return p; }
int main(){ int i, k; int nworkers, totalworkers; char cpuCount[20]; double *a, *b, *c, *d; double sums[2000]; cpu_set_t cpuset; TimeData timer; double triad_time, copy_time, total = 0; nprocessors = sysconf(_SC_NPROCESSORS_CONF); nworkers = cilk_spawn get_nworkers(); totalworkers = cilk_spawn get_totalworkers(); for (i=0;i<nworkers;i++) { sums[i] = 0; } LIKWID_MARKER_INIT; cilk_spawn allocate_vector(&a, SIZE); cilk_spawn allocate_vector(&b, SIZE); cilk_spawn allocate_vector(&c, SIZE); cilk_spawn allocate_vector(&d, SIZE); cilk_sync; for (i=0; i<SIZE; i++) { a[i] = 1.0; b[i] = 2.0; c[i] = 0.0; d[i] = 1.0; } time_start(&timer); for (k=0; k<ITER; k++) { for (i=0;i<nworkers;i++) { cilk_spawn LIKWID_MARKER_START("copy"); } cilk_sync; cilk_for(i=0;i<SIZE;i++) { c[i] = a[i]; } for (i=0;i<nworkers;i++) { cilk_spawn LIKWID_MARKER_STOP("copy"); } cilk_sync; } time_stop(&timer); copy_time = time_print(&timer)/(double)ITER; time_start(&timer); for (k=0; k<ITER; k++) { for (i=0;i<nworkers;i++) { cilk_spawn LIKWID_MARKER_START("triad"); } cilk_sync; cilk_for(i=0;i<SIZE;i++) { a[i] = b[i] + c[i] * d[i]; } for (i=0;i<nworkers;i++) { cilk_spawn LIKWID_MARKER_STOP("triad"); } cilk_sync; } time_stop(&timer); triad_time = time_print(&timer)/(double)ITER; printf("Processed %.1f Mbyte at copy benchmark in %.4f seconds: %.2f MByte/s\n", 1E-6*(2*SIZE*sizeof(double)), copy_time, 1E-6*((2*SIZE*sizeof(double))/copy_time)); printf("Processed %.1f Mbyte at triad benchmark in %.4f seconds: %.2f MByte/s\n", 1E-6*(4*SIZE*sizeof(double)), triad_time, 1E-6*((4*SIZE*sizeof(double))/triad_time)); printf("Main PID %d\n",getpid()); for (i=0;i<nworkers;i++) { cilk_spawn show_thread(); } cilk_sync; LIKWID_MARKER_CLOSE; }