Mechanics of Continua and Structures
To run mathematica in CCV one needs to generate a script file with an extension .wls
. There are certain notations and packages that cannot be used in a script file such as
The file to do this operation automatically can be found here. The notebook SymbolReplace.nb basically opens your files and searches for symbols such as $N^{(a)}$ and replaces it with Nsupa. Data structure of the file is as follows
nb = NotebookOpen["/Users/kaushikvijaykumar/Dropbox \ (Brown)/3D_elasticity/script_test/3Delasticity_Tets_Mar_23_notched_\
beam_damage_3PB.nb"]
opens the notebook file that needs to be modified
* The module CreateComps searches for all combination of indicial notations such as, $u_{i\cdot}$, $\sigma_{i\cdot j\cdot}$ and replaces it with $u[[i]]$ and $\sigma[[i,j]]$
Once this is done the modified ‘.nb’ should be benchmarked using a simple and computationally tractable problem to make sure that the modifications are consistent.
As mentioned earlier the mesh cannot be generated in a script file on ccv, therefore generate the mesh using the notebook file on your desktop and export it to the hard disk using
Export["meshdata.txt", NumberForm[#, ExponentFunction -> (Null &)] & /@ List @@ Omegasuph,"String"];
where “meshdata.txt” is the exported mesh file and Omegasuph is the generated mesh. This can be read back into the mathematica file using
To create a mathematica script file from the notebook file, all the cells should be converted to initialization cells and then the notebook can be saved as
as .wls
file.
A sample batch file for ccv, a test script file and the associated mesh file can be found here. The file description are as follows
batch.script
3PB_rescale_11k_elements_6k_neq_2.wls
meshdata.txt
In the batch file the command
srun hostname > nodefile
export NODEFILE=nodefile
srun
is a SLURM command, which associates the number of nodes and number cores and the export command exports the nodes to the file nodefile. For example, if you have requested for 2 nodes with 4 processors each, then nodeifle will contain Node1 and Node2 4 times each. Indicating that you have 4 cores of node1 and 4 cores of node2 at your disposal for your job. The rest of the commands in the batch can be read on the ccv website.
To run the mathematica script file across nodes copy paste the following in the script file
(*get association of resources, name of local host and remove local host from available resources*)
hosts = Counts[ReadList[Environment["NODEFILE"], "String"]]
local = First[StringSplit[Environment["HOSTNAME"],"."]]
hosts[local]--;
(*launch subkernels and connect them to the controlling Wolfram Kernel*)
Needs["SubKernels`RemoteKernels`"];
Map[If[hosts[#] > 0, LaunchKernels[RemoteMachine[#, "ssh -x -f -l `3` `1` /gpfs/runtime/opt/mathematica/11.0/Executables/wolfram -wstp -linkmode Connect `4` -linkname '`2`' -subkernel -noinit", hosts[#]]]]&, Keys[hosts]];
The variable hosts
counts the number nodes and the associated cores from the node file and stores it. hosts[local]--
makes the node1-core1 as the master kernel. I don’t fully understand the next set of commands but in a lay mans language it launches RemoteKernels
from path given in the code. Finally, save the notebook file as .wls
file and run it using the batch script on ccv.
Open the batch file sbatch.script
and
#SBATCH --time=24:00:00
, which sets the total time of job to be 24 hrs.#SBATCH -J mathematica-sample
indicates that your job name is mathematica-sample
.#SBATCH -o sample.out
the output file is sample.out
and in this file all the print statements from the mathematica script file will be executed. The command #SBATCH -e sample.err
is the standard error file which will indicate if there are any compilation errors.#SBATCH --nodes=4
and the number of processors using #SBATCH --ntasks-per-node=16
. The number of nodes will depend on the availablility on the cluster, which can be checked using the command nodes-v
. The number processors will depend on the node you want to run it on.module load mathematica/11.0
wolfram -script 3PB_rescale_11k_elements_6k_neq_2.wls
All you need to do is remove the ccv commands in the .wls
given in the previous section and add
Needs["Rescale'"]
to the .wls
file. The command to execute the script file is the same as earlier wolfram -script 3PB_rescale_11k_elements_6k_neq_2.wls
.