// information about the machine, outside of the CPU void ReportMachinePhysical() { printf("##Machine\n"); // this should work for any Mach based OS (MacOS, FreeBSD, etc.) #if defined(_MACHTYPES_H_) // see sysctl.h for the definitions { long returnBuffer=0, retval=0; long long bigBuffer = 0; size_t len; len = 4; returnBuffer = 0; retval = sysctlbyname("hw.ncpu", &returnBuffer, &len, NULL, 0); if (retval == 0) { printf("Machine has %ld CPUs\n", returnBuffer ); } len = 4; retval = sysctlbyname("hw.physicalcpu_max", &returnBuffer, &len, NULL, 0); if (retval == 0) printf("Machine has %ld physical CPUs\n", returnBuffer ); len = 4; retval = sysctlbyname("hw.logicalcpu_max", &returnBuffer, &len, NULL, 0); if (retval == 0) printf("Machine has %ld logical CPUs\n", returnBuffer ); len = 8; retval = sysctlbyname("hw.memsize", &bigBuffer, &len, NULL, 0); if (retval == 0) { printf("Machine has "); printMemSize( bigBuffer ); printf(" of RAM\n"); } len = 8; retval = sysctlbyname("hw.pagesize", &bigBuffer, &len, NULL, 0); if (retval == 0) { printf("Machine using "); printMemSize( bigBuffer ); printf(" pagesize\n"); } } #endif // _MACHTYPES_H_ }
int main() { long i; long count; long start = 1, end = 1; char nodataerror = 1; Node **path; #ifdef _DEBUG printf("ULONG_MAX: %ld (%d), UINT_MAX: %d (%d),\nUSHRT_MAX: %d (%d), UCHAR_MAX: %d (%d)\n\n",ULONG_MAX,sizeof(unsigned long),UINT_MAX,sizeof(unsigned int),USHRT_MAX,sizeof(unsigned short),UCHAR_MAX,sizeof(unsigned char)); printMemSize(); #endif printf("Enter m and n (number of nodes on the x-axis and y-axis,\n\tthe width and height of the grid)\n\tlike so:\n\t\"x\ty\" (without the quotes)\n"); scanf("%ld%ld",&m,&n); if(m<3){ printf("ERROR: 3 is the minimun for m, your value of: %ld doesn't qualify.\n",m); nodataerror = 0; } if(n<3){ printf("ERROR: 3 is the minimun for n, your value of: %ld doesn't qualify.\n",n); nodataerror = 0; } #ifdef _DEBUG printMemSize(); #endif if(nodataerror){ numNodes = m*n; numLinesH = n*(m-1); numLinesV = m*(n-1); numLines = numLinesH + numLinesV; numControlPosts = 2*(m-2) + 2*(n-2); printf("Enter start and end controlpost (starting from the bottom left numbered CCW)\n\tlike so:\n\"start\tend\" (without the quotes)\n"); scanf("%ld%ld",&start,&end); if(start>numControlPosts||start<1){ printf("ERROR: Start point not on the grid, for these dimensions (%ldx%ld)\n\tthe control posts on the grid are numbered %ld through %ld.\n",m,n,1L,numControlPosts); nodataerror = 0; } if(end>numControlPosts||end<1){ printf("ERROR: End point not on the grid, for these dimensions (%ldx%ld)\n\tthe control posts on the grid are numbered %ld through %ld.\n",m,n,1L,numControlPosts); nodataerror = 0; } if(start==end){ printf("ERROR: Start point is the same as endpoint you won't be needing any navigation.\n"); nodataerror = 0; } #ifdef _DEBUG printMemSize(); #endif if(nodataerror){ printf("Input accepted...\n"); nodes = (Node**)safeMalloc(sizeof(Node*)*numNodes); #ifdef _DEBUG printMemSize(); #endif lines = (Line**)safeMalloc(sizeof(Line*)*numLines); #ifdef _DEBUG printMemSize(); #endif printf("Creating grid..."); createGrid(); printf("Done\n"); #ifdef _DEBUG printMemSize(); #endif //create mines /*placeMine(getNode(2,0),getNode(3,0)); placeMine(getNode(2,1),getNode(3,1)); placeMine(getNode(2,2),getNode(3,2)); placeMine(getNode(2,3),getNode(3,3)); placeMine(getNode(2,4),getNode(3,4));*/ printf("Finding Path... CPs: %ld and %ld\n",start,end); startStopwatch(); path = findShortestRoute(getNodeFromControlPost(start),getNodeFromControlPost(end),&count); printf("Finding the path took %0.4lf seconds.\n",stopStopwatch()); printf("Path length: %ld\n",count); for(i=0;i<count;i++){ printf("\tPath node #%ld at (x,y) => (%ld,%ld)\n",i,path[i]->x,path[i]->y); } #ifdef _DEBUG printMemSize(); #endif safeFree(path); #ifdef _DEBUG if(m<=20){ printField(); } saveField("final_field.txt"); #endif } else { printf("There were errors, can not proceed.\n"); } } #ifdef _DEBUG printMemSize(); #endif printf("Hit enter to exit\n"); //empty stdin and wait emptySTDIN(); getchar(); // return 0; }