[Ocfs2-test-devel] [PATCH 4/4] Ocfs2-test: Add mpi operation funcs for libocfs2.

Tristan Ye tristan.ye at oracle.com
Tue Mar 24 05:24:08 PDT 2009


Provide generic utility fuctions on mpi operations for ocfs2-tests.

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 programs/libocfs2test/mpi_ops.c |   77 +++++++++++++++++++++++++++++++++++++++
 programs/libocfs2test/mpi_ops.h |   41 +++++++++++++++++++++
 2 files changed, 118 insertions(+), 0 deletions(-)
 create mode 100644 programs/libocfs2test/mpi_ops.c
 create mode 100644 programs/libocfs2test/mpi_ops.h

diff --git a/programs/libocfs2test/mpi_ops.c b/programs/libocfs2test/mpi_ops.c
new file mode 100644
index 0000000..7c00a94
--- /dev/null
+++ b/programs/libocfs2test/mpi_ops.c
@@ -0,0 +1,77 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * mpi_ops.c
+ *
+ * Provide generic utility fuctions on mpi operations for ocfs2-tests
+ *
+ * Written by tristan.ye at oracle.com
+ *
+ * Copyright (C) 2008 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include "mpi_ops.h"
+
+extern int rank, size;
+extern char *hostname;
+
+extern void abort_printf(const char *fmt, ...)
+{
+	va_list ap;
+
+	printf("%s (rank %d): ", hostname, rank);
+	va_start(ap, fmt);
+	vprintf(fmt, ap);
+
+	MPI_Abort(MPI_COMM_WORLD, 1);
+}
+
+extern void root_printf(const char *fmt, ...)
+{
+	va_list ap;
+
+	if (rank == 0) {
+		va_start(ap, fmt);
+		vprintf(fmt, ap);
+	}
+}
+
+extern void MPI_Barrier_Sync(void)
+{
+	int ret;
+
+	ret = MPI_Barrier(MPI_COMM_WORLD);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Barrier failed: %d\n", ret);
+}
+
+extern int MPI_Setup(int argc, char *argv[])
+{
+	int ret;
+
+	ret = MPI_Init(&argc, &argv);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Init failed!\n");
+
+	if (gethostname(hostname, HOSTNAME_MAX_SZ) < 0)
+		abort_printf("Get hostname failed!\n");
+
+	ret = MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Comm_rank failed: %d\n", ret);
+
+	ret = MPI_Comm_size(MPI_COMM_WORLD, &size);
+	if (ret != MPI_SUCCESS)
+		abort_printf("MPI_Comm_size failed: %d\n", ret);
+
+	return 0;
+}
diff --git a/programs/libocfs2test/mpi_ops.h b/programs/libocfs2test/mpi_ops.h
new file mode 100644
index 0000000..d4fa008
--- /dev/null
+++ b/programs/libocfs2test/mpi_ops.h
@@ -0,0 +1,41 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * mpi_ops.h
+ *
+ * Copyright (C) 2008 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+#ifndef MPI_OPS_H
+#define MPI_OPS_H
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <inttypes.h>
+#include <linux/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include <mpi.h>
+
+#define HOSTNAME_MAX_SZ		100
+
+void abort_printf(const char *fmt, ...);
+void root_printf(const char *fmt, ...);
+void MPI_Barrier_Sync(void);
+int MPI_Setup(int argc, char *argv[]);
+
+#endif
-- 
1.5.5




More information about the Ocfs2-test-devel mailing list