title: How to access the value of accumulator in tasks?
body: <p>I am trying to access an accumulator's value while in a task of a cluster. But when I do so it throws an exception:</p>
  
  <blockquote>
    <p>can't read the accumulator's value </p>
  </blockquote>
  
  <p>I tried to use the <code>row.localValue</code> but it returns the same numbers. Is there a workaround?</p>
  
  <pre><code>private def modifyDataset(
    data: String, row: org.apache.spark.Accumulator[Int]): Array[Int] = {
  
    var line = data.split(",")
    var lineSize = line.size      
    var pairArray = new Array[Int](lineSize-1)
    var a = row.value
    paiArray(0)=a
  
    row+=1
    pairArray
  
  }
  
  
  var sc = Spark_Context.InitializeSpark
  var row = sc.accumulator(1, "Rows")
  
  var dataset = sc.textFile("path")
  
  var pairInfoFile = noHeaderRdd.flatMap{ data =&gt; modifyDataset(data,row) }
    .persist(StorageLevel.MEMORY_AND_DISK)        
  pairInfoFile.count()
  </code></pre>