0

I created a script to find a number inside pi:

from math import pi from mpmath import mp from time import sleep as sleep def loop(find): #Breaks the find string into a list findList = [] print('Finding ' + str(find)) num = 1000 while True: mp.dps = num string = str(mp.pi) result = string.find(str(find)) if result == -1: print("Couldn't find " + str(find) + " within the first " + str(num) + " of Pi. Looking moving into the first " + str(num * 10) + " digits instead") num = num * 10 continue pass else: print(str(find )+ ' was found at character: ' + str(result)) break pass pass def main(): find = input("What do you want to find: ") find = int(find) character = loop(find) if True: main() input = () 

When a long number is inputed it takes a long time to process for obvious reasons. I'm running an Intel i5-9300h and a GTX 1650. I am wondering if 1) I can make this code run on my GPU instead of my CPU 2) If so, how do I do this? 3) Would it even benefit performance?

Any help is much appreciated.

1 Answer 1

1

I think numba will help with what you're looking for. It can run python code with CUDA support (i.e. your graphics card). Using CUDA for math is often faster than using a CPU because of better multithreading, however, whether you would get any benefit from it will depend on implementation. In your example I think you'll have to write a function that can approximate pi in a multithreaded way, in order to take advantage of what CUDA has to offer.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.