Crash in Intel MPI_COMM_SPAWN_MULTIPLE - mpi

I getting a crash inside MPI_COMM_SPAWN_MULTIPLE when using the Intel MPI implementation and compiling the code with ifort. The same code works without a problem using OpenMPI and compiling with gfortran. The relevant code is posted below.
ALLOCATE(commands(num_processes - 1))
ALLOCATE(args(num_processes - 1,2))
ALLOCATE(info(num_processes - 1))
ALLOCATE(max_procs(num_processes - 1))
ALLOCATE(error_array(num_processes - 1))
commands = TRIM(context%cl_parser%command)
args(:,1) = temp_string
IF (num_threads .lt. 0) THEN
args(:,2) = '-para=-1'
ELSE IF (num_threads .lt. 10) THEN
WRITE (temp_string, 1001) num_threads
args(:,2) = TRIM(temp_string)
ELSE
WRITE (temp_string, 1002) num_threads
args(:,2) = TRIM(temp_string)
END IF
max_procs = 1
DO i = 2, num_processes
CALL MPI_INFO_CREATE(info(i - 1), error)
CALL MPI_INFO_SET(info(i - 1), "wdir", process_dir(i), &
& error)
END DO
CALL MPI_COMM_SPAWN_MULTIPLE(num_processes - 1, commands, args, &
& max_procs, info, 0, &
& MPI_COMM_WORLD, child_comm, &
& error_array, error)
CALL MPI_INTERCOMM_MERGE(child_comm, .false., &
& context%intra_comm, error)
DO i = 1, num_processes - 1
CALL MPI_INFO_FREE(info(i), error)
END DO
DEALLOCATE(info)
DEALLOCATE(max_procs)
DEALLOCATE(args)
DEALLOCATE(commands)
DEALLOCATE(error_array)

Related

What is the string compression algorithm?

I am reversing an old game for translate it, here is the compression algorithm , I want to know what algorithm this is.
the following is the python pseudocode
while True:
byte = rawdata[praw]
low_byte = byte & 0xF
high_byte = byte >> 4
for i in range(low_byte):
buffer[pbuffer] = rawdata[praw]
pbuffer += 1
praw += 1
for i in range(high_byte):
low_byte2 = rawdata[praw] & 0xF
high_byte2 = rawdata[praw] >> 4
p = pbuffer - low_byte - 1
for i in range(high_byte2):
buffer[pbuffer] = buffer[p]
pbuffer += 1
praw += 1
if low_byte or high_byte is 0, will call this function
def func(data):
# do...while...
while data is even number:
data = (data << 7) | rwadata[praw]
p += 1
if (data & 1) != 0:
break
return (data >> 1)

How to find a smallest value without trying all posibilities

I am trying to write a program (in Lua, but I guess this is more of a mathematical problem) that calculates the total distance between a set of numbers and there are two or three different possibilities for some of these numbers. 
For example a set of numbers is: 2, 5, 0, 1. The sum of distances in this case is 9. (5-2 + 5-0 + 1-0)
The first row with alternatives is: 5, -, 3, 2.
The second row with alternatives is: 3, -, -, 3
The combination between the two rows with the smallest sum of distances is: 5, 5, 3, 3 with a sum of distances of 2.
My first attempt was to write a program that tries all possible iterations, but with a set of about 40 numbers, there are so many possibilities that my computer crashed...
Here is the code for that version, it first creates all the different possibilities and then calculates the differences and places them in column 0. Afterwards I can find the smallest value easily and see also the combination of numbers which results in that value.
local table1 = {2, 5, 0 ,1}
local table2 = {5, nil, 3, 2}
local imax = 1
local solution = {}
local answer = table1[1]
for x = 1,#table1 do
solution[x]={}
for i= 1, (2^imax)/2 do
solution[x][i] = table1[x]
end
if table2[x] ~= nil then -- there is an alternative number
for y = 1, x-1 do -- copy all the previous table entries except the last one
for j = ((2^imax)/2)+1, 2^imax do -- the number of new rows increases exponentially
solution[y][j] = solution[y][j-imax]
end
end
for j = ((2^imax)/2)+1, 2^imax do -- create the new table entry with the alternative number
solution[x][j] = table2[x]
end
imax = imax + 1 -- this number is to remind how many alternative numbers where found
end
end
solution[0]={}
for x = 1, #table1 do
for i = 1, (2^imax)/2 do
if x < #table1 then answer = math.sqrt((solution[x+1][i]-solution[x][i])^2) else answer = 0 end
if solution[0][i] == nil then solution[0][i] = answer else solution[0][i] = solution[0][i] + answer end
end
end
After reading about dynamic programming, I wrote a new version of this program. It calculates the smallest sum of differences, but I also want to know the path (the combination of numbers) to that sum... Still work to do...
local table1 = {2, 5, 0 ,1}
local table2 = {5, nil, 3, 2}
local solution = {}
local smallestsolution = {}
solution[1]={}
solution[2]={}
solution[3]={}
solution[4]={}
for i = 1, (#table1-1) do
solution[1][i] = math.sqrt((table1[i+1]-table1[i])^2)
if table2[i] ~= nil then solution[2][i] = math.sqrt((table1[i+1]-table2[i])^2) end
if table2[i+1] ~= nil then solution[3][i] = math.sqrt((table2[i+1]-table1[i])^2) end
if table2[i] ~= nil and table2[i+1] ~= nil then solution[4][i] = math.sqrt((table2[i+1]-table2[i])^2) end
end
for i = 1, (#table1-1) do
smallestsolution[i]=100000
for j = 1, 4 do
if solution[j][i] ~= nil and solution[j][i] < smallestsolution[i] then smallestsolution[i]=solution[j][i] end
end
end
local smallestsum = 0
for i = 1, (#table1-1) do
smallestsum = smallestsum + smallestsolution[i]
end
Thanks,
Emile
I managed to solve it myself! The hint to dynamic programming by #EgorSkriptunoff did the trick!
local table1 = {2, 5, 0 ,1}
local table2 = {5, nil, 3, 2}
local solution = {}
local smallestsolution = {}
solution[1]={}
solution[2]={}
solution[3]={}
solution[4]={}
local path = {}
local temp = {}
for i = 1, (#table1-1) do
solution[1][i] = math.sqrt((table1[i+1]-table1[i])^2)
if table2[i] ~= nil then solution[2][i] = math.sqrt((table1[i+1]-table2[i])^2) end
if table2[i+1] ~= nil then solution[3][i] = math.sqrt((table2[i+1]-table1[i])^2) end
if table2[i] ~= nil and table2[i+1] ~= nil then solution[4][i] = math.sqrt((table2[i+1]-table2[i])^2) end
end
for i = 1, (#table1-1) do
smallestsolution[i]=100000
temp[i] = 0
for j = 1, 4 do
if solution[j][i] ~= nil and solution[j][i] < smallestsolution[i] then smallestsolution[i]=solution[j][i] temp[i] = j end
end
end
local smallestsum = 0
for i = 1, (#table1-1) do
smallestsum = smallestsum + smallestsolution[i]
end
for i = 1, (#table1) do -- find the path belonging to the smallest sum of differences
if temp[i] == 1 then path[i] = table1[i] end
if temp[i] == 2 then path[i] = table2[i] end
if temp[i] == 3 then path[i] = table1[i] end
if temp[i] == 4 then path[i] = table2[i] end
if i == (#table1) then
if temp[i-1] == 1 then path[i] = table1[i] end
if temp[i-1] == 2 then path[i] = table1[i] end
if temp[i-1] == 3 then path[i] = table2[i] end
if temp[i-1] == 4 then path[i] = table2[i] end
end
end

Error in R Markdown (non-numeric argument to binary operator)

I only get this error in attempting to knit in R Markdown to a Word document. The code runs fine elsewhere (in the Rscript).Also I have already had previous code showing:
numericScores = transform(correctedScores, beer2_score = as.numeric(beer2_score))
numericScores = transform(correctedScores, beer3_score = as.numeric(beer3_score))
numericScores = transform(correctedScores, beer4_score = as.numeric(beer4_score))
numericScores = transform(correctedScores, beer5_score = as.numeric(beer5_score))
numericScores = transform(correctedScores, beer6_score = as.numeric(beer6_score))
# testing to see if they are indeed numeric
sapply(numericScores, mode)
correctedGuesses = Guesses[complete.cases(Guesses), ]
str(correctedGuesses)
correctedGuesses
correctedScores = numericScores[complete.cases(numericScores), ]
str(correctedScores)
correctedScores
########
# trying to put scores in correct order
# first I will label the beers with their names
for(i in 1:45){
for(j in 2:7) {
if (Order[i,j] == 1) { Order[i, j] = "Miller"}
if (Order[i,j] == 2) { Order[i, j] = "Natural"}
if (Order[i,j] == 3) { Order[i, j] = "Keystone"}
if (Order[i,j] == 4) { Order[i, j] = "Busch"}
if (Order[i,j] == 5) { Order[i, j] = "Bud"}
if (Order[i,j] == 6) { Order[i, j] = "Miller"}
}
}
# Deleting the unused/unavailable Order rows
Order = Order[-c(4, 33),]
Miller_sc = 0
Natural_sc = 0
Keystone_sc = 0
Busch_sc = 0
Bud_sc = 0
B = c(
Miller_sc,
Natural_sc,
Keystone_sc,
Busch_sc,
Bud_sc )
for (i in 1:43) {
for (j in 2:7) {
if (Order[i,j] == "Miller") {B[1] = B[1] + correctedScores[i,j]}
if (Order[i,j] == "Natural") {B[2] = B[2] + correctedScores[i,j]}
if (Order[i,j] == "Keystone") {B[3] = B[3] + correctedScores[i,j]}
if (Order[i,j] == "Busch") {B[4] = B[4] + correctedScores[i,j]}
if (Order[i,j] == "Bud") {B[5] = B[5] + correctedScores[i,j]}
}
}
The error reads:
Error in B[3] + correctedScores[i, j]: non-numeric argument to binary
operator Calls: ... handle ->withCallingHandlers ->
withVisible -> eval -> eval Execution halted
The usual reason for an error like this is that the code in your document refers to a variable in your global environment. When you knit the document, it can't see that variable, so you get an error.
Most commonly that error would be some variation on "variable not found". You're getting a different error, so R is finding a variable with the right name somewhere else.
Without the full document, we can't tell you for sure what variable would be causing your problems. When I take a quick look at your script, I see these variables with no definitions:
correctedScores
beer2_score # etc., though these might be columns in correctedScores
Guesses
Order
I also notice that the first 4 lines of your script do nothing, since the 5th line overwrites their result.

Error .. missing value where TRUE/FALSE needed

I have been trying to run this code (below here) and I have gotten that message "Error in if (temp[ii] == 0) { : missing value where TRUE/FALSE needed"...
temp = c(2.15, 3.5, 0, 0, 0, 1.24, 5.42, 6.87)
tm = length(temp)
for (i in 1:tm){
if (temp[i] == 0) {
counter3 = 1
last = temp[i - 1]
for (ii in i + 1:tm){
if (temp[ii] == 0) {
counter3 = counter3 + 1
}
if (temp[ii] != 0) {
nxt = temp[i + counter3]
}
}
}
}
Your problem is that temp[ii] is returning NA because ii goes out of bounds:
ii = i + 1:tm #Your declaration for ii
ii = 1:tm + 1:tm #Evaluates to
So ii will definitely be larger than tm (and therefore length(temp) at some point.
In order to better understand/debug for loops, consider printing just the indices:
for(i in 1:tm)
{
print(i)
for(ii in i + 1:tm)
print(ii)
}
At a guess I'm going to say that this is in R - if so I'm guessing that this line:
if (temp[i] == 0) (or temp[ii] == 0)
is resulting in an NA, and if conditions must have a TRUE or FALSE value.
Using a debugger if you can, I'd interrogate the value of temp[i] before the if block.
Difficult without knowing the language, but i think the issue is that the value in ii can be greater than the length of temp when i is at its upper bound. I'd have expected an index out of range or something similar but, without knowing the language, who knows! Hope you get your problem fixed.

AutoIt: Find window under mouse pointer

I'm using AutoIt3 and I need a way for the user to select a window. The fastest method is, in my opinion, having them point to a window. So the question is, how do I see what window is under their mouse pointer?
I extrapolated this from some code I had laying around for selecting areas on the screen. This will just pop up the Window title thats under the mouse (hit Escape to exit the loop):
#include <WinAPI.au3>
#include <Misc.au3>
Func _WindowFromPoint($iX,$iY)
Local $stInt64,$aRet,$stPoint=DllStructCreate("long;long")
DllStructSetData($stPoint,1,$iX)
DllStructSetData($stPoint,2,$iY)
$stInt64=DllStructCreate("int64",DllStructGetPtr($stPoint))
$aRet=DllCall("user32.dll","hwnd","WindowFromPoint","int64",DllStructGetData($stInt64,1))
If #error Then Return SetError(2,#error,0)
If $aRet[0]=0 Then Return SetError(3,0,0)
Return $aRet[0]
EndFunc
Local $hControl, $hWin, $hOldWin, $aMousePos
$hOldWin = ""
While Not _IsPressed("1B")
$aMousePos = MouseGetPos()
$hControl=_WindowFromPoint($aMousePos[0],$aMousePos[1])
; Since _WindowFromPoint() can return 'sub' windows, or control handles, we should seek the owner window
$hWin=_WinAPI_GetAncestor($hControl,2)
If $hWin <> $hOldWin Then
TrayTip("Window Info","Window under mouse = " & WinGetTitle($hWin), 1)
$hOldWin = $hWin
EndIf
Sleep(10)
WEnd
Here's a complete example of a full screen GUI, displaying the actual screen and a border around the window that's topmost under the mouse pointer. This function is used to write the Title of the window to console.
#include <Misc.au3>
#include <Array.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>
HotKeySet("{Esc}", "_Exit")
Func _Exit()
Exit 0
EndFunc
Global $xPosReminder, $yPosReminder
$dll = DllOpen("user32.dll")
$allWindows = WinList()
; exclude invisible windows from winlist
Dim $windows[1]
$windows[0] = 0
For $i = 1 to $allWindows[0][0]
; only fetches visible windows
If BitAnd(WinGetState($allWindows[$i][1]), 2) Then;AND $allWindows[$i][0] <> "" Then
ReDim $windows[$windows[UBound($windows) - 1] + 2]
$windows[UBound($windows) - 1] = $windows[UBound($windows) - 2] + 1
$windows[UBound($windows) - 2] = $allWindows[$i][1]
EndIf
Next
ReDim $windows[$windows[UBound($windows) - 1]]
_ArrayReverse($windows)
; capture screen without cursor
$pos = MouseGetPos()
MouseMove(#DesktopWidth, #DesktopHeight, 0)
$hBitmap = _ScreenCapture_Capture ("")
MouseMove($pos[0], $pos[1], 0)
; create and show new fullscreen gui
$hGUI = GUICreate("", #DesktopWidth, #DesktopHeight, 0, 0, $WS_POPUP)
GUISetState(#SW_SHOW)
; Initialize GDI+ library
_GDIPlus_StartUp()
$hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 3, 2)
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 0, 0)
Global $oldWindow = 0
; Wait for Click
While True
If _IsPressed("01", $dll) Then ; left mouse button
$xPos = MouseGetPos(0)
$yPos = MouseGetPos(1)
ExitLoop
EndIf
If __MouseMoved() Then
; Erzeugt eine Kopie einer 24 bit Bitmap
$hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF24RGB)
$currentWindow = __GetWindowByMousePosition($windows, MouseGetPos(0), MouseGetPos(1))
If $currentWindow <> $oldWindow Then
$windowPosition = WinGetPos($currentWindow)
; reduce position and size to desktop space
$windowPosition[0] = _Iif($windowPosition[0] < 0, 0, $windowPosition[0])
$windowPosition[1] = _Iif($windowPosition[1] < 0, 0, $windowPosition[1])
$windowPosition[2] = _Iif($windowPosition[2] > #DesktopWidth, #DesktopWidth, $windowPosition[2])
$windowPosition[3] = _Iif($windowPosition[3] > #DesktopHeight, #DesktopHeight, $windowPosition[3])
_GDIPlus_GraphicsDrawImage($hGraphics, $hClone, 0, 0)
_GDIPlus_GraphicsDrawRect($hGraphics, $windowPosition[0], $windowPosition[1], $windowPosition[2], $windowPosition[3], $hPen)
$oldWindow = $currentWindow
EndIf
EndIf
Sleep(1)
WEnd
; Free Ressources
_GDIPlus_PenDispose($hPen)
_GDIPlus_BitmapDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphics)
_WinAPI_DeleteObject($hBitmap)
_GDIPlus_ShutDown()
DllClose($dll)
GUISetState(#SW_HIDE)
Func __GetWindowByMousePosition($windows, $xPos, $yPos)
Local $currentWindow = 0
For $i = 0 to UBound($windows) - 1
$pos = WinGetPos($windows[$i])
If $xPos >= $pos[0] AND $xPos <= $pos[0] + $pos[2] AND $yPos >= $pos[1] AND $yPos <= $pos[1] + $pos[3] Then
$currentWindow = $windows[$i]
EndIf
Next
Return $currentWindow
EndFunc
Func __MouseMoved()
Local $actualPos = MouseGetPos()
If $xPosReminder <> $actualPos[0] OR $yPosReminder <> $actualPos[1] Then
$xPosReminder = $actualPos[0]
$yPosReminder = $actualPos[1]
Return True
Else
Return False
EndIf
EndFunc
ConsoleWrite(WinGetTitle(__GetWindowByMousePosition($windows, $xPos, $yPos)) & #CR)

Resources