10 #include <sys/sysctl.h>
16 #define MAX_GET_LEN 32
22 ostream &
tab(ostream &out)
42 for ( i=0; i<argc; i++ )
46 cout <<
"DEBUG: cmd_line: " <<
command << endl;
73 time_t ti = time(NULL);
77 clstring = clstring +
"\n# " + asctime(localtime(&ti)) +
"\n";
80 cout <<
"DEBUG command_line_time: " << clstring << endl;
96 if ( (bufsize = sysconf(_SC_GETPW_R_SIZE_MAX)) == -1 )
100 passwd pw, *result = NULL;
102 string user_name(
"unknown");
104 if ( getpwuid_r(getuid(), &pw, buffer, bufsize, &result) == 0 && result)
105 user_name = pw.pw_name;
131 for ( i = 0;
use[i] != NULL; i++ )
132 cout <<
use[i] << endl;
134 for ( i = 0;
use[i] && strstr(
use[i],
"Example") == 0; i++ )
135 cout <<
use[i] << endl;
137 cout << endl <<
"Bsoft version " <<
BVERSION <<
" (" << 8*
sizeof(long) <<
" bit)" << endl << endl;
154 char* test =
new char[8];
155 int* itest = (
int *) test;
156 float* ftest = (
float *) test;
158 memcpy(test,
"jbh ", 8);
160 if ( itest[0] == 1784834080 && fabs(ftest[0] - 6.84272e+25) < 1e+21 )
163 if ( itest[0] == 543711850 && fabs(ftest[0] - 1.96837e-19) < 1e-23 )
169 cout <<
"System type: Big-endian IEEE";
172 cout <<
"System type: Little-endian IEEE";
175 cout <<
"System type: Unknown";
178 cout <<
" (" << 8*
sizeof(long) <<
")" << endl << endl;
182 cout <<
"DEBUG systype: " << test <<
" " << itest[0] <<
" " << ftest[0] <<
" " << type << endl;
198 np = omp_get_num_procs();
201 np = sysconf( _SC_NPROCESSORS_ONLN );
213 #if defined(CTL_HW) && (defined(HW_MEMSIZE) || defined(HW_PHYSMEM64))
217 #if defined(HW_MEMSIZE)
219 #elif defined(HW_PHYSMEM64)
220 mib[1] = HW_PHYSMEM64;
222 u_int namelen =
sizeof(mib) /
sizeof(mib[0]);
224 size_t len =
sizeof(size);
226 if (sysctl(mib, namelen, &size, &len, NULL, 0) == 0)
229 #elif defined(_SC_PHYS_PAGES)
231 #if defined(_SC_PAGESIZE) // FreeBSD, Linux, OpenBSD, and Solaris
232 return (
long)sysconf( _SC_PHYS_PAGES ) *
233 (long)sysconf( _SC_PAGESIZE );
235 #elif defined(_SC_PAGE_SIZE)
236 return (
long)sysconf( _SC_PHYS_PAGES ) *
237 (long)sysconf( _SC_PAGE_SIZE );
240 #elif defined(_SC_AIX_REALMEM) // AIX
241 return (
long)sysconf( _SC_AIX_REALMEM ) * (long)1024L;
245 perror(
"system_memory: sysctl error");
260 cout <<
"Memory available: " << mem_avail << endl;
261 cout <<
"Memory required: " << mem_required <<
" ("
262 << setprecision(2) << mem_required*100.0/mem_avail <<
" %)" << endl << endl;
265 if ( mem_avail < mem_required ) {
266 cerr <<
"Error: Not enough memory!" << endl;
267 cerr <<
"Memory available: " << mem_avail << endl;
268 cerr <<
"Memory required: " << mem_required << endl << endl;
300 case '1': type =
Bit;
break;
303 case 'u': type =
UShort;
break;
304 case 's': type =
Short;
break;
306 case 'i': type =
Integer;
break;
307 case 'k': type =
ULong;
break;
308 case 'l': type =
Long;
break;
309 case 'f': type =
Float;
break;
310 case 'd': type =
Double;
break;
311 case 'S': type =
Short;
break;
312 case 'I': type =
Integer;
break;
313 case 'F': type =
Float;
break;
314 case 'D': type =
Double;
break;
338 for (
long i=0; i<n; ++i ) numsel[i] = ns[i];
344 vector<int> numsel(n, 0);
348 if (
string.
length() < 1 ||
string ==
"all" ) {
349 for ( i=0; i<n; i++ ) numsel[i] = 1;
354 cout <<
"DEBUG select_numbers: string=" <<
string <<
" n=" << n << endl;
360 for ( k=1, sc = strcol; sc; sc = sc->
next, k++ ) {
361 strarr = sc->
split(
",");
363 for ( s = strarr; s; s = s->
next ) {
367 for ( ; i <= j && i < n; i++ ) numsel[i] = k;
377 cout <<
"DEBUG select_numbers: ";
378 for ( i=0; i<n; i++ ) cout << numsel[i];
403 }
else if (powerOf == 1) {
406 while (rVal < startNumber) {
426 cerr <<
"Error in get_integer: scanning length too large!" << endl;
431 strncpy(temp, ptr, len);
433 sscanf(temp,
"%d", &d);
449 cerr <<
"Error in get_integer: scanning length too large!" << endl;
454 strncpy(temp, ptr, len);
456 sscanf(temp,
"%f", &f);
473 for ( i=0, n--; i<n; i++, n-- ) {
494 cout <<
"DEBUG swapbytes: size=" << size <<
" n=" << n << endl;
498 for ( i=0; i<size; i+=n, v+=n )
swapbytes(v, n);
528 for ( i=0; i<4; i++ ) v[i] = t[i];
530 expnt = (v[0] << 1) | (v[1] >> 7);
538 else if ( expnt > 2 )
543 t[1] = ( (v[1] & 0x7f) >> shift ) | ( 0x10 << expnt );
544 t[2] = ( v[1] << ( 8-shift ) ) | ( v[2] >> shift );
545 t[3] = ( v[2] << ( 8-shift ) ) | ( v[3] >> shift );
547 for ( i=0; i<4; i++ ) v[i] = t[i];
590 if ( (value0 > threshold) && (value0 < 0) )
612 size_t chunk_size = datasize/np;
616 np = (datasize - 1)/chunk_size + 1;
620 cout <<
"Number of processors: " << np << endl << endl;
623 cout <<
"Chunk size: " << chunk_size << endl << endl;
626 cout <<
"DEBUG get_chunk_size: chunk_size = " << chunk_size << endl;
646 size_t chunk_size(datasize/np);
648 while ( chunk_size%c ) chunk_size++;
652 np = (datasize - 1)/chunk_size + 1;
656 cout <<
"Number of processors: " << np << endl << endl;
659 cout <<
"Chunk size: " << chunk_size << endl << endl;
662 cout <<
"DEBUG get_chunk_size: chunk_size = " << chunk_size << endl;
680 int error_show(
const char* message,
const char* file,
int line)
684 snprintf(
string, 1024,
"[%s:%d] %s", file, line, message);
688 if ( errno ) cerr <<
"errno " << errno <<
": ";
692 cerr <<
"Make sure the file exists and the path to the file is correct" << endl;
695 cerr <<
"Make sure you have permission to write to this directory" << endl;
698 cerr <<
"The memory available on this computer may be insufficient" << endl;
725 string s =
"[" + file +
":" + to_string(line) +
"] " + message;
730 if ( errno ) cerr <<
"errno " << errno <<
": ";
734 cerr <<
"Make sure the file exists and the path to the file is correct" << endl;
737 cerr <<
"Make sure you have permission to write to this directory" << endl;
740 cerr <<
"The memory available on this computer may be insufficient" << endl;