- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am developing a program that currently uses maxval(x) and maxloc(x) in sequence operating on the same large array x. This is looped many times with interdependence between loops.
I am wondering if either of the following two are possible:
(1) The compiler automatically (mpif90 -O3 -ipo ...) recognizes that it only needs to perform the search operations to find the maximum of x once and records both its value and location.
(2) There is some other function in the MKL or elsewhere that will do both of these tasks at once.
If (1) is not true then it seems I could cut my computation time by almost half if something like (2) exists!
many thanks,
Brant
I am developing a program that currently uses maxval(x) and maxloc(x) in sequence operating on the same large array x. This is looped many times with interdependence between loops.
I am wondering if either of the following two are possible:
(1) The compiler automatically (mpif90 -O3 -ipo ...) recognizes that it only needs to perform the search operations to find the maximum of x once and records both its value and location.
(2) There is some other function in the MKL or elsewhere that will do both of these tasks at once.
If (1) is not true then it seems I could cut my computation time by almost half if something like (2) exists!
many thanks,
Brant
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Find maxloc(x) first. The optimal method for then finding maxval(x) is left as an exercise for the reader.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
duh ..... :)
Thanks!
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
More interesting questions
(a) finding both the minimum value and the maximum value
(b) finding both the mimimum absolute value and the maximum absolute value
For an array of size N, either of these can be performed in O (3N/2) comparisons rather than the 2N that would be used if each value were found by a separate search.
(a) finding both the minimum value and the maximum value
(b) finding both the mimimum absolute value and the maximum absolute value
For an array of size N, either of these can be performed in O (3N/2) comparisons rather than the 2N that would be used if each value were found by a separate search.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting mecej4
More interesting questions
(a) finding both the minimum value and the maximum value
(b) finding both the mimimum absolute value and the maximum absolute value
For an array of size N, either of these can be performed in O (3N/2) comparisons rather than the 2N that would be used if each value were found by a separate search.
(a) finding both the minimum value and the maximum value
(b) finding both the mimimum absolute value and the maximum absolute value
For an array of size N, either of these can be performed in O (3N/2) comparisons rather than the 2N that would be used if each value were found by a separate search.
Depending on how well SSE/AVX is utilized, the number of comparisons can be reduced by a factor of 2, 4, 8
The (minimum value + index) and (maximum value + index) is a little more interesting in SSE. The same mask that is used on the values can also be used on a seperate SSE/AVX register containing the current multiple indicies of the values.
Jim Dempsey

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page