aboutsummaryrefslogtreecommitdiff
blob: 17485e0993a368853cd1a146da4f455170faa87e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: mpi-select.eclass
# @MAINTAINER:
# Michael Gilroy <michael.gilroy24@gmail.com>
# @BLURB: Allow mpi software to select mpi implementation of choice.

EXPORT_FUNCTIONS src_configure src_compile src_test src_install

case ${EAPI:-0} in
  6) ;;
  5) ;;
  *) die "mpi-select.eclass does not support EAPI ${EAPI}"
esac

# @ECLASS-VARIABLE: IMPLEMENTATION_LIST
# @INTERNAL
# @DESCRIPTION:
# List of used MPI implementation
IMPLEMENTATION_LIST="mpich mpich2 openmpi openib-mvapich2"

# @ECLASS-VARIABLE: INSTALLED_IMPLEMENTATIONS
# @INTERNAL
# @DESCRIPTION:
# List of used MPI implementation
INSTALLED_IMPLEMENTATIONS=get_all_implementations

# @ECLASS-VARIABLE: MPI_DIR
# @INTERNAL
# @DESCRIPTION:
# Location in which mpi software should be installed
MPI_DIR="/usr/$(get_libdir)/mpi"

# @ECLASS-FUNCTION: mpi-select_implementation_install
# @DESCRIPTION:
# Install MPI software with arbitrary implementations
mpi-select_implementation_install()
{
	# IGNORE THIS FOR NOW
    for implementation in "$@"
    do
        if [[ "${installed}" == *"${implementation}"* ]]; then
            mpi-select_src_configure "${implementation}"
            mpi-select_src_compile "${implementation}"
            mpi-select_src_install "${implementation}"
        else
            die "invalid implementation"
        fi
    done
}
# @ECLASS-FUNCTION: mpi-select_detect_installs
# @DESCRIPTION:
# See what MPI software is installed on the system
get_all_implemenetations()
{
    for dir in "${MPI_DIR}"/*
    do
        INSTALLED_IMPLEMENTATIONS="${INSTALLED_IMPLEMENTATIONS} ${dir}"
    done

    echo "${INSTALLED_IMPLEMENTATIONS}"
}

# @ECLASS-FUNCTION: mpi_foreach_implementation
# @DESCRIPTION:
# Iterates through each given implementation and repeats commands for each implementation
mpi_foreach_implementation()
{
	debug-print-function ${FUNCNAME} "${@}"	

	# [[ -z "${INSTALLED_IMPLEMENTATIONS}" ]] \
	#			die "No mpi implementations detected"

	local status=0

	for implementation in "${@}"
	do
		# iterate through implementations, repeat same commands for each variant
		if [[ "${IMPLEMENTATION_LIST}" ~= *"${implementation}"* ]]
			local BUILD_DIR="${WORKDIR}/build"
			
			# modeling after multibuild for testing & learning
			_mpi_run()
			{
				local i=1
				while [[ ${!1} == _* ]];do
					i+=1
				done

				[[ ${i} -le ${#} ]]
				einfo ${@}
				echo ${@}
			}
		else
			die "invalid implementation!"
		fi

	
	done

	echo "${status}"
}

# TODO: write src_configure/compile/test/
mpi-select_src_configure()
{
	debug-print-function "${FUNCNAME}" "${@}"

	mpi-select_abi_src_configure()
	{
		debug-print-function "${FUNCNAME}" "${@}"
		pushd "${BUILD_DIR}" > /dev/null || die
		if declare -f mpi_src_configure > /dev/null; then
			mpi_src_configure
		else
			default_src_configure	
		fi
		popd > /dev/null || die
	}

	mpi_foreach_implementation mpi-select_abi_src_configure
}

mpi-select_src_compile()
{
	debug-print-function "${FUNCNAME}" "${@}"

	mpi-select_abi_src_compile()
	{
		debug-print-function "${FUNCNAME}" "${@}"
		pushd "${BUILD_DIR}" > /dev/null || die
		if declare -f mpi_src_configure > /dev/null; then
			mpi_src_compile
		else
			default_src_configure	
		fi
		popd > /dev/null || die
	}

	mpi_foreach_implementation mpi-select_abi_src_compile
}

mpi-select_src_test()
{
	debug-print-function "${FUNCNAME}" "${@}"

	mpi-select_abi_src_test()
	{
		debug-print-function "${FUNCNAME}" "${@}"
		pushd "${BUILD_DIR}" > /dev/null || die
		if declare -f mpi_src_configure > /dev/null; then
			mpi_src_test
		else
			default_src_configure	
		fi
		popd > /dev/null || die
	}

	mpi_foreach_implementation mpi-select_abi_src_test
}

mpi-select_src_install()
{
	debug-print-function "${FUNCNAME}" "${@}"

	mpi-select_abi_src_install()
	{
		debug-print-function "${FUNCNAME}" "${@}"
		pushd "${BUILD_DIR}" > /dev/null || die
		if declare -f mpi_src_configure > /dev/null; then
			mpi_src_install_
		else
			default_src_configure	
		fi
		popd > /dev/null || die
	}
	mpi_foreach_implementation mpi-select_abi_src_install
}