Skip to content

Commit

Permalink
Merge pull request #11 from fabiocfabini/master
Browse files Browse the repository at this point in the history
preprocessing.py parallelized
  • Loading branch information
ricardoribeiro-2020 authored Jul 19, 2022
2 parents d26e858 + 437ffd7 commit 6cf4cb1
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions python/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
"""
__version__ = "v0.3"

from multiprocessing import Pool
from itertools import product

import os
import sys
import time
import xml.etree.ElementTree as ET
import numpy as np


import contatempo
import dft
from headerfooter import header, footer
Expand All @@ -32,6 +36,9 @@

# pylint: disable=C0103
###################################################################################
def compute_rpoints(l, k, i):
return A1 * i / NR1 + A2 * k / NR2 + A3 * l / NR3

if __name__ == "__main__":
header("PREPROCESSING", __version__, time.asctime())

Expand Down Expand Up @@ -336,15 +343,17 @@
# Final calculations #########################################
print()

COUNT = 0
RPOINT = np.zeros((NR, 3), dtype=float)
for l in range(NR3):
for k in range(NR2):
for i in range(NR1):
RPOINT[COUNT] = A1 * i / NR1 + A2 * k / NR2 + A3 * l / NR3
COUNT += 1
params = {
"NR3": range(NR3),
"NR2": range(NR2),
"NR1": range(NR1),
}


with Pool(processes=NPR) as pool:
RPOINT = np.array(pool.starmap(compute_rpoints, product(*params.values())))

PHASE = np.exp(1j * np.dot(RPOINT, np.transpose(KPOINTS)))
PHASE = np.exp(1j * np.dot(RPOINT, KPOINTS.T))

# Start saving data to files ##################################
with open("phase.npy", "wb") as fich:
Expand Down

0 comments on commit 6cf4cb1

Please sign in to comment.