chiark / gitweb /
add nprocessors utility
authorIan Jackson <ian@davenant.relativity.greenend.org.uk>
Sat, 27 Sep 2008 15:02:47 +0000 (16:02 +0100)
committerIan Jackson <ian@davenant.relativity.greenend.org.uk>
Sat, 27 Sep 2008 15:02:47 +0000 (16:02 +0100)
Makefile
nprocessors.c [new file with mode: 0644]

index b41c543b25f800691cda9c7b3c198b39a76faea8..d3ddd4f8facfc7bb21bb85d9963aec99bc643d0f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,6 +31,9 @@ minimise:     energy.o graph.o common.o mgraph.o minimise.o half.o
 primer:                primer.o common.o
                $(CC) $(CFLAGS) -o $@ $^ $(LIBGSL)
 
+nprocessors:   nprocessors.o common.o
+               $(CC) $(CFLAGS) -o $@ $^ $(LIBGSL)
+
 prime.data:    primer
                ./$^ $o
 
diff --git a/nprocessors.c b/nprocessors.c
new file mode 100644 (file)
index 0000000..b15bf8e
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * prints number of processors
+ */
+
+#include <unistd.h>
+
+#include "common.h"
+
+int main(int argc, char **argv) {
+  if (argc!=1) fail("usage: nprocessors\n");
+  long sc= sysconf(_SC_NPROCESSORS_ONLN);
+  if (sc==-1) diee("nprocessors: sysconf failed");
+  printf("%ld\n",sc);
+  flushoutput();
+  return 0;
+}