Skip to content

Commit f22e395

Browse files
authored
Merge pull request #478 from ChunYen-Chen/record_cpu
Record more CPU information
2 parents bb0f20e + 2990c8f commit f22e395

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/Auxiliary/Aux_GetCPUInfo.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ void Aux_GetCPUInfo( const char *FileName )
2222
FILE *Note = fopen( FileName, "a" );
2323
char *line = NULL;
2424
size_t len = 0;
25-
char String[2][100];
25+
char String[2][MAX_STRING];
26+
char Trash[MAX_STRING];
27+
int SocketNow = -1, SocketPrevious = -1;
28+
int CorePerSocket = 0, NSocket = 0;
29+
bool GotFirstCPUInfo = false;
2630

2731

2832
// 1. get the CPU info
@@ -40,6 +44,18 @@ void Aux_GetCPUInfo( const char *FileName )
4044
{
4145
sscanf( line, "%s%s", String[0], String[1] );
4246

47+
if ( strcmp( String[0], "physical" ) == 0 && strcmp( String[1], "id" ) == 0 )
48+
{
49+
sscanf( line, "%s%s%s%d", String[0], String[1], Trash, &SocketNow );
50+
if ( SocketNow != SocketPrevious )
51+
{
52+
SocketPrevious = SocketNow;
53+
NSocket++;
54+
}
55+
}
56+
57+
if ( GotFirstCPUInfo ) continue;
58+
4359
if ( strcmp( String[0], "model" ) == 0 && strcmp( String[1], "name" ) == 0 )
4460
{
4561
memcpy( line, "CPU Type ", 10 );
@@ -62,7 +78,8 @@ void Aux_GetCPUInfo( const char *FileName )
6278
{
6379
memcpy( line, "CPU Cores", 9 );
6480
fprintf( Note, "%s", line );
65-
break;
81+
sscanf( line, "%s%s%s%d", String[0], String[1], Trash, &CorePerSocket );
82+
GotFirstCPUInfo = true;
6683
}
6784
}
6885

@@ -72,6 +89,10 @@ void Aux_GetCPUInfo( const char *FileName )
7289
line = NULL;
7390
}
7491

92+
fprintf( Note, "%-16s: %d\n", "Socket(s)", NSocket );
93+
// assuming the CPUs in the node are the same
94+
fprintf( Note, "%-16s: %d\n", "Core(s) per Node", CorePerSocket*NSocket );
95+
7596
fclose( CPUInfo );
7697

7798

0 commit comments

Comments
 (0)