6

Parallel kernels are not reading the init.m files in $UserBaseDirectory/Autoload since version 11.2. The master kernel reads it fine. In earlier versions of Mathematica parallel kernels read these init.m files. Any suggestions?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
Chris Degnen
  • 30,927
  • 2
  • 54
  • 108
  • I don't have v9.0 here, but in 10.0 and later init.m is definitely not evaluated on parallel kernels. – Szabolcs Jan 17 '18 at 16:39
  • I believe it worked from FileNameJoin[{$InstallationDirectory, "AddOns", "Autoload", "Kernel", "init.m"}] in 11.0 and 11.1. The key could be the Autoload part. I realise this is a non-standard (or very old) location but it worked, up until 11.2. – Chris Degnen Jan 17 '18 at 16:57
  • I think that's an incorrect use of the Autoload directory. It should contain packages, not Kernel/init.m. A package itself may (and should) contain a Kernel/init.m. This init.m has nothing to do with $UserBaseDirectory/Kernel/init.m—it's not an alternative for it. When you put Kernel/init.m in Autoload it considered that a package. – Szabolcs Jan 17 '18 at 17:55
  • All that said, it does appear that subkernels stopped loading autoload packages in 11.2, so the solution I suggested no longer works. I think I'll ask support about this because I don't know any other reasonable way to run initialization code on subkernels. – Szabolcs Jan 17 '18 at 17:56
  • The sysinit.m file used to have a check for the -noinit option, which would control if Kernel/init.m should load. It also contained the code to load Autoload stuff (unconditionally). None of this is present in sysinit.m anymore in 11.2. These files must be loading by another mechanism. – Szabolcs Jan 17 '18 at 18:05
  • Could you please edit the question to explain that what has changed is not how $(User)BaseDirectory/Kernel/init.m is read, but how Autoload packages are read? – Szabolcs Jan 18 '18 at 10:23
  • @Szabolcs Actually I'm not sure how Autoload works, and the documentation isn't great. I tried putting the init.m in C:\ProgramData\Mathematica\Autoload but it didn't work, (not even for the main kernel). I'll try again later. – Chris Degnen Jan 18 '18 at 16:44
  • I think what happens is that any file named init.m within Autload will be loaded, but I haven't had time to look at it in detail yet. I found the file where the loading code was moved to. It's not sysinit.m but Initialization....m, forgot the exact name. – Szabolcs Jan 19 '18 at 15:26
  • I edited the question to avoid confusion, as it was making incorrect claims. $(User)BaseDirectory/Kernel/init.m has never been read by the parallel kernels. What changed in 11.2 is that now init.m files in various locations within the Autoload directory also don't load on parallel kernels. – Szabolcs Mar 14 '18 at 12:21

1 Answers1

4

This works

Parallel`Developer`$InitCode=Hold[Get[FileNameJoin[{$BaseDirectory,"Kernel","init.m"}]]]

c/o Register "initialization code" to run on any newly started parallel kernel

However, it is undocumented.

Chris Degnen
  • 30,927
  • 2
  • 54
  • 108