Choose Language Hide Translation Bar
Staff (Retired)
Can JMP run JMP?

in Http Background Request  @burakbagdatli suggested using RunProgram to run another copy of JMP. Here's a toy example that works around some of the issues you might run into. It will need some tweaks to run on Mac; I only tried on Windows.

// a place to keep up with running instances
rp = [=> ];

nrows=8; // each copy of JMP will retrieve one row, from 1..nrows

For( i = 1, i <= nrows, i += 1, 
	// build a custom JSL for each JMP to execute
	workerFileName = Save Text File(
		"$temp\deleteMe_RunsWhenLaunchedBeCareful" || Char( i ) || ".jsl",
			instance = ]\"||char(i)||"\[;
			dt<<selectrows( instance );
			while(tickseconds()-start < 60,42); // simulate some work
	// don't launch another copy until the previous copy is running.
	// JMP will become unhappy if the preferences file is busy in another
	// copy of JMP. The sentinel will be deleted when JMP starts
	rp[rpIndex+=1] = Run Program( executable( "jmp" ), options( {workerFileName} ) );
	write("\!n",i," started...");
	// wait for the sentinel to vanish
		wait(.1);// don't burn the CPU while waiting
// many copies are probaly still running, wait for them to finish
busy = 1;
While( busy,
	busy = 0;
	For( j = 1, j <= rpIndex, j += 1,
		If( !(rp[j] << isreadEOF),
			busy += 1; // count the ones still alive
	write("\!n",busy," busy");
	wait(.5); // don't burn the CPU while waiting

Write( "\!ngathering results..." );

For( i = 1, i <= nrows, i += 1, 
	// do something with the results
	// clean up the temp files
	deletefile("$temp\deleteMe_RunsWhenLaunchedBeCareful" || Char( i ) || ".jsl");

Write( "\!ndone" );

A separate JSL file is created for each copy of JMP; in this example JMP only needs an instance number. Each instance opens its own copy of Big Class and gets the i'th name. Answers are returned in another file with a name that includes the instance number. When all the instances finish, the answers are gathered.

The sentinel detects when a JMP instance is fully started and finished writing the preferences (etc) file. Without the sentinel, JMP might not read the preferences correctly and show all sorts of odd dialogs you'd rather not see.

Article Labels

    There are no labels assigned to this post.

Article Tags