Skip to content

Conversation

@Artoria2e5
Copy link

This is the same as shafferjohn/Prime95#3, except that I've tested the code this time. It compiles and appears to work as intended in a very short test (does not print "does not support", actually calls the set-function).

@Artoria2e5
Copy link
Author

Oh bugger I've got to change the makefile too. My actual makefile for test uses dynamic versions of libraries to get it to build, so I gotta isolate the changes from what's actually needed here.

Compiles, builds, runs correctly. Done!
@tdulcet
Copy link
Member

tdulcet commented Nov 9, 2025

As mentioned in #1, this is just a mirror of the Prime95 source code, so I would recommend emailing George your patch or posting it on the Mersenne forum.

@Artoria2e5
Copy link
Author

@gwoltman sent a reply to this PR at shafferjohn/Prime95#2 (comment) but it's misplaced, so I'm bringing the thread back here.

How does setting Mac OS X affinities work? Don't hwloc queries in commonc.c end up setting OS_CAN_SET_AFFINITY to false?

We go behind hwloc's back and use our own thing. Hence the change in common.c for #ifdef __APPLE__.

The Affinity API is present on all Intel macOS 10.5+, which is a superset of what mprime can run on. In other words no more test is required, we can always set OS_CAN_SET_AFFINITY to 1 on macOS.

@Artoria2e5
Copy link
Author

(I would normally make this a comment-edit append to save screen space, but since George is mostly using email, I figured that added things should be their own messages).

I've thought about patching hwloc itself to provide this functionality, but there is a significant mismatch between what hwloc thinks (cpu sets) and what the kernel API exposes (core-sharing tags) [the kernel internally uses CPU sets but does not expose them, just Apple messing with ya!]. It would be possible to provide an implementation that checks whether the cpuset only spans one physical core and act accordingly, but the bitwise operations involved is giving me a headache.

For now let's use the more obvious encapsulation: just tags as "virtual core number". (I've said before on mersenneforum that there is a one-to-one tag-core relationship as long as the number of tags do not exceed the number of cores.) It's closer to what we intend anyways: run on core number X.

@gwoltman
Copy link
Contributor

gwoltman commented Nov 10, 2025 via email

@Artoria2e5
Copy link
Author

That works too if you're not so keen on changing commonc.c to bypass the setting of OS_CAN_SET_AFFINITY. George, I really do recommend that you use the webpage and view the actual, whole patch. Alternatively you can use "curl https://github.com/primesearch/Prime95/pull/2.patch" for a plaintext version.

PS: I'm Mingye Wang, not John Staffer! It's just that I sent the initial patch to John Staffer instead of here.

@gwoltman
Copy link
Contributor

gwoltman commented Nov 11, 2025 via email

@gwoltman
Copy link
Contributor

gwoltman commented Nov 11, 2025 via email

@Artoria2e5
Copy link
Author

George,

The errors appear to be from the kern headers I'm including, but not the particular parts that I'm using. I happen to also have a (slow) machine stuck on Montgomery with XCode 16 being the latest available official toolchain, so I'll try and see what can be done. Perhaps I just need to include some more useless headers.

@Artoria2e5
Copy link
Author

Artoria2e5 commented Nov 11, 2025

Correction. XCode 16 corresponds to a much newer version than Monterey (I can't get the name right), but I can always fish out an older SDK version from third-party places like https://github.com/joseluisq/macosx-sdks and make sure it builds.


Non-email append. 10.9 SDK compiles fine, suspecting a version in between. cat /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/version.plist indicates I'm using the 15.0 SDK. Using ls -la /Library/Developer/CommandLineTools/SDKs on George's side should help with figuring out his version, but judging from the table at https://developer.apple.com/support/xcode/ I should get pretty close with either the 12.5 SDK or the 13 SDK. Therefore attempting to reproduce with that without getting too much roundtrip time.

For now my "guess" for a solution is #include <mach/vm_types.h>.

@Artoria2e5
Copy link
Author

I'm afraid the current version in main (p95v3101b1) includes a typo: pthread_t should be thread_t. I also revised the placement of the mac branch in commonb.c in this version, added a bit to commonc.c (as we've discussed before), and added two include directives to aff.c (you do seem to have that version as indicated by the error). I recommend rolling back the changes and re-applying this version.

In the meantime I am still yet to reproduce the compilation error. For now my suggestion is: try adding #include <mach/vm_types.h> before the thread includes.

@gwoltman
Copy link
Contributor

gwoltman commented Nov 12, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants