Help me generate script run with real multithread Topic is solved

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
gameba
Posts: 18
Joined: 20 Mar 2018, 12:24

Help me generate script run with real multithread

25 Mar 2018, 05:58

I created a script to help me find duplicate images in my image database(>1000000 images). pls, view code below:

Code: Select all

#NoEnv
SetBatchLines, -1
Process, Priority,, High
#Include Gdip_All.ahk
#Include Gdip_ImageSearch.ahk
gdipToken := Gdip_Startup()
START:=A_TickCount
Loop 1000000
{
	A:=A_Index
	Loop % 1000001-A
	{
		B:=A_Index+A
		link:="G:\data\img" A ".png"
		linkb:="G:\data\img" B ".png"
		bmpHaystack := Gdip_CreateBitmapFromFile(link)
		bmpNeedle := Gdip_CreateBitmapFromFile(linkb)
		RET := Gdip_ImageSearch(bmpHaystack,bmpNeedle,LIST,0,0,0,0,4,0,1,1)
		;OutputDebug % RET
		Gdip_DisposeImage(bmpHaystack)
		Gdip_DisposeImage(bmpNeedle)
		If(RET>0){
			Msgbox % A "," B
		}
	}
}
Gdip_Shutdown(gdipToken)
END:=A_TickCount
OutputDebug % "THREAR4:" END-START
return
The script works fine.

I have a cpu intel core i7 4.8GHz 4core 8thread but I checked task manager, the script always use 14% cpu (86% idle). It does not work at full capacity because AHK not support multithread. So, I found AHK_H, I am a newbie, I don't have many experiments with AHK_H. I played with AHK_H 2 days but I don't know how to my script run with real multithreads.

Somebody can help me generate the script run with real multithread.
Thanks!
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Help me generate script run with real multithread  Topic is solved

25 Mar 2018, 08:29

Try something like this:

Code: Select all

threads:=[]
Loop 8
threads[A_Index]:=AhkThread("
(
SetBatchLines, -1
gdipToken := Gdip_Startup()
#Include Gdip_All.ahk
#Include Gdip_ImageSearch.ahk
run:
	running:=true
	bmpHaystack := Gdip_CreateBitmapFromFile(link)
	bmpNeedle := Gdip_CreateBitmapFromFile(linkb)
	RET := Gdip_ImageSearch(bmpHaystack,bmpNeedle,LIST,0,0,0,0,4,0,1,1)
	;OutputDebug `% RET
	Gdip_DisposeImage(bmpHaystack)
	Gdip_DisposeImage(bmpNeedle)
	If(RET>0){
		Msgbox,0,Error, `% A "","" B
	}
	running:=false
Return
OnExit:
Gdip_Shutdown(gdipToken)
ExitApp
)")
Process, Priority,, High
START:=A_TickCount
Loop 1000000
{
	A:=A_Index
	Loop % 1000001-A
	{
		B:=A_Index+A
		link:="G:\data\img" A ".png"
		linkb:="G:\data\img" B ".png"
		i:=0
		Loop
			if !(thread:=threads[(8<++i)?i:=1:i]).ahkgetvar("running"){
				thread.ahkassign("link",link),thread.ahkassign("linkb",linkb),thread.ahkLabel("run",1)
				break
			}
	}
}
END:=A_TickCount
MsgBox  % "THREAR4:" END-START
return
gameba
Posts: 18
Joined: 20 Mar 2018, 12:24

Re: Help me generate script run with real multithread

25 Mar 2018, 08:53

@HotKeyIt, Thank you for your reply
I tried it and received a error
Image


I use window10 64bit, I installed AHK version: v1.1.28.00 - February 11, 2018 64bit and download AHK_H V2 alpha.

I copy all file (AutoHotkey.dll, AutoHotkey.exe, msvcr100.dll) in folder "x64w" and paste to "C:\Program Files\AutoHotkey" , I continues copy 2 folder "Compiler", "lib" and paste to "C:\Program Files\AutoHotkey". Is it the right way to install AHK_H V2 alpha?
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Help me generate script run with real multithread

25 Mar 2018, 09:57

Yes but the script above is for AutoHotkey_H v1, your picture is not displayed unfortunately, can you type down the error?
gameba
Posts: 18
Joined: 20 Mar 2018, 12:24

Re: Help me generate script run with real multithread

25 Mar 2018, 10:03

HotKeyIt wrote:Yes but the script above is for AutoHotkey_H v1, your picture is not displayed unfortunately, can you type down the error?
sorry, I forget set public image :D
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Help me generate script run with real multithread

25 Mar 2018, 10:09

This error is due to using AutoHotkey_H v2, try using AutoHotkey_H v1. AFAIK your Gdip functions are also not compatible with v2, otherwise you need to use proper syntax for v2:
ProcessSetPriority("High"), also remove Setbatchlines.
guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Help me generate script run with real multithread

25 Mar 2018, 14:08

for reference, this GDIP library should work for v2:

https://github.com/mmikeww/AHKv2-Gdip

guest3456
Posts: 3462
Joined: 09 Oct 2013, 10:31

Re: Help me generate script run with real multithread

25 Mar 2018, 19:17

HotKeyIt wrote:What about Gdip_ImageSearch.ahk?
not included

gameba
Posts: 18
Joined: 20 Mar 2018, 12:24

Re: Help me generate script run with real multithread

25 Mar 2018, 20:11

HotKeyIt wrote:This error is due to using AutoHotkey_H v2, try using AutoHotkey_H v1. AFAIK your Gdip functions are also not compatible with v2, otherwise you need to use proper syntax for v2:
ProcessSetPriority("High"), also remove Setbatchlines.
You are god! you save my life. Now, I can maximise my CPU processor's efficiency . Thank you very much!

Image

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 14 guests