Skip to content

Commit

Permalink
PyWolf v.3.0.0
Browse files Browse the repository at this point in the history
Added multithread-based parallelism support
  • Loading branch information
tiagoecmagalhaes committed Nov 16, 2024
1 parent 552dd0b commit 8297940
Show file tree
Hide file tree
Showing 19 changed files with 1,646 additions and 188 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Please see the following articless for more technical details:

- https://doi.org/10.1016/j.cpc.2022.108336
- https://arxiv.org/abs/2203.02734
- https://doi.org/10.1016/j.cpc.2023.108899



If you find this software useful for your research, please cite:

> Tiago E.C. Magalhães, José M. Rebordão, "PyWolf: A PyOpenCL implementation for simulating the propagation of partially coherent light", Computer Physics Communications, Volume 276, 2022, 108336. [DOI](https://doi.org/10.1016/j.cpc.2022.108336)
> Tiago E.C. Magalhães, Daniela O. Santos, "A new version of PyWolf for the propagation of partially coherent light in media other than free space", Computer Physics Communications, Volume 294, 2024. [DOI](https://doi.org/10.1016/j.cpc.2023.108899)
## Support
Expand Down
51 changes: 34 additions & 17 deletions app_functions/startSim.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#-------------------------------------------------------------------------------
# Name: StartSim
# Purpose: PyWolf function to Start the Simulation of Partially Coherent Light Propagation
# Version: 2.0.0
# Version: 3.0.0
#
# Author: Tiago E. C. Magalhaes
#
Expand Down Expand Up @@ -116,8 +116,11 @@ def func_startSim(ui,all_parameters):
N = int(all_parameters[0][4][0])
NZ = int(all_parameters[0][4][2])
M = int(N/2)
useThread = int(all_parameters[0][4][3])
numThreads = int(all_parameters[0][4][4])
useFFTzeroPadding = int(all_parameters[0][4][1])
FFTpad_list = [useFFTzeroPadding, NZ]
FFTpad_list = [useFFTzeroPadding, NZ]
useThreads_list = [useThread, numThreads]
NS = None
if useFFTzeroPadding:
NS = NZ
Expand Down Expand Up @@ -614,6 +617,8 @@ def func_startSim(ui,all_parameters):
#_______________________________________________________________




#---------------------------------------------------------------
# Q functions
#---------------------------------------------------------------
Expand All @@ -636,15 +641,27 @@ def func_startSim(ui,all_parameters):
#---------------------------------------------------------------
# 1st FFTs
#---------------------------------------------------------------


ui.update_outputText("Performing 1st 2D Fourier transforms...")
ui.update_outputText("___")
for i1 in range(0,N):
ui.update_outputTextSameLine(str(round(i1*100./N,1))+"% concluded ("+str(i1)+"/"+str(N-1)+").")
for j1 in range(0,N):
if count_nonzero(ui.CSDA_prop.matrix[i1,j1].real)==0:
pass
else:
ui.CSDA_prop.matrix[i1,j1] = func_fft2d(ui,ui.CSDA_prop.matrix[i1,j1],False,FFTpad_list)
##ui.update_outputText("___")

if count_nonzero(ui.CSDA_prop.matrix)==0:
pass
else:
ui.CSDA_prop.matrix = func_fft2d(ui,ui.CSDA_prop.matrix, useThreads_list, False, FFTpad_list)

'''
for i in range(0, N):
if count_nonzero(ui.CSDA_prop.matrix[i].real)==0:
pass
else:
ui.update_outputTextSameLine(str(round(i*100./N,1))+"% concluded ("+str(i)+"/"+str(N-1)+").")
ui.CSDA_prop.matrix[i] = func_fft2d(ui,ui.CSDA_prop.matrix[i],False,FFTpad_list)
'''

ui.update_outputTextSameLine("\r"+str(round(100.0,1))+"% concluded")
ui.update_outputText("2D Fourier transforms completed!")
#_______________________________________________________________
Expand All @@ -665,13 +682,13 @@ def func_startSim(ui,all_parameters):

ui.update_outputText("Performing 2nd 2D Fourier transforms...")
ui.update_outputText("___")
for i1 in range(0,N):
ui.update_outputTextSameLine(str(round(i1*100./N,1))+"% concluded ("+str(i1)+"/"+str(N-1)+").")
for j1 in range(0,N):
if count_nonzero(ui.CSDA_prop.matrix[i1,j1])==0:
pass
else:
ui.CSDA_prop.matrix[i1,j1]=func_fft2d(ui,ui.CSDA_prop.matrix[i1,j1],True,FFTpad_list)


if count_nonzero(ui.CSDA_prop.matrix)==0:
pass
else:
ui.CSDA_prop.matrix = func_fft2d(ui,ui.CSDA_prop.matrix,useThreads_list, True, FFTpad_list)

ui.update_outputTextSameLine("\r"+str(round(100.0,1))+"% concluded")
ui.update_outputText("2D Fourier transforms completed!")

Expand Down
3 changes: 1 addition & 2 deletions app_functions/testPars.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def func_testPars(ui):
pyopencl_list = [ui.checkBox_pyopencl.isChecked(),ui.comboBox_platform.currentIndex(),ui.comboBox_device.currentIndex()]
save_list = [ui.checkBox_save.isChecked(),ui.saveDirName,ui.checkBox_saveSourceCSDA.isChecked(),ui.checkBox_savePropCSDA.isChecked()]
debug_list = [ui.checkBox_debug.isChecked()]
matrix_list = [ui.lineEdit_N.text(),ui.checkBox_FFT.isChecked(), ui.lineEdit_NZ.text()]
matrix_list = [ui.lineEdit_N.text(),ui.checkBox_FFT.isChecked(), ui.lineEdit_NZ.text(), ui.checkBox_useThread.isChecked(), int(ui.spinBox_numThreads.text())]
##schedule = [ui.checkBox_schedule.isChecked(),ui.dateTimeEdit.text()]
options_list = [nameTime_list, pyopencl_list,save_list,debug_list,matrix_list]

Expand Down Expand Up @@ -499,7 +499,6 @@ def func_testPars(ui):
#___________________________________________________________________________



# OK
ui.update_outputText("All parameters are OK.")

Expand Down
2 changes: 2 additions & 0 deletions docs_/v3.0.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PyWolf v3.0.0
• Multithreading option added.
2 changes: 1 addition & 1 deletion examples/Far-field_AnnularSource.wolf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PyWolf v2.0.0
PyWolf v3.0.0
Far-field of an annular source
[04/01/2022 15:44:10]
True
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PyWolf v2.0.0
PyWolf v3.0.0
Gaussian Schell-model beam
[10/08/2023 15:56:55]
True
Expand Down
2 changes: 1 addition & 1 deletion examples/Gaussian Schell-model beam.wolf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PyWolf v2.0.0
PyWolf v3.0.0
Gaussian Schell-model beam
[11/01/2022 15:42:46]
True
Expand Down
2 changes: 1 addition & 1 deletion examples/Imaging Partially Coherent Light.wolf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PyWolf v2.0.0
PyWolf v3.0.0
Imaging Partially Coherent Light
[11/01/2022 15:43:07]
True
Expand Down
2 changes: 1 addition & 1 deletion examples/Square_Fresnel.wolf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PyWolf v2.0.0
PyWolf v3.0.0
Square Source - Fresnel propagation
[11/01/2022 15:43:26]
True
Expand Down
2 changes: 1 addition & 1 deletion examples/Sunlight.wolf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PyWolf v2.0.0
PyWolf v3.0.0
Sunlight
[11/01/2022 15:43:35]
True
Expand Down
53 changes: 43 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""
PyWolf version 2.0.2
PyWolf version 3.0.0
*
Software to perform simulations of the propagation of partially coherent light
using parallel computing devices through PyOpenCL
*
Tiago E. C. Magalhaes
2023
2024
"""


Expand Down Expand Up @@ -35,6 +34,9 @@
# PyOpenCL
import pyopencl

# threading
import threading

# OS
import os
from os import getcwd, chdir
Expand Down Expand Up @@ -86,7 +88,7 @@ def setupUi(self, MainWindow,appname,rect,current_dir,log_txt,output_txt):
# parameters
#=======================================================================
# version
self.version = "PyWolf v2.0.2"
self.version = "PyWolf v3.0.0"

# simulation successful
self.sim = False
Expand Down Expand Up @@ -122,6 +124,7 @@ def setupUi(self, MainWindow,appname,rect,current_dir,log_txt,output_txt):
#///////////////////////////////////////////////////////////////////////
#=======================================================================


#=======================================================================
# Main Window
#=======================================================================
Expand Down Expand Up @@ -683,6 +686,8 @@ def setupUi(self, MainWindow,appname,rect,current_dir,log_txt,output_txt):
#-----------------------------------------------------------------------
# Spin Box
#-----------------------------------------------------------------------

# Number of Planes
self.spinBox_numPlanes = QtWidgets.QSpinBox(self.scrollAreaWidgetContents_numPlanes)
self.spinBox_numPlanes.setObjectName("spinBox_numPlanes")
self.spinBox_numPlanes.setFont(font_normalLabel)
Expand All @@ -691,6 +696,17 @@ def setupUi(self, MainWindow,appname,rect,current_dir,log_txt,output_txt):
self.spinBox_numPlanes.setMaximumWidth(int(size_spinBox(self)))
self.gridLayout_7.addWidget(self.spinBox_numPlanes, 64, 1, 1, 1)
self.spinBox_numPlanes.valueChanged.connect(self.update_numPlanes)


# Number of Threads
self.spinBox_numThreads = QtWidgets.QSpinBox(self.scrollAreaWidgetContents_FFT)
self.spinBox_numThreads.setObjectName("spinBox_numPlanes")
self.spinBox_numThreads.setFont(font_normalLabel)
self.spinBox_numThreads.setMinimum(1)
self.spinBox_numThreads.setMaximum(psutil.cpu_count())
self.spinBox_numThreads.setMaximumWidth(int(size_spinBox(self)))
self.gridLayout_FFT.addWidget(self.spinBox_numThreads, 1, 1, 1, 1)
#self.spinBox_numPlanes.valueChanged.connect(self.update_numPlanes)
#_______________________________________________________________________


Expand Down Expand Up @@ -912,13 +928,21 @@ def setupUi(self, MainWindow,appname,rect,current_dir,log_txt,output_txt):
self.gridLayout_7.addWidget(self.label_N, 15, 0, 1, 1)

# Label NZ
self.label_NZ = QtWidgets.QLabel(self.scrollAreaWidgetContents_numPlanes)
self.label_NZ = QtWidgets.QLabel(self.scrollAreaWidgetContents_FFT)
self.label_NZ.setFont(font_normalLabel)
self.label_NZ.setObjectName("label_NZ")
self.gridLayout_FFT.addWidget(self.label_NZ, 1, 0, 1, 1)
self.gridLayout_FFT.addWidget(self.label_NZ, 4, 0, 1, 1)
self.label_NZ.setText("Total matrix size (>N): ")
self.label_NZ.setVisible(False)

# Label Number of Threads
self.label_numThreads = QtWidgets.QLabel(self.scrollAreaWidgetContents_FFT)
self.label_numThreads.setPalette(palette_parSection)
self.label_numThreads.setFont(font_normalLabel)
self.label_numThreads.setObjectName("label_numThreads")
self.label_numThreads.setText("Number of Threads: ")
self.gridLayout_FFT.addWidget(self.label_numThreads, 1, 0, 1, 1)

# label Propagation Quantities (title)
self.label_PropagationQuantities = QtWidgets.QLabel(self.scrollAreaWidgetContents_numPlanes)
self.label_PropagationQuantities.setPalette(palette_titles)
Expand Down Expand Up @@ -1343,7 +1367,7 @@ def setupUi(self, MainWindow,appname,rect,current_dir,log_txt,output_txt):
self.lineEdit_NZ.setFont(font_normalLabel)
self.lineEdit_NZ.setObjectName("lineEdit_NZ")
self.lineEdit_NZ.setStyleSheet('background: '+colortxt_textEdit)
self.gridLayout_FFT.addWidget(self.lineEdit_NZ, 1, 1, 1, 1)
self.gridLayout_FFT.addWidget(self.lineEdit_NZ, 4, 1, 1, 1)
self.lineEdit_NZ.setMaximumWidth(int(size_entries(self)))
self.lineEdit_NZ.setText("256")
self.lineEdit_NZ.setVisible(False)
Expand Down Expand Up @@ -1555,11 +1579,20 @@ def setupUi(self, MainWindow,appname,rect,current_dir,log_txt,output_txt):
# setting checked by default
self.checkBox_pyopencl.setChecked(True)

# checkbox use fft
self.checkBox_useThread = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_FFT)
self.checkBox_useThread.setFont(font_normalLabel)
self.checkBox_useThread.setObjectName("checkBox_FFT")
self.gridLayout_FFT.addWidget(self.checkBox_useThread, 0, 0, 1, 1)
self.checkBox_useThread.setChecked(False)
self.checkBox_useThread.setText("Use Multithreading?")
##self.checkBox_useFFT.stateChanged.connect(self.zeroPadingOptions)

# checkbox fft zero padding
self.checkBox_FFT = QtWidgets.QCheckBox(self.scrollAreaWidgetContents_FFT)
self.checkBox_FFT.setFont(font_normalLabel)
self.checkBox_FFT.setObjectName("checkBox_FFT")
self.gridLayout_FFT.addWidget(self.checkBox_FFT, 0, 0, 1, 1)
self.gridLayout_FFT.addWidget(self.checkBox_FFT, 2, 0, 1, 1)
self.checkBox_FFT.setChecked(False)
self.checkBox_FFT.setText("Use FFT Zero Padding?")
self.checkBox_FFT.stateChanged.connect(self.zeroPadingOptions)
Expand Down Expand Up @@ -2303,7 +2336,7 @@ def create_action(self, text, slot=None, shortcut=None,icon=None, tip=None, chec


def on_about(self):
msg = """ PyWolf version 1.0.1
msg = """ PyWolf version 3.0.0
This software is licensed to you under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Expand Down Expand Up @@ -2663,7 +2696,7 @@ def close_application(self):
# initial parameters
log_txt = "" # log file
debug = False
appname = "PyWolf v2.0.2"
appname = "PyWolf v3.0.0"
cr = "Copyright (C) 2020 Tiago E. C. Magalhaes under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version."

# time
Expand Down
Loading

0 comments on commit 8297940

Please sign in to comment.