/**
* Section 1
**/
SparkConf sparkConf = new SparkConf()
   .setAppName("Spark Workflow")
   .setMaster("local[2]")
   .set("spark.executor.memory", "1g");
JavaSparkContext sparkCtx = new JavaSparkContext(sparkConf);
...
/**
* Section 2
**/
String afile = SparkMain.class.getResource("/txt/a.txt").getFile();
...
/**
* Section 3
**/
JavaRDD<String> aValues = sparkCtx.textFile(afile);
...
/**
* Section 4
**/
JavaPairRDD<Integer, DenseMatrix> aMatrices = aValues.mapToPair(new StringToTupleFunction());
...
/**
* Section 5
**/
JavaPairRDD<Integer, Tuple2<DenseMatrix, DenseMatrix>> groupingADMatrices = aMatrices.join(dMatrices);
JavaPairRDD<Integer, DenseMatrix> adMatrices = groupingADMatrices.mapToPair(new MatrixAddFunction());
...
/**
* Section 6
**/
JavaPairRDD<Integer, Tuple2<DenseMatrix, DenseMatrix>> groupingBCMatrix = bMatrices.join(cMatrices);
JavaPairRDD<Integer, DenseMatrix> bcMatrices = groupingBCMatrix.mapToPair(new MatrixMultFunction());
...
/**
* Section 7
**/
JavaPairRDD<Integer, Tuple2<DenseMatrix, DenseMatrix>> groupingADBCMatrices = adMatrices.join(bcMatrices);
JavaPairRDD<Integer, DenseMatrix> resultMatrices = groupingADBCMatrices.mapToPair(new MatrixAddFunction());
/**
* Section 8
**/
resultMatrices.foreach(x -> System.out.println(x));