Choose Language Hide Translation Bar
Craige_Hales
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 = [=> ];
rpIndex=0;

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)||"\[;
			deletefile("$temp/sentinel.txt");
			dt=open("$sample_data/big class.jmp"); 
			dt<<selectrows( instance );
			start=tickseconds();
			while(tickseconds()-start < 60,42); // simulate some work
			savetextfile("$temp/deleteme"||char(instance)||".txt",dt:name[instance]);
			exit();
		]\"
	);
	// 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
	savetextfile("$temp/sentinel.txt","");
	rp[rpIndex+=1] = Run Program( executable( "jmp" ), options( {workerFileName} ) );
	write("\!n",i," started...");
	// wait for the sentinel to vanish
	while(fileexists("$temp/sentinel.txt"),
		wait(.1);// don't burn the CPU while waiting
	);
	write("ok");
);
// 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, 
	filename="$temp/deleteme"||char(i)||".txt";
	// do something with the results
	write("\!n",loadtextfile(filename));
	// clean up the temp files
	deletefile(filename);
	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