xref: /phasta/phSolver/common/cycle_count.c (revision 712d3df0b59ebebaaeaea358162c8d2c043c6e08)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <mpi.h>
5 #ifdef __bgq__
6 #include <hwi/include/bqc/A2_inlines.h>
7 #endif
8 #include "FCMangle.h"
9 
10 static uint64_t start;
11 static uint64_t total;
12 
13 
14 #define cycle_count_stop FortranCInterface_GLOBAL_(cycle_count_stop, CYCLE_COUNT_STOP)
15 #define cycle_count_start FortranCInterface_GLOBAL_(cycle_count_start, CYCLE_COUNT_START)
16 #define cycle_count_print FortranCInterface_GLOBAL_(cycle_count_print, CYCLE_COUNT_PRINT)
17 
cycle_count_stop()18 void cycle_count_stop()
19 {
20 #ifdef __bgq__
21 	uint64_t tb = GetTimeBase();
22 	if(__builtin_expect(tb < start, 0))
23 	{
24 		total += tb + (UINT64_MAX-start);
25 	}
26 	else
27 	{
28 		total += tb-start;
29 	}
30 #else
31 	total = 0; //FIEX ME for non BGQ env
32 #endif
33 }
cycle_count_start()34 void cycle_count_start()
35 {
36 #ifdef __bgq__
37 	start = GetTimeBase();
38 #else
39 	start = 0; //FIEX ME for non BGQ env
40 #endif
41 }
42 
cycle_count_print()43 void cycle_count_print()
44 {
45         uint64_t iresult;
46 	int rank;
47 	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
48 	MPI_Allreduce(&total, &iresult, 1, MPI_LONG_LONG_INT,
49 			MPI_MAX, MPI_COMM_WORLD);
50         if(rank == 0)
51 	printf("fillsparse : %llu cycles\n", iresult);
52 	total = 0;
53 }
54